-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Theme JSON: migrate get_style_nodes to 6.1 #41262
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,17 +162,12 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n | |
* @return array Sanitized structure. | ||
*/ | ||
public static function remove_insecure_properties( $theme_json ) { | ||
$sanitized = array(); | ||
|
||
$theme_json = WP_Theme_JSON_Schema::migrate( $theme_json ); | ||
|
||
$sanitized = array(); | ||
$theme_json = WP_Theme_JSON_Schema::migrate( $theme_json ); | ||
$valid_block_names = array_keys( static::get_blocks_metadata() ); | ||
$valid_element_names = array_keys( static::ELEMENTS ); | ||
|
||
$theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names ); | ||
|
||
$blocks_metadata = static::get_blocks_metadata(); | ||
$style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata ); | ||
$theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names ); | ||
$style_nodes = static::get_style_nodes( $theme_json ); | ||
|
||
foreach ( $style_nodes as $metadata ) { | ||
$input = _wp_array_get( $theme_json, $metadata['path'], array() ); | ||
|
@@ -327,10 +322,9 @@ protected static function get_blocks_metadata() { | |
* @since 5.8.0 | ||
* | ||
* @param array $theme_json The tree to extract style nodes from. | ||
* @param array $selectors List of selectors per block. | ||
* @return array | ||
*/ | ||
protected static function get_style_nodes( $theme_json, $selectors = array() ) { | ||
protected static function get_style_nodes( $theme_json ) { | ||
$nodes = array(); | ||
if ( ! isset( $theme_json['styles'] ) ) { | ||
return $nodes; | ||
|
@@ -374,7 +368,7 @@ protected static function get_style_nodes( $theme_json, $selectors = array() ) { | |
return $nodes; | ||
} | ||
|
||
$nodes = array_merge( $nodes, static::get_block_nodes( $theme_json, $selectors ) ); | ||
$nodes = array_merge( $nodes, static::get_block_nodes( $theme_json ) ); | ||
|
||
// This filter allows us to modify the output of WP_Theme_JSON so that we can do things like loading block CSS independently. | ||
return apply_filters( 'gutenberg_get_style_nodes', $nodes ); | ||
|
@@ -393,13 +387,13 @@ public function get_styles_block_nodes() { | |
* An internal method to get the block nodes from a theme.json file. | ||
* | ||
* @param array $theme_json The theme.json converted to an array. | ||
* @param array $selectors Optional list of selectors per block. | ||
* | ||
* @return array The block nodes in theme.json. | ||
*/ | ||
private static function get_block_nodes( $theme_json, $selectors = array() ) { | ||
$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors; | ||
private static function get_block_nodes( $theme_json ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing params like this could be considered a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for chiming in. This PR is pretty stale and I was going to abandon it. After the min version of WordPress Gutenberg requires is moved to 6.1, maybe we could revisit it? There's a PR to bump it to 6.0 at the moment. |
||
$selectors = static::get_blocks_metadata(); | ||
$nodes = array(); | ||
|
||
if ( ! isset( $theme_json['styles'] ) ) { | ||
return $nodes; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/WordPress/gutenberg/pull/41262/files#r1043371996