mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-02 16:59:35 +01:00
a225c5cdc6
This also includes: - The removal of the Post Author block. - Renaming build_query_vars_from_query_block function. - Update the block supports. Props gziolo. See #52991. -This line, and those below, will be ignored-- M package-lock.json M package.json M src/wp-includes/assets/script-loader-packages.php M src/wp-includes/block-supports/colors.php AM src/wp-includes/block-supports/elements.php D src/wp-includes/block-supports/padding.php AM src/wp-includes/block-supports/spacing.php M src/wp-includes/block-supports/typography.php M src/wp-includes/blocks/column/block.json M src/wp-includes/blocks/index.php D src/wp-includes/blocks/post-author D src/wp-includes/blocks/post-author.php M src/wp-includes/blocks/post-content.php M src/wp-includes/blocks/post-featured-image.php M src/wp-includes/blocks/query/block.json M src/wp-includes/blocks/query-loop/block.json M src/wp-includes/blocks/query-loop.php M src/wp-includes/blocks/query-pagination/block.json M src/wp-includes/blocks/query-pagination-next.php M src/wp-includes/blocks/query-pagination-numbers.php M src/wp-includes/blocks/site-tagline/block.json M src/wp-includes/blocks/site-title/block.json M src/wp-includes/blocks.php M src/wp-settings.php M tests/phpunit/tests/blocks/block.php M tools/webpack/packages.js Built from https://develop.svn.wordpress.org/trunk@50945 git-svn-id: http://core.svn.wordpress.org/trunk@50554 1a063a9b-81f0-0310-95a4-ce76da25c4cd
69 lines
2.3 KiB
PHP
69 lines
2.3 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 = _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 );
|