Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

@oandregal
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant