Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Author Name: Add to and from Post Author transformations #41151

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/block-library/src/post-author-name/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import metadata from './block.json';
import edit from './edit';
import transforms from './transforms';

/**
* WordPress dependencies
Expand All @@ -14,5 +15,6 @@ export { metadata, name };

export const settings = {
icon,
transforms,
edit,
};
2 changes: 1 addition & 1 deletion packages/block-library/src/post-author-name/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function render_block_core_post_author_name( $attributes, $content, $block ) {

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );

return sprintf( '<div %1$s>', $wrapper_attributes ) . $author_name . '</div>';
return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $author_name );
Copy link
Member Author

Choose a reason for hiding this comment

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

A small code quality improvement, unrelated to this PR.

}

/**
Expand Down
25 changes: 25 additions & 0 deletions packages/block-library/src/post-author-name/transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';

const transforms = {
from: [
{
type: 'block',
blocks: [ 'core/post-author' ],
transform: ( { textAlign } ) =>
createBlock( 'core/post-author-name', { textAlign } ),
},
],
to: [
{
type: 'block',
blocks: [ 'core/post-author' ],
transform: ( { textAlign } ) =>
createBlock( 'core/post-author', { textAlign } ),
},
],
};

export default transforms;