Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cab6b8e
Deprecate 'Post author' block
t-hamano Oct 13, 2023
72e877b
Merge branch 'trunk' into post-author/deprecate
t-hamano Oct 16, 2023
7390397
Change `inserter` property to `false`
t-hamano Oct 16, 2023
580fc86
Clean empty attributes
t-hamano Oct 16, 2023
491a15e
Incorrect condition when converting Avatar and Biography
t-hamano Oct 16, 2023
a8173e3
Use 1em margin as block gap value
t-hamano Oct 16, 2023
e29b59f
Merge branch 'trunk' into post-author/deprecate
t-hamano Dec 28, 2023
91c8592
Merge branch 'trunk' into post-author/deprecate
t-hamano Dec 29, 2023
02a9cdd
Merge branch 'trunk' into post-author/deprecate
t-hamano Feb 23, 2024
400ac2d
__next40pxDefaultSize to the migrate button
t-hamano Feb 23, 2024
1a6962b
Merge branch 'trunk' into post-author/deprecate
t-hamano May 27, 2024
f2cec4a
Resolve conflicts
t-hamano Jul 22, 2024
9875c31
Show migration content via new private slot fill
t-hamano Jul 29, 2024
d4c68b2
Merge branch 'trunk' into post-author/deprecate
t-hamano Oct 7, 2024
b1e0972
Merge branch 'trunk' into post-author/deprecate
t-hamano Dec 30, 2025
e480533
Fix critical error
t-hamano Dec 30, 2025
145bb68
Remove transforms
t-hamano Dec 30, 2025
57aea0e
Move files
t-hamano Dec 30, 2025
d7171a3
Add block type check
t-hamano Dec 30, 2025
bbf4161
Fix typo
t-hamano Jan 3, 2026
389af04
Merge branch 'trunk' into post-author/deprecate
t-hamano Jan 3, 2026
11ab982
Update copy and button text
t-hamano Jan 3, 2026
735e16e
Apply zero gap
t-hamano Jan 22, 2026
0ad71b7
Preserve spacing styles
t-hamano Jan 22, 2026
8234f9c
Merge branch 'trunk' into post-author/deprecate
t-hamano Jan 22, 2026
2247071
Inherit testAlign to child blocks
t-hamano Jan 22, 2026
e759885
Merge branch 'trunk' into post-author/deprecate
t-hamano Jan 29, 2026
0b6288c
Fix lint error
t-hamano Jan 29, 2026
04c8a9f
Don't insert paragraph block if byline is empty
t-hamano Jan 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,13 @@ Show a block pattern. ([Source](https://github.com/WordPress/gutenberg/tree/trun
- **Supports:** interactivity (clientNavigation), ~~html~~, ~~inserter~~, ~~renaming~~, ~~visibility~~
- **Attributes:** slug

## Author
## Author (deprecated)

Display post author details such as name, avatar, and bio. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/post-author))
This block is deprecated. Please use the Avatar block, the Author Name block, and the Author Biography block instead. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/post-author))

- **Name:** core/post-author
- **Category:** theme
- **Supports:** anchor, color (background, gradients, link, text), filter (duotone), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** anchor, color (background, gradients, link, text), filter (duotone), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~, ~~inserter~~
- **Attributes:** avatarSize, byline, isLink, linkTarget, showAvatar, showBio, textAlign

## Author Biography
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import BlockStyles from '../block-styles';
import { default as InspectorControls } from '../inspector-controls';
import { default as InspectorControlsTabs } from '../inspector-controls-tabs';
import useInspectorControlsTabs from '../inspector-controls-tabs/use-inspector-controls-tabs';
import InspectorControlsLastItem from '../inspector-controls/last-item';
import AdvancedControls from '../inspector-controls-tabs/advanced-controls-panel';
import PositionControls from '../inspector-controls-tabs/position-controls-panel';
import useBlockInspectorAnimationSettings from './useBlockInspectorAnimationSettings';
Expand Down Expand Up @@ -369,6 +370,7 @@ const BlockInspectorSingleBlock = ( {
) }
</>
) }
<InspectorControlsLastItem.Slot />
<SkipToSelectedBlock key="back" />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import {
useBlockEditContext,
mayDisplayControlsKey,
} from '../block-edit/context';

const { Fill, Slot } = createSlotFill( Symbol( 'InspectorControlsLastItem' ) );

