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

get_style_nodes should be compatible with parent method. #41217

Merged
merged 4 commits into from
May 23, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ protected static function get_blocks_metadata() {
*
* @since 5.8.0
*
* @param array $theme_json The tree to extract style nodes from.
* @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 ) {
protected static function get_style_nodes( $theme_json, $selectors = array() ) {
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
$nodes = array();
if ( ! isset( $theme_json['styles'] ) ) {
return $nodes;
Expand All @@ -147,7 +148,7 @@ protected static function get_style_nodes( $theme_json ) {
return $nodes;
}

$nodes = array_merge( $nodes, static::get_block_nodes( $theme_json ) );
$nodes = array_merge( $nodes, static::get_block_nodes( $theme_json, $selectors ) );

// 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 );
Expand All @@ -166,11 +167,12 @@ 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 = static::get_blocks_metadata();
private static function get_block_nodes( $theme_json, $selectors = array() ) {
$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
$nodes = array();
if ( ! isset( $theme_json['styles'] ) ) {
return $nodes;
Expand Down Expand Up @@ -215,9 +217,9 @@ private static function get_block_nodes( $theme_json ) {
/**
* Gets the CSS rules for a particular block from theme.json.
*
* @param array $block_metadata Meta data about the block to get styles for.
* @param array $block_metadata Metadata about the block to get styles for.
*
* @return array Styles for the block.
* @return string Styles for the block.
*/
public function get_styles_for_block( $block_metadata ) {
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
Expand Down