Make WordPress Core

Opened 12 months ago

Closed 9 months ago

Last modified 9 months ago

#64280 closed defect (bug) (fixed)

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

Reported by: ramonopoly Owned by: ramonopoly
Priority: normal Milestone: 7.0
Component: Themes Version: 6.4
Severity: normal Keywords: has-patch has-unit-tests gutenberg-merge
Cc: Focuses:

Description

This ticket corresponds to the bug report in ​https://github.com/WordPress/gutenberg/issues/73157

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)

Step-by-step reproduction instructions

  1. Enable the KSES filters with add_action( 'init', 'kses_init_filters' );
  2. Go to Appearance > Editor
  3. Open the Styles sidebar
  4. Select "Blocks"
  5. Select "Image"
  6. Change the "Enlarge on click" options
  7. Save the changes

⚠️ Note how the changes are reverted

Change History (9)

This ticket was mentioned in ​PR #10534 on ​WordPress/wordpress-develop by ​@ramonopoly.


12 months ago
#1

A PR to sync ​https://github.com/WordPress/gutenberg/pull/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: ​https://github.com/WordPress/gutenberg/issues/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.

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

#2 @ellatrix
12 months ago

@ramonopoly Was this introduced in trunk (6.9)?

#3 @ramonopoly
12 months ago

  • Milestone Awaiting Review → 7.0

Was this introduced in trunk (6.9)

Are you asking which milestone this should be?

I've updated it to 7.0. The bug has been around for eons. See:

​https://github.com/WordPress/gutenberg/pull/73452#issuecomment-3562566719

#4 @ellatrix
12 months ago

Oh, I see it's filed under trunk which I thought means that it's introduced in the current unreleased version.

#5 @ramonopoly
12 months ago

  • Version trunk → 6.4

Oh, I see it's filed under trunk which I thought means that it's introduced in the current unreleased version.

Oh, that is a very good point.

I think the bug was introduced in 6.4!

​https://github.com/WordPress/gutenberg/pull/54509

So the "version" is the affected version. ​https://make.wordpress.org/core/handbook/contribute/trac/

I get it. I can update.

Thanks for checking.

#6 @ellatrix
12 months ago

No worries. There's a lot of tickets filed wrongly under trunk I think, I just picked a random one to figure out why :)

​@ramonopoly commented on ​PR #10534:


9 months ago
#7

Rebased. This change should be good for a final test before commit. It's been running on Gutenberg since v22.2

#8 @ramonopoly
9 months ago

  • Owner set to ramonopoly
  • Resolution → fixed
  • Status new → closed

In 61618:

WP_Theme_JSON: preserve valid non-preset settings for lightbox when KSES filters are active

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

Previously, when KSES filters were active (via add_action( 'init', 'kses_init_filters' )), valid non-preset settings in Global Styles were being incorrectly filtered out. For example, lightbox.enabled and lightbox.allowEditing for Image blocks.

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

Props ramonopoly, mmtr86, oandregal, wildworks, westonruter, andrewserong.

Fixes #64280.

Note: See TracTickets for help on using tickets.