wp_theme_get_element_class_name example

add_action( 'init', 'register_block_core_comments' );

/** * Use the button block classes for the form-submit button. * * @param array $fields The default comment form arguments. * * @return array Returns the modified fields. */
function comments_block_form_defaults( $fields ) {
    if ( wp_is_block_theme() ) {
        $fields['submit_button'] = '<input name="%1$s" type="submit" id="%2$s" class="%3$s wp-block-button__link ' . wp_theme_get_element_class_name( 'button' ) . '" value="%4$s" />';
        $fields['submit_field']  = '<p class="form-submit wp-block-button">%1$s %2$s</p>';
    }

    return $fields;
}
add_filter( 'comment_form_defaults', 'comments_block_form_defaults' );

/** * Enqueues styles from the legacy `core/post-comments` block. These styles are * required only by the block's fallback. * * @param string $block_name Name of the new block type. */
add_action( 'init', 'register_block_core_post_comments_form' );

/** * Use the button block classes for the form-submit button. * * @param array $fields The default comment form arguments. * * @return array Returns the modified fields. */
function post_comments_form_block_form_defaults( $fields ) {
    if ( wp_is_block_theme() ) {
        $fields['submit_button'] = '<input name="%1$s" type="submit" id="%2$s" class="wp-block-button__link ' . wp_theme_get_element_class_name( 'button' ) . '" value="%4$s" />';
        $fields['submit_field']  = '<p class="form-submit wp-block-button">%1$s %2$s</p>';
    }

    return $fields;
}
$button_internal_markup = wp_kses_post( $attributes['buttonText'] );
            }
        } else {
            $button_classes[]       = 'has-icon';
            $button_internal_markup =
                '<svg class="search-icon" viewBox="0 0 24 24" width="24" height="24"> <path d="M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z"></path> </svg>';
        }

        // Include the button element class.         $button_classes[] = wp_theme_get_element_class_name( 'button' );
        $button           = new WP_HTML_Tag_Processor( sprintf( '<button type="submit" %s>%s</button>', $inline_styles['button']$button_internal_markup ) );

        if ( $button->next_tag() ) {
            $button->add_class( implode( ' ', $button_classes ) );
            if ( 'expand-searchfield' === $attributes['buttonBehavior'] && 'button-only' === $attributes['buttonPosition'] ) {
                $button->set_attribute( 'aria-label', __( 'Expand search field' ) );
                $button->set_attribute( 'aria-controls', 'wp-block-search__input-' . $input_id );
                $button->set_attribute( 'aria-expanded', 'false' );
            } else {
                $button->set_attribute( 'aria-label', wp_strip_all_tags( $attributes['buttonText'] ) );
            }
        }
Home | Imprint | This part of the site doesn't use cookies.