mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-06 19:01:44 +01:00
e335b68afc
This includes the following fixes: - Generate babel polyfill dynamically https://github.com/WordPress/gutenberg/pull/31279 - Improve the List View component https://github.com/WordPress/gutenberg/pull/31290 https://github.com/WordPress/gutenberg/pull/32063 - Template mode: - Fix embed dimensions https://github.com/WordPress/gutenberg/pull/32057 - Update the welcome guide https://github.com/WordPress/gutenberg/pull/32055 https://github.com/WordPress/gutenberg/pull/32026 - Don’t display the notice at the same time as the welcome guide https://github.com/WordPress/gutenberg/pull/32076 - Remove MetaBoxes https://github.com/WordPress/gutenberg/pull/32315 - Update the title area https://github.com/WordPress/gutenberg/pull/32037 - Widgets Screen: - Fix unsaved changes https://github.com/WordPress/gutenberg/pull/31757 - Fix toolbar alignment https://github.com/WordPress/gutenberg/pull/31991 - Fix block toolbar position after scroll https://github.com/WordPress/gutenberg/pull/32212 - Fix the visible widget area header https://github.com/WordPress/gutenberg/pull/32262 - Fix legacy widgets preview https://github.com/WordPress/gutenberg/pull/32260 - - Block Widgets in the customizer: - Fix customizer title overlapping block toolbar https://github.com/WordPress/gutenberg/pull/32140 - Fix styling issues https://github.com/WordPress/gutenberg/pull/32072 - Fix escape key events https://github.com/WordPress/gutenberg/pull/32175 - Add preferences menu group label https://github.com/WordPress/gutenberg/pull/32259 - Fix creating and replacing legacy widgets https://github.com/WordPress/gutenberg/pull/32005 - Fix the welcome guide’s image https://github.com/WordPress/gutenberg/pull/32264 https://github.com/WordPress/gutenberg/pull/32302 - Fix Cover to Image transform duotone error https://github.com/WordPress/gutenberg/pull/32006 - Remove filter_var usage from blocks https://github.com/WordPress/gutenberg/pull/32046 - Fix image width for aligned Post Featured Image block https://github.com/WordPress/gutenberg/pull/32070 - Prevent excessive Image block re-rendering https://github.com/WordPress/gutenberg/pull/32102 - Remove gutenberg domain from core blocks https://github.com/WordPress/gutenberg/pull/32152 - Use the block editor context class for the the different settings filters https://github.com/WordPress/gutenberg/pull/32159 - Fix Latest Posts block grid view https://github.com/WordPress/gutenberg/pull/32160 - Fix preset classes generation per block https://github.com/WordPress/gutenberg/pull/32190 - Fix logic to enable custom colors and gradients https://github.com/WordPress/gutenberg/pull/32200 - Update the Site Logo logic to use a dedicated site option https://github.com/WordPress/gutenberg/pull/32229 - Limit the Latest Posts block’s featured image width https://github.com/WordPress/gutenberg/pull/32245 - Remove opacity animation in the canvas. https://github.com/WordPress/gutenberg/pull/32266 - Make the focus style valid CSS https://github.com/WordPress/gutenberg/pull/32305 - Fix theme.json styles for the core/list block https://github.com/WordPress/gutenberg/pull/32343 - Fix PHP notice when calling render_block https://github.com/WordPress/gutenberg/pull/32135 Props nosolosw, noisysocks. See #52991. Built from https://develop.svn.wordpress.org/trunk@51051 git-svn-id: http://core.svn.wordpress.org/trunk@50660 1a063a9b-81f0-0310-95a4-ce76da25c4cd
72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Elements styles block support.
|
|
*
|
|
* @package WordPress
|
|
* @since 5.8.0
|
|
*/
|
|
|
|
/**
|
|
* Render the elements stylesheet.
|
|
*
|
|
* @since 5.8.0
|
|
* @access private
|
|
*
|
|
* @param string $block_content Rendered block content.
|
|
* @param array $block Block object.
|
|
* @return string Filtered block content.
|
|
*/
|
|
function wp_render_elements_support( $block_content, $block ) {
|
|
$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.
|
|
* This code in the future when we have a public API
|
|
* should take advantage of WP_Theme_JSON::compute_style_properties
|
|
* and work for any element and style.
|
|
*/
|
|
if ( null === $link_color ) {
|
|
return $block_content;
|
|
}
|
|
|
|
$class_name = 'wp-elements-' . uniqid();
|
|
|
|
if ( strpos( $link_color, 'var:preset|color|' ) !== false ) {
|
|
// Get the name from the string and add proper styles.
|
|
$index_to_splice = strrpos( $link_color, '|' ) + 1;
|
|
$link_color_name = substr( $link_color, $index_to_splice );
|
|
$link_color = "var(--wp--preset--color--$link_color_name)";
|
|
}
|
|
$link_color_declaration = esc_html( safecss_filter_attr( "color: $link_color" ) );
|
|
|
|
$style = "<style>.$class_name a{" . $link_color_declaration . " !important;}</style>\n";
|
|
|
|
// Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
|
|
// Retrieve the opening tag of the first HTML element.
|
|
$html_element_matches = array();
|
|
preg_match( '/<[^>]+>/', $block_content, $html_element_matches, PREG_OFFSET_CAPTURE );
|
|
$first_element = $html_element_matches[0][0];
|
|
// If the first HTML element has a class attribute just add the new class
|
|
// as we do on layout and duotone.
|
|
if ( strpos( $first_element, 'class="' ) !== false ) {
|
|
$content = preg_replace(
|
|
'/' . preg_quote( 'class="', '/' ) . '/',
|
|
'class="' . $class_name . ' ',
|
|
$block_content,
|
|
1
|
|
);
|
|
} else {
|
|
// If the first HTML element has no class attribute we should inject the attribute before the attribute at the end.
|
|
$first_element_offset = $html_element_matches[0][1];
|
|
$content = substr_replace( $block_content, ' class="' . $class_name . '"', $first_element_offset + strlen( $first_element ) - 1, 0 );
|
|
}
|
|
|
|
return $content . $style;
|
|
|
|
}
|
|
|
|
add_filter( 'render_block', 'wp_render_elements_support', 10, 2 );
|