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.


git-svn-id: https://develop.svn.wordpress.org/trunk@56629 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Isabel Brison
2023-09-20 01:24:32 +00:00
parent a0cce3900e
commit bee2dc4ba2
7 changed files with 144 additions and 7 deletions

View File

@@ -0,0 +1,7 @@
/*
Theme Name: Block Theme Post Content Default
Theme URI: https://wordpress.org/
Description: For testing purposes only.
Version: 1.0.0
Text Domain: block-theme-post-content-default
*/

View File

@@ -0,0 +1,3 @@
<!-- wp:paragraph -->
<p>Index Template</p>
<!-- /wp:paragraph -->

View File

@@ -0,0 +1,2 @@
<!-- wp:post-title {"level":1,"style":{"spacing":{"margin":{"bottom":"var:preset|spacing|40"}}}} /-->
<!-- wp:post-content /-->

View File

@@ -0,0 +1,104 @@
{
"version": 1,
"title": "Block theme",
"settings": {
"color": {
"palette": [
{
"slug": "light",
"name": "Light",
"color": "#f5f7f9"
},
{
"slug": "dark",
"name": "Dark",
"color": "#000"
}
],
"gradients": [
{
"name": "Custom gradient",
"gradient": "linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%)",
"slug": "custom-gradient"
}
],
"duotone": [
{
"colors": [ "#333333", "#aaaaaa" ],
"slug": "custom-duotone",
"name": "Custom Duotone"
}
],
"custom": false,
"customGradient": false
},
"typography": {
"fontSizes": [
{
"name": "Custom",
"slug": "custom",
"size": "100px"
}
],
"customFontSize": false,
"customLineHeight": true
},
"spacing": {
"units": ["rem"],
"customPadding": true,
"blockGap": true
},
"blocks": {
"core/paragraph": {
"color": {
"palette": [
{
"slug": "light",
"name": "Light",
"color": "#f5f7f9"
}
]
}
}
}
},
"styles" : {
"blocks" :{
"core/post-featured-image": {
"shadow": "10px 10px 5px 0px rgba(0,0,0,0.66)",
"filter": {
"duotone": "var(--wp--preset--duotone--custom-duotone)"
}
}
},
"elements": {
"button": {
"shadow": "10px 10px 5px 0px rgba(0,0,0,0.66)"
},
"link": {
"typography": {
"textDecoration": "none"
},
"border": {
"bottom": {
"width": "2px",
"color": "currentColor",
"style": "solid"
}
},
":hover": {
"typography": {
"textDecoration": "none"
},
"border": {
"bottom": {
"width": "2px",
"color": "#000",
"style": "dotted"
}
}
}
}
}
}
}

View File

@@ -446,14 +446,20 @@ class Tests_Blocks_Editor extends WP_UnitTestCase {
'type' => 'constrained',
),
);
// With no block theme, expect an empty array.
$this->assertSame( array(), wp_get_post_content_block_attributes() );
// With no block theme, expect null.
$this->assertNull( wp_get_post_content_block_attributes() );
switch_theme( 'block-theme' );
$this->assertSame( $attributes_with_layout, wp_get_post_content_block_attributes() );
}
public function test_wp_get_post_content_block_attributes_no_layout() {
switch_theme( 'block-theme-post-content-default' );
$this->assertSame( array(), wp_get_post_content_block_attributes() );
}
/**
* @ticket 53458
*/
@@ -527,6 +533,19 @@ class Tests_Blocks_Editor extends WP_UnitTestCase {
switch_theme( WP_DEFAULT_THEME );
}
/**
* @ticket 59358
*/
public function test_get_block_editor_settings_without_post_content_block() {
$post_editor_context = new WP_Block_Editor_Context( array( 'post' => get_post() ) );
$settings = get_block_editor_settings( array(), $post_editor_context );
$this->assertArrayNotHasKey( 'postContentAttributes', $settings );
}
/**
* @ticket 52920
* @expectedDeprecated block_editor_settings

View File

@@ -185,6 +185,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
'Block Theme [0.4.0]',
'Block Theme [1.0.0] in subdirectory',
'Block Theme Deprecated Path',
'Block Theme Post Content Default',
'Block Theme with defined Typography Fonts',
'Empty `fontFace` in theme.json - no webfonts defined',
'A theme with the Update URI header',