Changeset 58244
- Timestamp:
- 05/30/2024 04:38:26 AM (13 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r58242 r58244 1200 1200 } 1201 1201 foreach ( $style_nodes as &$node ) { 1202 $node ['selector'] = static::scope_selector( $options['scope'], $node['selector']);1202 $node = static::scope_style_node_selectors( $options['scope'], $node ); 1203 1203 } 1204 1204 unset( $node ); … … 1824 1824 $result = implode( ', ', $selectors_scoped ); 1825 1825 return $result; 1826 } 1827 1828 /** 1829 * Scopes the selectors for a given style node. 1830 * 1831 * This includes the primary selector, i.e. `$node['selector']`, as well as any custom 1832 * selectors for features and subfeatures, e.g. `$node['selectors']['border']` etc. 1833 * 1834 * @since 6.6.0 1835 * 1836 * @param string $scope Selector to scope to. 1837 * @param array $node Style node with selectors to scope. 1838 * @return array Node with updated selectors. 1839 */ 1840 protected static function scope_style_node_selectors( $scope, $node ) { 1841 $node['selector'] = static::scope_selector( $scope, $node['selector'] ); 1842 1843 if ( empty( $node['selectors'] ) ) { 1844 return $node; 1845 } 1846 1847 foreach ( $node['selectors'] as $feature => $selector ) { 1848 if ( is_string( $selector ) ) { 1849 $node['selectors'][ $feature ] = static::scope_selector( $scope, $selector ); 1850 } 1851 if ( is_array( $selector ) ) { 1852 foreach ( $selector as $subfeature => $subfeature_selector ) { 1853 $node['selectors'][ $feature ][ $subfeature ] = static::scope_selector( $scope, $subfeature_selector ); 1854 } 1855 } 1856 } 1857 1858 return $node; 1826 1859 } 1827 1860 -
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r58241 r58244 5590 5590 ); 5591 5591 } 5592 5593 /** 5594 * Tests the correct scoping of selectors for a style node. 5595 * 5596 * @ticket 61119 5597 */ 5598 public function test_scope_style_node_selectors() { 5599 $theme_json = new ReflectionClass( 'WP_Theme_JSON' ); 5600 5601 $func = $theme_json->getMethod( 'scope_style_node_selectors' ); 5602 $func->setAccessible( true ); 5603 5604 $node = array( 5605 'name' => 'core/image', 5606 'path' => array( 'styles', 'blocks', 'core/image' ), 5607 'selector' => '.wp-block-image', 5608 'selectors' => array( 5609 'root' => '.wp-block-image', 5610 'border' => '.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder', 5611 'typography' => array( 5612 'textDecoration' => '.wp-block-image caption', 5613 ), 5614 'filter' => array( 5615 'duotone' => '.wp-block-image img, .wp-block-image .components-placeholder', 5616 ), 5617 ), 5618 ); 5619 5620 $actual = $func->invoke( null, '.custom-scope', $node ); 5621 $expected = array( 5622 'name' => 'core/image', 5623 'path' => array( 'styles', 'blocks', 'core/image' ), 5624 'selector' => '.custom-scope .wp-block-image', 5625 'selectors' => array( 5626 'root' => '.custom-scope .wp-block-image', 5627 'border' => '.custom-scope .wp-block-image img, .custom-scope .wp-block-image .wp-block-image__crop-area, .custom-scope .wp-block-image .components-placeholder', 5628 'typography' => array( 5629 'textDecoration' => '.custom-scope .wp-block-image caption', 5630 ), 5631 'filter' => array( 5632 'duotone' => '.custom-scope .wp-block-image img, .custom-scope .wp-block-image .components-placeholder', 5633 ), 5634 ), 5635 ); 5636 5637 $this->assertEquals( $expected, $actual ); 5638 } 5592 5639 }
Note: See TracChangeset
for help on using the changeset viewer.