Skip to content

Commit

Permalink
Merge pull request #221 from alleyinteractive/feature/filter-post-tit…
Browse files Browse the repository at this point in the history
…le-level-support

Enhancement - Add Filter for Post Title Heading Level Support
  • Loading branch information
ellm authored Aug 28, 2024
2 parents be23e1b + 15a139d commit 36f0105
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

All notable changes to `WP Curate` will be documented in this file.

## 2.2.3 - 2024-0826
## 2.3.0 - 2024-08-28

- Enhancement: Enable block filter support for Post Title block setting Heading Level select.

## 2.2.3 - 2024-08-26

- Stack post buttons (move, pin, etc.) in smaller block widths.

Expand All @@ -12,7 +16,7 @@ All notable changes to `WP Curate` will be documented in this file.

## 2.2.1 - 2024-08-15

- Bug Fix: Handle cases where a pinned post has been deleted or unpublished.
- Bug Fix: Handle cases where a pinned post has been deleted or unpublished.

## 2.2.0 - 2024-08-05

Expand Down
4 changes: 4 additions & 0 deletions blocks/post-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"level": {
"type": "number",
"default": 3
},
"supportsLevel": {
"type": "boolean",
"default": true
}
},
"render": "file:render.php",
Expand Down
55 changes: 29 additions & 26 deletions blocks/post-title/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface PostTitleEditProps {
clientId?: string;
attributes: {
level?: number;
supportsLevel?: boolean;
};
context: {
postId: number;
Expand Down Expand Up @@ -48,11 +49,11 @@ export default function Edit({
query: { postType = 'post' },
customPostTitles = [],
} = context;
const { level = 3 } = attributes;
const { level = 3, supportsLevel } = attributes;
const [rawTitle = '', , fullTitle] = useEntityProp('postType', postType, 'title', postId.toString());
const isPinned = pinnedPosts.includes(postId);
const currentCustomPostTitle = customPostTitles.find((item) => item?.postId === postId);
const TagName = level === 0 ? 'p' : `h${level}`;
const TagName = !supportsLevel || level === 0 ? 'p' : `h${level}`;
const blockProps = useBlockProps();

useEffect(() => {
Expand Down Expand Up @@ -146,30 +147,32 @@ export default function Edit({
return (
<>
{ titleElement }
<InspectorControls>
<PanelBody
title={__('Setup', 'wp-curate')}
initialOpen
>
<SelectControl
label={__('Heading Level')}
// @ts-ignore
value={level.toString()}
options={[
{ label: 'p', value: '0' },
{ label: 'h1', value: '1' },
{ label: 'h2', value: '2' },
{ label: 'h3', value: '3' },
{ label: 'h4', value: '4' },
{ label: 'h5', value: '5' },
{ label: 'h6', value: '6' },
]}
onChange={(newLevel) => {
setAttributes({ level: parseInt(newLevel, 10) });
}}
/>
</PanelBody>
</InspectorControls>
{supportsLevel ? (
<InspectorControls>
<PanelBody
title={__('Setup', 'wp-curate')}
initialOpen
>
<SelectControl
label={__('Heading Level')}
// @ts-ignore
value={level.toString()}
options={[
{ label: 'p', value: '0' },
{ label: 'h1', value: '1' },
{ label: 'h2', value: '2' },
{ label: 'h3', value: '3' },
{ label: 'h4', value: '4' },
{ label: 'h5', value: '5' },
{ label: 'h6', value: '6' },
]}
onChange={(newLevel) => {
setAttributes({ level: parseInt(newLevel, 10) });
}}
/>
</PanelBody>
</InspectorControls>
) : null}
</>
);
}
2 changes: 1 addition & 1 deletion wp-curate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Curate
* Plugin URI: https://github.com/alleyinteractive/wp-curate
* Description: Plugin to curate homepages and other landing pages
* Version: 2.2.3
* Version: 2.3.0
* Author: Alley Interactive
* Author URI: https://github.com/alleyinteractive/wp-curate
* Requires at least: 6.4
Expand Down

0 comments on commit 36f0105

Please sign in to comment.