From b993c633ad40fc7b3e887e97bdae89d49aa07d7e Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 14 Jun 2023 17:55:03 +1000 Subject: [PATCH 01/21] Add Post Content attributes as a block editor setting --- src/wp-includes/block-editor.php | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 476d89e9846f6..c39e6e70df2c4 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -361,6 +361,89 @@ function _wp_get_iframed_editor_assets() { ); } +/** + * Finds the first occurrence of a specific block in an array of blocks. + * + * @since 6.3.0 + * + * @param string $block_name Name of the block to find. + * @param array $blocks Array of blocks. + * @return array Found block, or empty array if none found. + */ +function _wp_find_first_block( $block_name, $blocks ) { + foreach ( $blocks as $block ) { + if ( $block_name === $block['blockName'] ) { + return $block; + } + if ( ! empty( $block['innerBlocks'] ) ) { + $found_block = _wp_find_first_block( $block_name, $block['innerBlocks'] ); + + if ( ! empty( $found_block ) ) { + return $found_block; + } + } + } + + return array(); +} + +/** + * Adds styles and __experimentalFeatures to the block editor settings. + * + * @since 6.3.0 + * + * @return array Post Content block attributes or empty array if they don't exist. + */ +function _wp_get_post_content_block_attributes() { + $is_block_theme = wp_is_block_theme(); + + global $post_ID; + + if ( ! $is_block_theme || ! $post_ID ) { + return array(); + } + + $template_slug = get_page_template_slug( $post_ID ); + + if ( ! $template_slug ) { + $post_slug = 'singular'; + $page_slug = 'singular'; + $template_types = get_block_templates(); + + foreach ( $template_types as $template_type ) { + if ( 'page' === $template_type->slug ) { + $page_slug = 'page'; + } + if ( 'single' === $template_type->slug ) { + $post_slug = 'single'; + } + } + + $what_post_type = get_post_type( $post_ID ); + switch ( $what_post_type ) { + case 'page': + $template_slug = $page_slug; + break; + default: + $template_slug = $post_slug; + break; + } + } + + $current_template = get_block_templates( array( 'slug__in' => array( $template_slug ) ) ); + + if ( ! empty( $current_template ) ) { + $template_blocks = parse_blocks( $current_template[0]->content ); + $post_content_block = _wp_find_first_block( 'core/post-content', $template_blocks ); + + if ( ! empty( $post_content_block['attrs'] ) ) { + return $post_content_block['attrs']; + } + } + + return array(); +} + /** * Returns the contextualized block editor settings for a selected editor context. * @@ -529,6 +612,11 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex ), ); + $editor_settings['randomthing'] = 'test'; + if ( ! empty( _wp_get_post_content_block_attributes() )) { + $editor_settings['postContentAttributes'] = _wp_get_post_content_block_attributes(); + } + /** * Filters the settings to pass to the block editor for all editor type. * From 33a6cc94bc09eed0a2d06e23bb5919cb0d9cbc36 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Wed, 14 Jun 2023 12:14:53 +0200 Subject: [PATCH 02/21] Fix coding standards issues --- src/wp-includes/block-editor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index c39e6e70df2c4..8efd238821f92 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -363,7 +363,7 @@ function _wp_get_iframed_editor_assets() { /** * Finds the first occurrence of a specific block in an array of blocks. - * + * * @since 6.3.0 * * @param string $block_name Name of the block to find. @@ -389,7 +389,7 @@ function _wp_find_first_block( $block_name, $blocks ) { /** * Adds styles and __experimentalFeatures to the block editor settings. - * + * * @since 6.3.0 * * @return array Post Content block attributes or empty array if they don't exist. @@ -613,7 +613,7 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex ); $editor_settings['randomthing'] = 'test'; - if ( ! empty( _wp_get_post_content_block_attributes() )) { + if ( ! empty( _wp_get_post_content_block_attributes() ) ) { $editor_settings['postContentAttributes'] = _wp_get_post_content_block_attributes(); } From 4b484b350afcd27ba8cb44d7306318c238c04041 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 15 Jun 2023 16:25:40 +1000 Subject: [PATCH 03/21] Remove dummy setting --- src/wp-includes/block-editor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 8efd238821f92..db5312ab4c54d 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -612,7 +612,6 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex ), ); - $editor_settings['randomthing'] = 'test'; if ( ! empty( _wp_get_post_content_block_attributes() ) ) { $editor_settings['postContentAttributes'] = _wp_get_post_content_block_attributes(); } From 4a4ea463fadf941d0e90e717c2e6986f02071933 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 15 Jun 2023 16:42:16 +1000 Subject: [PATCH 04/21] Rename finding function and make public --- src/wp-includes/block-editor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index db5312ab4c54d..b06d67d6f3c45 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -370,13 +370,13 @@ function _wp_get_iframed_editor_assets() { * @param array $blocks Array of blocks. * @return array Found block, or empty array if none found. */ -function _wp_find_first_block( $block_name, $blocks ) { +function wp_get_first_block( $block_name, $blocks ) { foreach ( $blocks as $block ) { if ( $block_name === $block['blockName'] ) { return $block; } if ( ! empty( $block['innerBlocks'] ) ) { - $found_block = _wp_find_first_block( $block_name, $block['innerBlocks'] ); + $found_block = wp_get_first_block( $block_name, $block['innerBlocks'] ); if ( ! empty( $found_block ) ) { return $found_block; @@ -434,7 +434,7 @@ function _wp_get_post_content_block_attributes() { if ( ! empty( $current_template ) ) { $template_blocks = parse_blocks( $current_template[0]->content ); - $post_content_block = _wp_find_first_block( 'core/post-content', $template_blocks ); + $post_content_block = wp_get_first_block( 'core/post-content', $template_blocks ); if ( ! empty( $post_content_block['attrs'] ) ) { return $post_content_block['attrs']; From 405e49914501b6af72c77bda5dc4b75fca9be810 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 15 Jun 2023 17:42:04 +1000 Subject: [PATCH 05/21] Add test for wp_get_first_block --- tests/phpunit/tests/blocks/editor.php | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 0769cbc31c411..5961aadb98fcc 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -396,6 +396,42 @@ function filter_block_editor_settings_my_editor( $editor_settings ) { $this->assertSame( 12345, $settings['maxUploadFileSize'] ); } + /** + * @ticket 58534 + */ + public function test_wp_get_first_block() { + $block_name = 'core/paragraph'; + $blocks = array( + array( + 'blockName' => 'core/image', + ), + array( + 'blockName' => $block_name, + 'attrs' => array( + 'content' => 'Hello World!', + ), + ), + array( + 'blockName' => 'core/heading', + ), + array( + 'blockName' => $block_name, + ), + ); + $blocks_with_no_paragraph = array( + array( + 'blockName' => 'core/image', + ), + array( + 'blockName' => 'core/heading', + ), + ); + + $this->assertSame( $blocks[1], wp_get_first_block( $block_name, $blocks ) ); + + $this->assertSame( array(), wp_get_first_block( $block_name, $blocks_with_no_paragraph ) ); + } + /** * @ticket 53458 */ From df0003bb1e1f44f28e0e6185475ea0e366a2406f Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 15 Jun 2023 17:47:29 +1000 Subject: [PATCH 06/21] Fix linting error --- tests/phpunit/tests/blocks/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 5961aadb98fcc..338622be851e8 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -407,7 +407,7 @@ public function test_wp_get_first_block() { ), array( 'blockName' => $block_name, - 'attrs' => array( + 'attrs' => array( 'content' => 'Hello World!', ), ), From e3fdf7dc4074d4ce706362a64849a10e8532994b Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 15 Jun 2023 17:50:00 +1000 Subject: [PATCH 07/21] fix further lint errors --- tests/phpunit/tests/blocks/editor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 338622be851e8..e131299e0d02b 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -400,8 +400,8 @@ function filter_block_editor_settings_my_editor( $editor_settings ) { * @ticket 58534 */ public function test_wp_get_first_block() { - $block_name = 'core/paragraph'; - $blocks = array( + $block_name = 'core/paragraph'; + $blocks = array( array( 'blockName' => 'core/image', ), @@ -418,7 +418,7 @@ public function test_wp_get_first_block() { 'blockName' => $block_name, ), ); - $blocks_with_no_paragraph = array( + $blocks_with_no_paragraph = array( array( 'blockName' => 'core/image', ), From 1dbdbb61bca62919d8a432b9e4ec662187e6b421 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 16 Jun 2023 11:40:40 +1000 Subject: [PATCH 08/21] Add test for _wp_get_post_content_block_attributes --- tests/phpunit/tests/blocks/editor.php | 110 ++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index e131299e0d02b..52f762850645a 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -1,3 +1,105 @@ +Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 +Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 +Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 +Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 +Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 +Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 + +Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 + +Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 assertSame( array(), wp_get_first_block( $block_name, $blocks_with_no_paragraph ) ); } + /** + * @ticket 58534 + */ + public function test__wp_get_post_content_block_attributes() { + // With no block theme and no post ID, expect an empty array. + $this->assertSame( array(), _wp_get_post_content_block_attributes() ); + } + /** * @ticket 53458 */ From b7464cb7a5d991aea3f5a23e3a50afc5c50619e5 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 16 Jun 2023 12:26:42 +1000 Subject: [PATCH 09/21] Add a test to check for post content attributes --- .../block-theme/templates/single.html | 2 + tests/phpunit/tests/blocks/editor.php | 113 ++---------------- 2 files changed, 13 insertions(+), 102 deletions(-) create mode 100644 tests/phpunit/data/themedir1/block-theme/templates/single.html diff --git a/tests/phpunit/data/themedir1/block-theme/templates/single.html b/tests/phpunit/data/themedir1/block-theme/templates/single.html new file mode 100644 index 0000000000000..4ad4c7caec0d1 --- /dev/null +++ b/tests/phpunit/data/themedir1/block-theme/templates/single.html @@ -0,0 +1,2 @@ + + diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 52f762850645a..251a6caab360b 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -1,105 +1,3 @@ -Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 -Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 -Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 -Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 -Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 -Deprecated: auto_detect_line_endings is deprecated in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Runner.php on line 294 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 184 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 213 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 201 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 225 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 172 - -Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 241 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 133 - -Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/isabelbrison/wordpress-develop/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php on line 92 array( + 'type' => 'constrained', + ), + ); // With no block theme and no post ID, expect an empty array. $this->assertSame( array(), _wp_get_post_content_block_attributes() ); + + global $post_ID; + $post_ID = 1; + switch_theme( 'block-theme' ); + + $this->assertSame( $attributes_with_layout, _wp_get_post_content_block_attributes() ); } /** From 1bbc1aba440c44e0d953723aacd0516b65ca13e6 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 16 Jun 2023 12:29:02 +1000 Subject: [PATCH 10/21] remove extra tab --- tests/phpunit/tests/blocks/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 251a6caab360b..fae57f8befa6e 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -440,7 +440,7 @@ public function test__wp_get_post_content_block_attributes() { 'layout' => array( 'type' => 'constrained', ), - ); + ); // With no block theme and no post ID, expect an empty array. $this->assertSame( array(), _wp_get_post_content_block_attributes() ); From fbd09819536dfbfddab8914b1401d846c8120999 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 19 Jun 2023 11:00:36 +1000 Subject: [PATCH 11/21] Change order of wp_get_first_block parameters --- src/wp-includes/block-editor.php | 8 ++++---- tests/phpunit/tests/blocks/editor.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index b06d67d6f3c45..2b86dde642cbd 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -366,17 +366,17 @@ function _wp_get_iframed_editor_assets() { * * @since 6.3.0 * - * @param string $block_name Name of the block to find. * @param array $blocks Array of blocks. + * @param string $block_name Name of the block to find. * @return array Found block, or empty array if none found. */ -function wp_get_first_block( $block_name, $blocks ) { +function wp_get_first_block( $blocks, $block_name ) { foreach ( $blocks as $block ) { if ( $block_name === $block['blockName'] ) { return $block; } if ( ! empty( $block['innerBlocks'] ) ) { - $found_block = wp_get_first_block( $block_name, $block['innerBlocks'] ); + $found_block = wp_get_first_block( $block['innerBlocks'], $block_name ); if ( ! empty( $found_block ) ) { return $found_block; @@ -434,7 +434,7 @@ function _wp_get_post_content_block_attributes() { if ( ! empty( $current_template ) ) { $template_blocks = parse_blocks( $current_template[0]->content ); - $post_content_block = wp_get_first_block( 'core/post-content', $template_blocks ); + $post_content_block = wp_get_first_block( $template_blocks, 'core/post-content' ); if ( ! empty( $post_content_block['attrs'] ) ) { return $post_content_block['attrs']; diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index fae57f8befa6e..ecc32008e6308 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -427,9 +427,9 @@ public function test_wp_get_first_block() { ), ); - $this->assertSame( $blocks[1], wp_get_first_block( $block_name, $blocks ) ); + $this->assertSame( $blocks[1], wp_get_first_block( $blocks, $block_name ) ); - $this->assertSame( array(), wp_get_first_block( $block_name, $blocks_with_no_paragraph ) ); + $this->assertSame( array(), wp_get_first_block( $blocks_with_no_paragraph, $block_name ) ); } /** From a4f048ad966835a4f70f0f93a4d79fc82654f567 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 19 Jun 2023 11:10:12 +1000 Subject: [PATCH 12/21] Update function name and meta --- src/wp-includes/block-editor.php | 11 +++++++---- tests/phpunit/tests/blocks/editor.php | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 2b86dde642cbd..591e089b50b32 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -388,13 +388,16 @@ function wp_get_first_block( $blocks, $block_name ) { } /** - * Adds styles and __experimentalFeatures to the block editor settings. + * Retrieves Post Content block attributes from the current post template. * * @since 6.3.0 + * @access private + * + * @global int $post_ID * * @return array Post Content block attributes or empty array if they don't exist. */ -function _wp_get_post_content_block_attributes() { +function wp_get_post_content_block_attributes() { $is_block_theme = wp_is_block_theme(); global $post_ID; @@ -612,8 +615,8 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex ), ); - if ( ! empty( _wp_get_post_content_block_attributes() ) ) { - $editor_settings['postContentAttributes'] = _wp_get_post_content_block_attributes(); + if ( ! empty( wp_get_post_content_block_attributes() ) ) { + $editor_settings['postContentAttributes'] = wp_get_post_content_block_attributes(); } /** diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index ecc32008e6308..9ffca3a93cfd1 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -435,20 +435,20 @@ public function test_wp_get_first_block() { /** * @ticket 58534 */ - public function test__wp_get_post_content_block_attributes() { + public function test_wp_get_post_content_block_attributes() { $attributes_with_layout = array( 'layout' => array( 'type' => 'constrained', ), ); // With no block theme and no post ID, expect an empty array. - $this->assertSame( array(), _wp_get_post_content_block_attributes() ); + $this->assertSame( array(), wp_get_post_content_block_attributes() ); global $post_ID; $post_ID = 1; switch_theme( 'block-theme' ); - $this->assertSame( $attributes_with_layout, _wp_get_post_content_block_attributes() ); + $this->assertSame( $attributes_with_layout, wp_get_post_content_block_attributes() ); } /** From 727f13544003cbe7aa126324f2ef9367a1c049cb Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 19 Jun 2023 11:16:59 +1000 Subject: [PATCH 13/21] Avoid calling function twice --- src/wp-includes/block-editor.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 591e089b50b32..8787a846d9781 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -615,8 +615,10 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex ), ); - if ( ! empty( wp_get_post_content_block_attributes() ) ) { - $editor_settings['postContentAttributes'] = wp_get_post_content_block_attributes(); + $post_content_block_attributes = wp_get_post_content_block_attributes(); + + if ( ! empty( $post_content_block_attributes ) ) { + $editor_settings['postContentAttributes'] = $post_content_block_attributes; } /** From 42a4d15948b55de21b085170e296b2ee18478ebd Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 19 Jun 2023 11:22:00 +1000 Subject: [PATCH 14/21] Add test to check for post content attributes in editor settings --- tests/phpunit/tests/blocks/editor.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 9ffca3a93cfd1..173abc177f563 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -511,6 +511,15 @@ public function test_get_block_editor_settings_theme_json_settings() { $this->assertSameSets( array( 'rem' ), $settings['enableCustomUnits'] ); // settings.spacing.customPadding $this->assertTrue( $settings['enableCustomSpacing'] ); + // settings.postContentAttributes + $this->assertSameSets( + array( + 'layout' => array( + 'type' => 'constrained', + ), + ), + $settings['postContentAttributes'] + ); switch_theme( WP_DEFAULT_THEME ); } From e206857baba2bca107f49e55ab2434af837026d7 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 19 Jun 2023 11:24:10 +1000 Subject: [PATCH 15/21] Remove extra whitespace --- src/wp-includes/block-editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 8787a846d9781..b4abd8aa6f2c9 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -392,7 +392,7 @@ function wp_get_first_block( $blocks, $block_name ) { * * @since 6.3.0 * @access private - * + * * @global int $post_ID * * @return array Post Content block attributes or empty array if they don't exist. From 67ae702dd99b7a6ebab63d21ed2753981eee4d57 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 20 Jun 2023 13:09:32 +1000 Subject: [PATCH 16/21] Test: handle globals in setup/teardown --- tests/phpunit/tests/blocks/editor.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 173abc177f563..480ee583b4220 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -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_postID = $post_ID; + $post_ID = 1; } public function tear_down() { /** @var WP_REST_Server $wp_rest_server */ global $wp_rest_server; $wp_rest_server = null; + global $post_ID; + $post_ID = $this->orig_postID; parent::tear_down(); } @@ -441,11 +447,9 @@ public function test_wp_get_post_content_block_attributes() { 'type' => 'constrained', ), ); - // With no block theme and no post ID, expect an empty array. + // With no block theme, expect an empty array. $this->assertSame( array(), wp_get_post_content_block_attributes() ); - - global $post_ID; - $post_ID = 1; + switch_theme( 'block-theme' ); $this->assertSame( $attributes_with_layout, wp_get_post_content_block_attributes() ); From fd820199ed44dd139eae3b651852a6525c753b10 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 20 Jun 2023 13:54:49 +1000 Subject: [PATCH 17/21] Fix lint errors --- tests/phpunit/tests/blocks/editor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 480ee583b4220..3dfe0e2caede2 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -29,7 +29,7 @@ public function set_up() { do_action( 'rest_api_init', $wp_rest_server ); global $post_ID; - $this->orig_postID = $post_ID; + $this->orig_post_ID = $post_ID; $post_ID = 1; } @@ -38,7 +38,7 @@ public function tear_down() { global $wp_rest_server; $wp_rest_server = null; global $post_ID; - $post_ID = $this->orig_postID; + $post_ID = $this->orig_post_ID; parent::tear_down(); } @@ -449,7 +449,7 @@ public function test_wp_get_post_content_block_attributes() { ); // With no block theme, expect an empty array. $this->assertSame( array(), wp_get_post_content_block_attributes() ); - + switch_theme( 'block-theme' ); $this->assertSame( $attributes_with_layout, wp_get_post_content_block_attributes() ); From 6a5e931e850642ade65efbdbcb015768f795c288 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 20 Jun 2023 13:57:23 +1000 Subject: [PATCH 18/21] try again --- tests/phpunit/tests/blocks/editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 3dfe0e2caede2..f54363459f206 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -29,7 +29,7 @@ public function set_up() { do_action( 'rest_api_init', $wp_rest_server ); global $post_ID; - $this->orig_post_ID = $post_ID; + $this->orig_post_id = $post_ID; $post_ID = 1; } @@ -38,7 +38,7 @@ public function tear_down() { global $wp_rest_server; $wp_rest_server = null; global $post_ID; - $post_ID = $this->orig_post_ID; + $post_ID = $this->orig_post_id; parent::tear_down(); } From 07e84c94d98c360a9494df4a941d3edc08394aa8 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 20 Jun 2023 13:59:32 +1000 Subject: [PATCH 19/21] fix spacing --- tests/phpunit/tests/blocks/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index f54363459f206..6b6d8477b75ed 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -30,7 +30,7 @@ public function set_up() { global $post_ID; $this->orig_post_id = $post_ID; - $post_ID = 1; + $post_ID = 1; } public function tear_down() { From c104d907c6b6ad5ba846a30f816d191e6e9281d6 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 20 Jun 2023 16:57:25 +1000 Subject: [PATCH 20/21] Fix deprecation errors --- tests/phpunit/tests/blocks/editor.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 6b6d8477b75ed..e01947a34cee1 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -29,8 +29,7 @@ public function set_up() { do_action( 'rest_api_init', $wp_rest_server ); global $post_ID; - $this->orig_post_id = $post_ID; - $post_ID = 1; + $post_ID = 1; } public function tear_down() { @@ -38,7 +37,7 @@ public function tear_down() { global $wp_rest_server; $wp_rest_server = null; global $post_ID; - $post_ID = $this->orig_post_id; + $post_ID = null; parent::tear_down(); } From 0bcf57ae09f9a8e8d2fa7bbdae6876cce90407cf Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 21 Jun 2023 13:19:07 +1000 Subject: [PATCH 21/21] Move global to top of function. Co-authored-by: Felix Arntz --- src/wp-includes/block-editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index b4abd8aa6f2c9..b823c09391c93 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -398,10 +398,10 @@ function wp_get_first_block( $blocks, $block_name ) { * @return array Post Content block attributes or empty array if they don't exist. */ function wp_get_post_content_block_attributes() { - $is_block_theme = wp_is_block_theme(); - global $post_ID; + $is_block_theme = wp_is_block_theme(); + if ( ! $is_block_theme || ! $post_ID ) { return array(); }