const InspectorControlsLastItem = ( props ) => {
const context = useBlockEditContext();
if ( ! context[ mayDisplayControlsKey ] ) {
return null;
}
return <Fill { ...props } />;
};
InspectorControlsLastItem.Slot = function InspectorControlsLastItemSlot(
props
) {
return <Slot { ...props } />;
};

export default InspectorControlsLastItem;
2 changes: 2 additions & 0 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
normalizeString,
} from './components/inserter/search-items';
import { PrivateListView } from './components/list-view';
import InspectorControlsLastItem from './components/inspector-controls/last-item';
import { useHasBlockToolbar } from './components/block-toolbar/use-has-block-toolbar';
import { cleanEmptyObject } from './hooks/utils';
import BlockQuickNavigation from './components/block-quick-navigation';
Expand Down Expand Up @@ -79,6 +80,7 @@ lock( privateApis, {
normalizeString,
PrivateListView,
ResizableBoxPopover,
InspectorControlsLastItem,
useHasBlockToolbar,
cleanEmptyObject,
BlockQuickNavigation,
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@use "./nextpage/editor.scss" as *;
@use "./page-list/editor.scss" as *;
@use "./paragraph/editor.scss" as *;
@use "./post-author/editor.scss" as *;
@use "./post-excerpt/editor.scss" as *;
@use "./pullquote/editor.scss" as *;
@use "./rss/editor.scss" as *;
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/post-author/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "core/post-author",
"title": "Author",
"title": "Author (deprecated)",
"category": "theme",
"description": "Display post author details such as name, avatar, and bio.",
"description": "This block is deprecated. Please use the Avatar block, the Author Name block, and the Author Biography block instead.",
"textdomain": "default",
"attributes": {
"textAlign": {
Expand Down Expand Up @@ -37,6 +37,7 @@
},
"usesContext": [ "postType", "postId", "queryId" ],
"supports": {
"inserter": false,
"anchor": true,
"html": false,
"spacing": {
Expand Down
48 changes: 47 additions & 1 deletion packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import {
InspectorControls,
RichText,
useBlockProps,
store as blockEditorStore,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import {
Button,
ComboboxControl,
SelectControl,
ToggleControl,
__experimentalText as Text,
__experimentalVStack as VStack,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
Expand All @@ -26,14 +31,19 @@ import { useDispatch, useSelect } from '@wordpress/data';
import { useMemo, useState } from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';
import { __, sprintf } from '@wordpress/i18n';
import { store as blocksStore } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { recreateWithRecommendedBlocks } from './utils';
import {
useDefaultAvatar,
useToolsPanelDropdownMenuProps,
} from '../utils/hooks';
import { unlock } from '../lock-unlock';

const { InspectorControlsLastItem } = unlock( blockEditorPrivateApis );

const AUTHORS_QUERY = {
who: 'authors',
Expand Down Expand Up @@ -114,6 +124,7 @@ function PostAuthorEdit( {
context: { postType, postId, queryId },
attributes,
setAttributes,
clientId,
} ) {
const isDescendentOfQueryLoop = Number.isFinite( queryId );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
Expand Down Expand Up @@ -145,8 +156,12 @@ function PostAuthorEdit( {
},
[ postType, postId ]
);

const blockTypes = useSelect(
( select ) => select( blocksStore ).getBlockTypes(),
[]
);
const { editEntityRecord } = useDispatch( coreStore );
const { replaceBlock } = useDispatch( blockEditorStore );

const {
textAlign,
Expand Down Expand Up @@ -195,6 +210,13 @@ function PostAuthorEdit( {
);
}

function transformBlock() {
replaceBlock(
clientId,
recreateWithRecommendedBlocks( attributes, blockTypes )
);
}

return (
<>
<InspectorControls>
Expand Down Expand Up @@ -310,6 +332,30 @@ function PostAuthorEdit( {
) }
</ToolsPanel>
</InspectorControls>
{ blockTypes.some(
( blockType ) => blockType.name === 'core/group'
) && (
<InspectorControlsLastItem>
<VStack
className="wp-block-post-author__transform"
alignment="left"
spacing={ 4 }
>
<Text as="p">
{ __(
'This block is no longer supported. Recreate its design with the Avatar, Author Name and Author Biography blocks.'
) }
</Text>
<Button
variant="primary"
onClick={ transformBlock }
__next40pxDefaultSize
>
{ __( 'Recreate' ) }
</Button>
</VStack>
</InspectorControlsLastItem>
) }

<BlockControls group="block">
<AlignmentControl
Expand Down
9 changes: 9 additions & 0 deletions packages/block-library/src/post-author/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@use "@wordpress/base-styles/variables" as *;
@use "@wordpress/base-styles/colors" as *;

.wp-block-post-author__transform {
background: $gray-100;
border-radius: $radius-block-ui;
margin: $grid-unit-20;
padding: $grid-unit-20;
}
139 changes: 139 additions & 0 deletions packages/block-library/src/post-author/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { unlock } from '../lock-unlock';

const { cleanEmptyObject } = unlock( blockEditorPrivateApis );

/**
* Generate Author-related blocks based on block attributes.
*
* @param {Object} attributes Block's attributes.
* @param {Object} blockTypes Block types.
* @return {Object} Generated block.
*/
export function recreateWithRecommendedBlocks( attributes, blockTypes ) {
const {
avatarSize,
byline,
showAvatar,
showBio,
isLink,
linkTarget,
textAlign,
style,
...restAttributes
} = attributes;

const shouldInsertAvatarBlock =
showAvatar &&
blockTypes.some( ( blockType ) => blockType.name === 'core/avatar' );
const shouldInsertParagraphBlock =
byline &&
blockTypes.some( ( blockType ) => blockType.name === 'core/paragraph' );
const shouldInsertPostAuthorNameBlock = blockTypes.some(
( blockType ) => blockType.name === 'core/post-author-name'
);
const shouldInsertPostAuthorBiographyBlock =
showBio &&
blockTypes.some(
( blockType ) => blockType.name === 'core/post-author-biography'
);

return createBlock(
'core/group',
{
...restAttributes,
style: cleanEmptyObject( {
...style,
spacing: {
...style?.spacing,
blockGap: '1em',
},
color: {
...style?.color,
// Duotone must be applied to the avatar block.
duotone: undefined,
},
} ),
layout: {
type: 'flex',
flexWrap: 'nowrap',
verticalAlignment: 'top',
},
Comment on lines +66 to +70
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layout and spacing changes are a bit unexpected when migrating the block. Can we apply some sensible defaults to match the previous spacing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Post Author block also has a Flex layout, but seems to have a 1em right margin between the avatar and the content. Therefore, in a8173e3, this is used as the styles.spacing.blockGap value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating on this. The block gap spacing is only one aspect of the issue. In the video I shared you'll notice that the overall width of the block change. That is unexpected and could further break themes.

Before

Screenshot 2023-10-17 at 12 50 24 pm

After

Screenshot 2023-10-17 at 12 50 32 pm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the width of the block, I think the Post Author block does not have box-sizing:border-box, so the width change will occur if left and right padding is applied.

This spacing support for this block was added in #35963, but this PR was before #43243 that recommends adding box-sizing:border-box at the same time as supporting spacing controls.

Originally, I think the Post Author block should also have box-sizing:border-box, but what approach do you think is best to prevent breaking changes as much as possible? Personally, I think that increasing the width of the Post Author block by padding is not originally intended, and that changing the width may be acceptable for migration purposes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: Post Author block now supports borders, as of #64599. At the same time, box-sizing: border-box was added, so there should be no width change when migrating.

},
[
shouldInsertAvatarBlock &&
createBlock( 'core/avatar', {
size: avatarSize,
style: cleanEmptyObject( {
border: {
radius: '0px',
},
color: {
duotone: style?.color?.duotone,
},
} ),
} ),
createBlock(
'core/group',
{
style: {
layout: {
selfStretch: 'fill',
flexSize: null,
},
spacing: {
blockGap: '0',
},
},
layout: {
type: 'flex',
orientation: 'vertical',
justifyContent: 'stretch',
},
},
[
shouldInsertParagraphBlock &&
createBlock( 'core/paragraph', {
content: byline,
placeholder: __( 'Write byline…' ),
style: {
typography: {
fontSize: '0.5em',
textAlign,
},
},
} ),
shouldInsertPostAuthorNameBlock &&
createBlock( 'core/post-author-name', {
isLink,
linkTarget,
textAlign,
style: {
typography: {
fontSize: '1em',
},
},
} ),
shouldInsertPostAuthorBiographyBlock &&
createBlock( 'core/post-author-biography', {
textAlign,
style: {
typography: {
fontSize: '0.7em',
},
},
} ),
].filter( Boolean )
),
].filter( Boolean )
);
}
Loading