diff --git a/src/wp-includes/block-supports/elements.php b/src/wp-includes/block-supports/elements.php index 740d522b0cf40..34960956519a4 100644 --- a/src/wp-includes/block-supports/elements.php +++ b/src/wp-includes/block-supports/elements.php @@ -17,7 +17,10 @@ * @return string Filtered block content. */ function wp_render_elements_support( $block_content, $block ) { - $link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', 'color', 'text' ), null ); + $link_color = null; + if ( ! empty( $block['attrs'] ) ) { + $link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', 'color', 'text' ), null ); + } /* * For now we only care about link color. diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 5aef6f1886cb6..5580e39285df7 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -609,6 +609,28 @@ function ( $carry, $element ) { return $selector . '{' . $declaration_block . '}'; } + /** + * Function that appends a sub-selector to a existing one. + * + * Given the compounded $selector "h1, h2, h3" + * and the $to_append selector ".some-class" the result will be + * "h1.some-class, h2.some-class, h3.some-class". + * + * @param string $selector Original selector. + * @param string $to_append Selector to append. + * + * @return string + */ + private static function append_to_selector( $selector, $to_append ) { + $new_selectors = array(); + $selectors = explode( ',', $selector ); + foreach ( $selectors as $sel ) { + $new_selectors[] = $sel . $to_append; + } + + return implode( ',', $new_selectors ); + } + /** * Given a settings array, it returns the generated rulesets * for the preset classes. @@ -633,7 +655,7 @@ private static function compute_preset_classes( $settings, $selector ) { foreach ( $values as $value ) { foreach ( $preset['classes'] as $class ) { $stylesheet .= self::to_ruleset( - $selector . '.has-' . $value['slug'] . '-' . $class['class_suffix'], + self::append_to_selector( $selector, '.has-' . $value['slug'] . '-' . $class['class_suffix'] ), array( array( 'name' => $class['property_name'], diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 12c89fad5ba7b..aceb3bd73bc5f 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -619,6 +619,28 @@ function test_get_editor_settings_no_theme_support() { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * Function that appends a sub-selector to a existing one. + * + * Given the compounded $selector "h1, h2, h3" + * and the $to_append selector ".some-class" the result will be + * "h1.some-class, h2.some-class, h3.some-class". + * + * @param string $selector Original selector. + * @param string $to_append Selector to append. + * + * @return string + */ + private static function append_to_selector( $selector, $to_append ) { + $new_selectors = array(); + $selectors = explode( ',', $selector ); + foreach ( $selectors as $sel ) { + $new_selectors[] = $sel . $to_append; + } + + return implode( ',', $new_selectors ); + } + /** * @ticket 52991 */