-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add Post Content attributes as a block editor setting #4614
Add Post Content attributes as a block editor setting #4614
Conversation
Thanks for the PR! |
Can you please add some unit tests to this PR. |
src/wp-includes/block-editor.php
Outdated
* @param array $blocks Array of blocks. | ||
* @return array Found block, or empty array if none found. | ||
*/ | ||
function _wp_find_first_block( $block_name, $blocks ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function could be useful for the general developer community as well. I know I've reinvented this wheel a few times already for extracting images/excerpts from post content on various projects. Can the pseudo-private _
prefix be removed?
Also, wp_find_
is used as a prefix only 3 times in core right now. As a developer, I generally expect WordPress functions that return data to use wp_get_
.
Thanks for fixing the coding standards stuff @audrasjb! I'm having issues running the composer scripts locally 😩 I've added a test for the now-renamed |
I just added a base test case for |
Update: I got it working! Had to add a single template to the test block theme. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tellthemachines, Left some nitpick feedback.
function _wp_get_post_content_block_attributes() { | ||
$is_block_theme = wp_is_block_theme(); | ||
|
||
global $post_ID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docblock for global.
* @global int $post_ID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit-pick: It would be good to follow the pattern of putting the global
declaration to the very top of the function code.
src/wp-includes/block-editor.php
Outdated
if ( ! empty( _wp_get_post_content_block_attributes() ) ) { | ||
$editor_settings['postContentAttributes'] = _wp_get_post_content_block_attributes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_wp_get_post_content_block_attributes()
call multiple time if condition true instead define a variable and use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tellthemachines Looks solid to me, +1 to having wp_get_first_block()
as a generally available function.
I left a few small comments below, but none strictly a blocker (except probably the two documentation bits).
function _wp_get_post_content_block_attributes() { | ||
$is_block_theme = wp_is_block_theme(); | ||
|
||
global $post_ID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit-pick: It would be good to follow the pattern of putting the global
declaration to the very top of the function code.
Thanks for the feedback folks! Question on the tests: I added an extra assertion to |
Update: @hellofromtonya has pointed me in the right direction and I've updated the tests accordingly. |
@@ -27,12 +27,18 @@ public function set_up() { | |||
global $wp_rest_server; | |||
$wp_rest_server = new Spy_REST_Server(); | |||
do_action( 'rest_api_init', $wp_rest_server ); | |||
|
|||
global $post_ID; | |||
$this->orig_post_id = $post_ID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure, so I copied what's being done for the $wp_rest_server
global and set it to null on teardown. It shouldn't matter because $post_ID
shouldn't be set to any value at this point (if it was, test_wp_get_post_content_block_attributes
wouldn't fail without it being set explicitly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @tellthemachines, LGTM! Just the one nit-pick remaining, but not a big deal. Feel free to update before commit.
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tellthemachines the update. Look good to me.
@tellthemachines Re-run the failed job it show |
Trac ticket: https://core.trac.wordpress.org/ticket/58534
This PR adds the changes from WordPress/gutenberg#45299.
To test, checkout the PR locally and update the "@wordpress/editor" package to its latest version - "13.12.0". Then run the build, and use the Redux dev tools to inspect settings in the state of the
core/block-editor
store.Edit: I somehow left out that this PR also adds the changes from WordPress/gutenberg#49049 🤦
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.