Add Post Content attributes as a block editor setting#4614
Add Post Content attributes as a block editor setting#4614tellthemachines wants to merge 21 commits into
Conversation
|
Thanks for the PR! |
|
Can you please add some unit tests to this PR. |
| * @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.
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. |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
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.
Missing docblock for global.
* @global int $post_ID
There was a problem hiding this comment.
Nit-pick: It would be good to follow the pattern of putting the global declaration to the very top of the function code.
| if ( ! empty( _wp_get_post_content_block_attributes() ) ) { | ||
| $editor_settings['postContentAttributes'] = _wp_get_post_content_block_attributes(); |
There was a problem hiding this comment.
_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.
Makes sense!
felixarntz
left a comment
There was a problem hiding this comment.
@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.
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. |
| do_action( 'rest_api_init', $wp_rest_server ); | ||
|
|
||
| global $post_ID; | ||
| $this->orig_post_id = $post_ID; |
There was a problem hiding this comment.
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).
felixarntz
left a comment
There was a problem hiding this comment.
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>
mukeshpanchal27
left a comment
There was a problem hiding this comment.
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-editorstore.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.