Make WordPress Core

Changeset 56629


Ignore:
Timestamp:
09/20/2023 01:24:32 AM (10 months ago)
Author:
isabel_brison
Message:

Editor: Fix post editor layout when Post Content has no attributes.

Changes output of wp_get_post_content_block_attributes to return null if Post Content block doesn’t exist or empty array if it has no attributes.

Props flixos90, mukesh27.
Fixes #59358.

Location:
trunk
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r56500 r56629  
    410410 *
    411411 * @since 6.3.0
     412 * @since 6.4.0 Return null if there is no post content block.
    412413 * @access private
    413414 *
    414415 * @global int $post_ID
    415416 *
    416  * @return array Post Content block attributes or empty array if they don't exist.
     417 * @return array|null Post Content block attributes array or null if Post Content block doesn't exist.
    417418 */
    418419function wp_get_post_content_block_attributes() {
     
    422423
    423424    if ( ! $is_block_theme || ! $post_ID ) {
    424         return array();
     425        return null;
    425426    }
    426427
     
    458459        $post_content_block = wp_get_first_block( $template_blocks, 'core/post-content' );
    459460
    460         if ( ! empty( $post_content_block['attrs'] ) ) {
     461        if ( isset( $post_content_block['attrs'] ) ) {
    461462            return $post_content_block['attrs'];
    462463        }
    463464    }
    464465
    465     return array();
     466    return null;
    466467}
    467468
     
    636637    $post_content_block_attributes = wp_get_post_content_block_attributes();
    637638
    638     if ( ! empty( $post_content_block_attributes ) ) {
     639    if ( isset( $post_content_block_attributes ) ) {
    639640        $editor_settings['postContentAttributes'] = $post_content_block_attributes;
    640641    }
  • trunk/tests/phpunit/tests/blocks/editor.php

    r56619 r56629  
    447447            ),
    448448        );
    449         // With no block theme, expect an empty array.
     449        // With no block theme, expect null.
     450        $this->assertNull( wp_get_post_content_block_attributes() );
     451
     452        switch_theme( 'block-theme' );
     453
     454        $this->assertSame( $attributes_with_layout, wp_get_post_content_block_attributes() );
     455    }
     456
     457    public function test_wp_get_post_content_block_attributes_no_layout() {
     458        switch_theme( 'block-theme-post-content-default' );
     459
    450460        $this->assertSame( array(), wp_get_post_content_block_attributes() );
    451 
    452         switch_theme( 'block-theme' );
    453 
    454         $this->assertSame( $attributes_with_layout, wp_get_post_content_block_attributes() );
    455461    }
    456462
     
    529535
    530536    /**
     537     * @ticket 59358
     538     */
     539    public function test_get_block_editor_settings_without_post_content_block() {
     540
     541        $post_editor_context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
     542
     543        $settings = get_block_editor_settings( array(), $post_editor_context );
     544
     545        $this->assertArrayNotHasKey( 'postContentAttributes', $settings );
     546
     547    }
     548
     549    /**
    531550     * @ticket 52920
    532551     * @expectedDeprecated block_editor_settings
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r56621 r56629  
    186186            'Block Theme [1.0.0] in subdirectory',
    187187            'Block Theme Deprecated Path',
     188            'Block Theme Post Content Default',
    188189            'Block Theme with defined Typography Fonts',
    189190            'Empty `fontFace` in theme.json - no webfonts defined',
Note: See TracChangeset for help on using the changeset viewer.