Skip to content

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Nov 20, 2025

A PR to sync WordPress/gutenberg#73452

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.

Related Issue: WordPress/gutenberg#73157

Solution

Added a new preserve_valid_settings() method and SAFE_SETTINGS const that work to preserves 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

Trac ticket: https://core.trac.wordpress.org/ticket/64280


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ramonopoly, westonruter.

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

@ramonjd ramonjd self-assigned this Nov 20, 2025
@ramonjd ramonjd added the bug label Nov 20, 2025
@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@ramonjd ramonjd requested a review from t-hamano November 21, 2025 03:16
Comment on lines 3697 to 3700
* @param array $input Input settings to process.
* @param array $output Output settings array (passed by reference).
* @param array $schema Schema to validate against (typically VALID_SETTINGS).
* @param array $path Current path in the schema (for recursive calls).
Copy link
Member

Choose a reason for hiding this comment

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

This seems like an opportunity to supply a more specific type for the $path parameter, like array<string|int>:

Suggested change
* @param array $input Input settings to process.
* @param array $output Output settings array (passed by reference).
* @param array $schema Schema to validate against (typically VALID_SETTINGS).
* @param array $path Current path in the schema (for recursive calls).
* @param array $input Input settings to process.
* @param array $output Output settings array (passed by reference).
* @param array $schema Schema to validate against (typically VALID_SETTINGS).
* @param array<string|int> $path Current path in the schema (for recursive calls).

At first I was thinking string[], but in looking at _wp_array_set(), it has this logic:

foreach ( $path as $path_element ) {
if (
! is_string( $path_element ) && ! is_integer( $path_element ) &&
! is_null( $path_element )
) {
return;
}
}

Curiously, there is no _doing_it_wrong() here. Also curious is that that null is apparently allowed among the $path array? This seems wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good spotting. yeah it seems weird that $path = array('a', null, 'b') is allowed.

Looks like the tests don't cover it either

https://github.com/WordPress/wordpress-develop/blob/a1071476c73e110d214b1c25cba0b27ebb506386/tests/phpunit/tests/functions/wpArraySet.php

…set, non-CSS settings during property removal. Added unit tests to validate the functionality of safe settings and their existence in VALID_SETTINGS.
…e_properties`.

This update includes the ticket number 64280 in the documentation for the tests that validate safe settings and their paths in valid settings.
… used only internally. Update unit tests to validate the removal of insecure properties and ensure safe settings are not allowed to be unsafe.
…n settings. Introduce a new method to preserve valid typed settings based on schema markers. Update unit tests to ensure correct behavior for boolean values and their validation against the schema.
…o assertions. This improves clarity on expected outcomes for lightbox settings and appearance tools, ensuring better maintainability and understanding of test intentions.
…alls in `preserve_valid_typed_settings`. This change enhances consistency in method referencing within the class.
…ions for parameters in the preserve_valid_typed_settings method, enhancing clarity and type safety.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants