Make WordPress Core

Opened 21 months ago

Last modified 20 months ago

#57599 new defect (bug)

`wp_theme_json_data_default` filter is not properly to setting `settings.spacing.padding` value

Reported by: fabiankaegy's profile fabiankaegy Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: Editor Keywords: has-unit-tests
Focuses: Cc:

Description

There appears to be an issue in how the theme.json filters get currently applied. When trying to use the filter on the default layer to enable the settings.spacing.padding option it doesn't work as expected.

Within a plugin I'm trying to call the filter like so:

<?php
/**
 * Plugin Name: Test
 */

add_filter( 'wp_theme_json_data_default', 'test_filter_core_theme_json' );

function test_filter_core_theme_json( $theme_json ) {
        $new_data = [
                'version' => 2,
                'settings' => [
                        'spacing' => [
                                'margin' => true,
                                'padding' => true,
                        ],
                ],
        ];

        return $theme_json->update_with( $new_data );
};

And for Theme I'm using a completely empty theme that has this theme.json file:

{
        "version": 2,
        "$schema": "https://schemas.wp.org/trunk/theme.json"
}

The expected result is that the padding dimension panel in for example the group block could be added. But that isn't the case. At the same time the margin option which I've also added in the example above does work as intended.

If you change the theme.json file to set the padding option to true it does work. And also if you change the filter that gets used to the theme layer it works as expected:

<?php
/**
 * Plugin Name: Test
 */

add_filter( 'wp_theme_json_data_theme', 'test_filter_core_theme_json' );

function test_filter_core_theme_json( $theme_json ) {
        $new_data = [
                'version' => 2,
                'settings' => [
                        'spacing' => [
                                'margin' => true,
                                'padding' => true,
                        ],
                ],
        ];

        return $theme_json->update_with( $new_data );
};

or

{
        "version": 2,
        "$schema": "https://schemas.wp.org/trunk/theme.json",
        "settings": {
                "spacing": {
                        "padding": true
                }
        }
}

Change History (5)

This ticket was mentioned in Slack in #core-editor by fabiankaegy. View the logs.


21 months ago

#2 @fabiankaegy
21 months ago

You can also verify that the setting isn't getting applied correctly using:

<?php
add_action( 'enqueue_block_editor_assets', function() {
        $core_settings = WP_Theme_JSON_Resolver::get_core_data()->get_settings();
        $block_settings = WP_Theme_JSON_Resolver::get_block_data()->get_settings();
        $theme_settings = WP_Theme_JSON_Resolver::get_theme_data()->get_settings();
        $user_settings = WP_Theme_JSON_Resolver::get_user_data()->get_settings();
        $settings = WP_Theme_JSON_Resolver::get_merged_data()->get_settings();
} );

with XDebug for example

This ticket was mentioned in PR #3969 on WordPress/wordpress-develop by @fabiankaegy.


20 months ago
#3

  • Keywords has-patch has-unit-tests added

#4 @fabiankaegy
20 months ago

I added a draft PR that contains a failing test case which covers the issue I described. The patch does not currently contain a solution for the issue. Just a test case to ensure the functionality has proper test coverage.

#5 @fabiankaegy
20 months ago

  • Keywords has-patch removed

I removed the has-patch label since currently all I've done is add a unit test.

Note: See TracTickets for help on using tickets.