WP_Theme_JSON::get_style_nodes() WordPress Method
This method returns an array of style nodes for the current theme.
WP_Theme_JSON::get_style_nodes( array $theme_json, array $selectors = array() ) #
Builds metadata for the style nodes, which returns in the form of:
Description
[ [ ‘path’ => [ ‘path’, ‘to’, ‘some’, ‘node’ ], ‘selector’ => ‘CSS selector for some node’, ‘duotone’ => ‘CSS selector for duotone for some node’ ], [ ‘path’ => [‘path’, ‘to’, ‘other’, ‘node’ ], ‘selector’ => ‘CSS selector for other node’, ‘duotone’ => null ], ]
Parameters
- $theme_json
(array)(Required)The tree to extract style nodes from.
- $selectors
(array)(Optional)List of selectors per block.
Default value: array()
Return
(array)
Source
File: wp-includes/class-wp-theme-json.php
protected static function get_style_nodes( $theme_json, $selectors = array() ) { $nodes = array(); if ( ! isset( $theme_json['styles'] ) ) { return $nodes; } // Top-level. $nodes[] = array( 'path' => array( 'styles' ), 'selector' => static::ROOT_BLOCK_SELECTOR, ); if ( isset( $theme_json['styles']['elements'] ) ) { foreach ( $theme_json['styles']['elements'] as $element => $node ) { $nodes[] = array( 'path' => array( 'styles', 'elements', $element ), 'selector' => static::ELEMENTS[ $element ], ); } } // Blocks. if ( ! isset( $theme_json['styles']['blocks'] ) ) { return $nodes; } foreach ( $theme_json['styles']['blocks'] as $name => $node ) { $selector = null; if ( isset( $selectors[ $name ]['selector'] ) ) { $selector = $selectors[ $name ]['selector']; } $duotone_selector = null; if ( isset( $selectors[ $name ]['duotone'] ) ) { $duotone_selector = $selectors[ $name ]['duotone']; } $nodes[] = array( 'path' => array( 'styles', 'blocks', $name ), 'selector' => $selector, 'duotone' => $duotone_selector, ); if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { $nodes[] = array( 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), 'selector' => $selectors[ $name ]['elements'][ $element ], ); } } } return $nodes; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |