Make WordPress Core

Changeset 52743


Ignore:
Timestamp:
02/16/2022 10:18:33 PM (3 years ago)
Author:
jorgefilipecosta
Message:

Script Loader: Improvements to the load block support styles mechanism.

This commit applies feedback given to commit 52741. It changes the new function name, the file where it is located, and improves its documentation and marks.

Follow-up to [52741].
Props hellofromtonya, swissspidy, oandregal.
See #55148.

Location:
trunk/src/wp-includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/elements.php

    r52741 r52743  
    6969    }
    7070
    71     wp_enqueue_block_support( $style );
     71    wp_enqueue_block_support_styles( $style );
    7272
    7373    return $content;
  • trunk/src/wp-includes/block-supports/layout.php

    r52741 r52743  
    176176    );
    177177
    178     wp_enqueue_block_support( $style );
     178    wp_enqueue_block_support_styles( $style );
    179179
    180180    return $content;
  • trunk/src/wp-includes/blocks.php

    r52741 r52743  
    13331333}
    13341334add_filter( 'block_type_metadata', '_wp_multiple_block_styles' );
    1335 
    1336 /**
    1337  * This function takes care of adding inline styles
    1338  * in the proper place, depending on the theme in use.
    1339  *
    1340  * For block themes, it's loaded in the head.
    1341  * For classic ones, it's loaded in the body
    1342  * because the wp_head action (and wp_enqueue_scripts)
    1343  * happens before the render_block.
    1344  *
    1345  * See https://core.trac.wordpress.org/ticket/53494.
    1346  *
    1347  * @param string $style String containing the CSS styles to be added.
    1348  */
    1349 function wp_enqueue_block_support( $style ) {
    1350     $action_hook_name = 'wp_footer';
    1351     if ( wp_is_block_theme() ) {
    1352         $action_hook_name = 'wp_enqueue_scripts';
    1353     }
    1354     add_action(
    1355         $action_hook_name,
    1356         function () use ( $style ) {
    1357             echo "<style>$style</style>\n";
    1358         }
    1359     );
    1360 }
  • trunk/src/wp-includes/script-loader.php

    r52738 r52743  
    28842884    wp_enqueue_style( 'global-styles-css-custom-properties' );
    28852885}
     2886
     2887/**
     2888 * This function takes care of adding inline styles
     2889 * in the proper place, depending on the theme in use.
     2890 *
     2891 * @since 5.9.1
     2892 *
     2893 * For block themes, it's loaded in the head.
     2894 * For classic ones, it's loaded in the body
     2895 * because the wp_head action (and wp_enqueue_scripts)
     2896 * happens before the render_block.
     2897 *
     2898 * @link https://core.trac.wordpress.org/ticket/53494.
     2899 *
     2900 * @param string $style String containing the CSS styles to be added.
     2901 */
     2902function wp_enqueue_block_support_styles( $style ) {
     2903    $action_hook_name = 'wp_footer';
     2904    if ( wp_is_block_theme() ) {
     2905        $action_hook_name = 'wp_enqueue_scripts';
     2906    }
     2907    add_action(
     2908        $action_hook_name,
     2909        static function () use ( $style ) {
     2910            echo "<style>$style</style>\n";
     2911        }
     2912    );
     2913}
Note: See TracChangeset for help on using the changeset viewer.