Skip to content

Commit

Permalink
get_style_nodes should be compatible with parent method. (#41217)
Browse files Browse the repository at this point in the history
* get_style_nodes should be compatible with parent method. fix phpdoc.

* Formatting.

* Pass optional $selectors arg to get_block_nodes

* Update lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php

Co-authored-by: Andrew Serong <[email protected]>

Co-authored-by: Ramon <[email protected]>
Co-authored-by: Andrew Serong <[email protected]>
  • Loading branch information
3 people authored May 23, 2022
1 parent 8e44ad4 commit 78cea0f
Showing 1 changed file with 9 additions and 7 deletions.
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() ) {
$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

0 comments on commit 78cea0f

Please sign in to comment.