Make WordPress Core


Ignore:
Timestamp:
09/01/2022 03:43:25 PM (2 years ago)
Author:
desrosj
Message:

Script Loader: Allow a priority to be passed to wp_enqueue_block_support_styles().

wp_enqueue_block_support_styles() attaches inline styles to the wp_head or wp_footer actions. This adds a priority parameter to the function to allow the styles to be given a loading order when necessary.

Props bernhard-reiter, ramonopoly.
See #56467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r53956 r54048  
    28962896
    28972897/**
    2898  * This function takes care of adding inline styles
    2899  * in the proper place, depending on the theme in use.
     2898 * Hooks inline styles in the proper place, depending on the active theme.
    29002899 *
    29012900 * @since 5.9.1
    2902  *
    2903  * For block themes, it's loaded in the head.
    2904  * For classic ones, it's loaded in the body
    2905  * because the wp_head action happens before
    2906  * the render_block.
     2901 * @since 6.1.0 Added the `$priority` parameter.
     2902 *
     2903 * For block themes, styles are loaded in the head.
     2904 * For classic ones, styles are loaded in the body because the wp_head action happens before render_block.
    29072905 *
    29082906 * @link https://core.trac.wordpress.org/ticket/53494.
    29092907 *
    2910  * @param string $style String containing the CSS styles to be added.
    2911  */
    2912 function wp_enqueue_block_support_styles( $style ) {
     2908 * @param string $style    String containing the CSS styles to be added.
     2909 * @param int    $priority To set the priority for the add_action.
     2910 */
     2911function wp_enqueue_block_support_styles( $style, $priority = 10 ) {
    29132912    $action_hook_name = 'wp_footer';
    29142913    if ( wp_is_block_theme() ) {
     
    29192918        static function () use ( $style ) {
    29202919            echo "<style>$style</style>\n";
    2921         }
     2920        },
     2921        $priority
    29222922    );
    29232923}
Note: See TracChangeset for help on using the changeset viewer.