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

Pseudo elements supports on button elements #43088

Merged
merged 3 commits into from
Aug 11, 2022
Merged
Changes from 1 commit
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
25 changes: 23 additions & 2 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 @@ -22,6 +22,7 @@ class WP_Theme_JSON_6_1 extends WP_Theme_JSON_6_0 {
*/
const VALID_ELEMENT_PSEUDO_SELECTORS = array(
'link' => array( ':hover', ':focus', ':active', ':visited' ),
'button' => array( ':hover', ':focus', ':active', ':visited' )
);

/**
Expand Down Expand Up @@ -481,9 +482,19 @@ protected static function get_style_nodes( $theme_json, $selectors = array() ) {
foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {

if ( isset( $theme_json['styles']['elements'][ $element ][ $pseudo_selector ] ) ) {

$element_selector = [];
// This converts selectors like '.wp-element-button, .wp-block-button__link'
// to an array, so that the pseudo selector is added to both parts of the selector.
$el_selectors = explode( ',', static::ELEMENTS[ $element ] );
foreach ( $el_selectors as $el_selector_item ) {
$element_selector[] = $el_selector_item . $pseudo_selector;
}
$element_selector = implode( ',', $element_selector );

$nodes[] = array(
'path' => array( 'styles', 'elements', $element ),
'selector' => static::ELEMENTS[ $element ] . $pseudo_selector,
'selector' => $element_selector,
);
}
}
Expand Down Expand Up @@ -566,9 +577,19 @@ private static function get_block_nodes( $theme_json, $selectors = array() ) {
if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) {

$block_selector = [];
// This converts selectors like '.wp-element-button, .wp-block-button__link'
MaggieCabrera marked this conversation as resolved.
Show resolved Hide resolved
// to an array, so that the pseudo selector is added to both parts of the selector.
$bl_selectors = explode( ',', $selectors[ $name ]['elements'][ $element ] );
foreach ( $bl_selectors as $bl_selector_item ) {
$block_selector[] = $bl_selector_item . $pseudo_selector;
}
$block_selector = implode( ',', $block_selector );

$nodes[] = array(
'path' => array( 'styles', 'blocks', $name, 'elements', $element ),
'selector' => $selectors[ $name ]['elements'][ $element ] . $pseudo_selector,
'selector' => $block_selector,
);
}
}
Expand Down