Skip to content

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Nov 20, 2025

Fixes: #73157

Problem

When KSES filters are active (via add_action( 'init', 'kses_init_filters' )), valid non-preset settings in Global Styles are being incorrectly filtered out. Specifically:

  • lightbox.enabled and lightbox.allowEditing for Image blocks

The issue occurs because remove_insecure_settings() only preserved:

  1. Presets (from PRESETS_METADATA)
  2. Indirect CSS properties (from INDIRECT_PROPERTIES_METADATA)

All other valid settings were being stripped, even though they're defined in VALID_SETTINGS and are safe scalar values or arrays.

Solution

Extended VALID_SETTINGS to also do type validation (as well as schema key validation) for the lightbox settings only (for now).

The idea is that VALID_SETTINGS values will act as type validation for further valid settings.

Testing Instructions

Manual Testing

  1. Enable KSES filters:

    add_action( 'init', 'kses_init_filters' );

    Add this to your theme's functions.php or a plugin.

  2. Test Image Block Lightbox Settings:

    • Go to Appearance > Editor > Styles
    • Navigate to Blocks > Image
    • Open the Settings panel
    • Toggle the "Enlarge on click" (lightbox) setting
    • Save the changes
    • Expected: The setting should persist after saving and page reload
    • Before fix: The setting would revert after saving
  3. Test Other Valid Settings:

    • Try changing other valid settings in Global Styles (e.g., layout settings, spacing settings)
    • Save and verify they persist
    • Expected: All valid settings should be preserved

Automated Testing

Run the PHPUnit tests:

npm run test:unit:php:base -- --filter WP_Theme_JSON_Gutenberg_Test

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like this approach and it gives room for adding additional settings further down the track. While there are other boolean values we could add, this addresses the issue with the lightbox which is that there is a user-facing feature that folks should be able to interact with, that currently doesn't work when KSES filters are active.

Whereas for other boolean settings like appearanceTools or useRootPAddingAwareAlignments, there isn't a UI for them, so it isn't as critical that we (yet) support them. But that could be something to look at further down the track.

For now, I'm in favour of going with this approach.

Arguably, it could be possible to extend the VALID_SETTINGS to include types instead of null as a value... but I like the approach you've gone with here of keeping them separate, which ensures that VALID_SETTINGS remains fairly simple, too.

