Skip to content

Global Styles: fix presets that use a callback to validate user data#35255

Merged
oandregal merged 2 commits into
trunkfrom
update/secure-settings-to-use-value-func
Oct 7, 2021
Merged

Global Styles: fix presets that use a callback to validate user data#35255
oandregal merged 2 commits into
trunkfrom
update/secure-settings-to-use-value-func

Conversation

@oandregal
Copy link
Copy Markdown
Member

@oandregal oandregal commented Sep 30, 2021

Follow-up to #34667
Related #35228 #35248

This PR makes the remove_insecure_settings take the value from the callback registered by the preset via value_func, if it exists.

Note that for allowing the user to create their own duotones via the global styles sidebar, we'd need to also update or hook into the safecss_filter_attr function from WordPress core. I'm not doing this here because we don't need it so far.

How to test

  • Paste the following function at the end of lib/class-wp-theme-json-gutenberg.php (alternative create your own function in any file that's in scope):
/**
 * Test function.
 *
 * @param array $preset Color preset.
 *
 * @return string Color value.
 */
function return_color_key_value_from_preset( $preset ) {
	return $preset['color'];
}
  • In PRESETS_METADATA, remove the value_key of the first preset (color.palette) and paste this instead: 'value_func' => 'return_color_key_value_from_preset',. This is telling the preset will look up for the value via the callback we created.

Then, run npm run test-php: the expected result is that all the tests still pass. Also verify that the tests will fail in trunk if we use value_func for the color.palette.

@oandregal oandregal self-assigned this Sep 30, 2021
@oandregal oandregal requested a review from ajlende September 30, 2021 11:35
@oandregal oandregal added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Sep 30, 2021
@oandregal oandregal requested a review from a team October 4, 2021 10:59
Comment thread lib/class-wp-theme-json-gutenberg.php Outdated
Comment thread lib/class-wp-theme-json-gutenberg.php
@oandregal oandregal merged commit 061f1e6 into trunk Oct 7, 2021
@oandregal oandregal deleted the update/secure-settings-to-use-value-func branch October 7, 2021 06:41
@github-actions github-actions Bot added this to the Gutenberg 11.8 milestone Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants