maithemewp / mai-engine

Other
17 stars 3 forks source link

Block inline CSS overriding button (and likely other) styles. #637

Closed JiveDig closed 9 months ago

JiveDig commented 10 months ago

This is a Media/Text block with text color set, and it's affecting <a> link colors.

CleanShot 2023-12-05 at 10 07 18

CleanShot 2023-12-05 at 10 05 57

JiveDig commented 10 months ago

Testing removing link attribute from the block data before it's parsed.

add_filter( 'render_block_data', 'mai_render_block_data_handle_link_color', 10, 3 );
/**
 * Removes inline styles from blocks.
 *
 * @since TBD
 *
 * @param array         $parsed_block The block being rendered.
 * @param array         $source_block An un-modified copy of $parsed_block, as it appeared in the source content.
 * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block.
 *
 * @return array
 */
function mai_render_block_data_handle_link_color( $parsed_block, $source_block, $parent_block ) {
    // Remove link colors from inline styles.
    if ( isset( $parsed_block['attrs']['style']['elements']['link']['color'] ) ) {
        unset( $parsed_block['attrs']['style']['elements']['link']['color'] );
    }

    return $parsed_block;
}