I see this PR is still a draft (and that the Github action is complaining that there isn't a corresponding core PR), but IMO this is a good fix, so I'll give it the ✅ and it's working nicely for me in testing.

Comment on lines 3798 to 3914
// Validate the type.
$is_valid_type = false;
switch ( $type ) {
case 'boolean':
$is_valid_type = is_bool( $value );
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this — it gives room for eventually adding settings that might be string values that need a particular kind of validation, too.

Comment on lines 3005 to 3006
public function test_safe_settings_paths_should_exist_in_valid_settings() {
// Verify all paths in SAFE_SETTINGS exist in VALID_SETTINGS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice, thanks for adding this in! I like that this ensures that SAFE_SETTINGS is always a subset of VALID_SETTINGS 👍

@ramonjd ramonjd self-assigned this Nov 20, 2025
@ramonjd ramonjd marked this pull request as ready for review November 20, 2025 05:16
@github-actions
Copy link

github-actions bot commented Nov 20, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: mmtr <[email protected]>
Co-authored-by: oandregal <[email protected]>
Co-authored-by: t-hamano <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@andrewserong andrewserong added the [Type] Bug An existing feature does not function as intended label Nov 20, 2025
@ramonjd ramonjd added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label Nov 20, 2025
@ramonjd
Copy link
Member Author

ramonjd commented Nov 20, 2025

Thanks for the speedy and thorough review, @andrewserong

Arguably, it could be possible to extend the VALID_SETTINGS to include types instead of null as a value

I nearly went down that track, but baulked as I didn't want to cause more bugs given the way VALID_SETTINGS is being used, and then it wouldn't cater for exceptions.

I wonder if SAFE_SETTINGS should be a private const for now?

@andrewserong
Copy link
Contributor

I wonder if SAFE_SETTINGS should be a private const for now?

Good question. I see that none of the other consts in this class are declared as private, so I'd lean toward going with a simple const for consistency, but I don't feel strongly about it.

@ramonjd ramonjd requested a review from mmtr November 20, 2025 05:41
@github-actions
Copy link

github-actions bot commented Nov 20, 2025

Flaky tests detected in 459384c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19608681254
📝 Reported issues:

Copy link
Contributor

@mmtr mmtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This does solve the issue on my tests 🙂

@ramonjd ramonjd force-pushed the try/theme-json-allow-valid-settings branch 2 times, most recently from 67e0fb1 to 59f898d Compare November 21, 2025 03:11
@ramonjd
Copy link
Member Author

ramonjd commented Nov 21, 2025

@t-hamano is this a candidate for RC as well?

@t-hamano
Copy link
Contributor

is this a candidate for RC as well?

@ramonjd If I understand correctly, this issue has been around for quite some time, right? If so, it might be better to wait to ship to the core and aim for a more complete fix for the 7.0 release.

@ramonjd
Copy link
Member Author

ramonjd commented Nov 23, 2025

If I understand correctly, this issue has been around for quite some time, right? If so, it might be better to wait to ship to the core and aim for a more complete fix for the 7.0 release.

Ah okay, I only heard about this bug last week, but you're right. Thanks for tip.

Comment on lines +1315 to +1318
if ( is_array( $schema[ $key ] ) ) {
if ( ! is_array( $value ) ) {
unset( $tree[ $key ] );
} elseif ( wp_is_numeric_array( $value ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in WordPress/wordpress-develop@d1fafd8 were never backported to Gutenberg.

Just doing this for janitorial purposes and to make sure it doesn't affect these changes (it doesn't).

ramonjd referenced this pull request in WordPress/wordpress-develop Nov 23, 2025
Removes the custom `WP_Theme_JSON::is_assoc()` method again in favor of the existing `wp_is_numeric_array()` helper function.

Props mmaattiiaass, costdev, swissspidy, spacedmonkey.
Fixes #60360.

git-svn-id: https://develop.svn.wordpress.org/trunk@57751 602fd350-edb4-49c9-b593-d223f7449a82
…n valid settings while excluding presets and indirect properties. Update unit tests to verify preservation of valid block and top-level settings.
…mplementing O(1) lookups for preset and indirect property paths, improving performance during valid settings preservation.
… coalescing operator for improved readability.
… settings and enhance preserve_valid_settings method to validate and preserve safe settings. Add unit test to ensure safe settings are retained during property removal.
…FE_SETTINGS exist within VALID_SETTINGS, ensuring integrity of safe settings during validation.
…cumentation to streamline comments and focus on functionality.
…emoving the now redundant implementation and ensuring safe settings are preserved through direct validation, enhancing code clarity.
… internal use only, and update unit test to ensure removal of unsafe settings during validation.
…gs in the sanitize method, ensuring only valid boolean values are preserved. Update unit tests to verify behavior for boolean and non-boolean values in settings.
@ramonjd ramonjd force-pushed the try/theme-json-allow-valid-settings branch from 7c74bd1 to a461b75 Compare November 24, 2025 01:11
@ramonjd
Copy link
Member Author

ramonjd commented Nov 24, 2025

I think this is good to go. I've moved the type validation to the VALID_SETTINGS schema modal, but only for the lightbox for now.

We can slowly add more settings as the need arises.

I'll merge into Gutenberg, and if stable, then do the same for Core.

@andrewserong
Copy link
Contributor

We can slowly add more settings as the need arises.

Sounds good, and André gave us some good ideas for how we can support more validation types in the future, too 👍
Thanks for persisting with this!

@ramonjd ramonjd merged commit e74af14 into trunk Nov 24, 2025
36 checks passed
@ramonjd ramonjd deleted the try/theme-json-allow-valid-settings branch November 24, 2025 02:34
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to change the lightbox settings of the Image block within Global Styles when KSES is active

6 participants