Make WordPress Core


Ignore:
Timestamp:
09/25/2023 05:04:41 PM (21 months ago)
Author:
spacedmonkey
Message:

Script Loader: Replace hardcoded output of style tags with calls to wp_add_inline_style.

In this commit, enhancements have been made by replacing manually constructed style tags with calls to wp_add_inline_style. Previously, numerous style tags were generated and output directly in the header, resulting in redundant code and bypassing the core's style enqueueing system. This approach made it challenging for third-party developers to manage and control the output of these style tags.

To ensure backward compatibility, the following functions have been deprecated and replaced:

  • print_embed_styles
  • print_emoji_styles
  • wp_admin_bar_header
  • _admin_bar_bump_cb

Backward compatibility shims have also been added, ensuring that if these functions were previously unhooked from there actions, they will continue to not output a style tag.

However, for the following functions, conversion to use inline styles was not feasible due to the potential disruption it might cause by changing the style tag IDs, potentially breaking JavaScript functionality for a number of plugins in the repository:

  • custom-background
  • wp-custom

These changes improve code maintainability and enhance the flexibility and control available to developers when managing style outputs within WordPress core.

Props spacedmonkey, hlunter, westonruter, flixos90.
Fixes #58775.

File:
1 edited

Legend:

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

    r56180 r56682  
    10601060
    10611061/**
    1062  * Prints the CSS in the embed iframe header.
    1063  *
    1064  * @since 4.4.0
    1065  */
    1066 function print_embed_styles() {
    1067     $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
    1068     $suffix    = SCRIPT_DEBUG ? '' : '.min';
    1069     ?>
    1070     <style<?php echo $type_attr; ?>>
    1071         <?php echo file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ); ?>
    1072     </style>
    1073     <?php
     1062 * Enqueues the CSS in the embed iframe header.
     1063 *
     1064 * @since 6.4.0
     1065 */
     1066function wp_enqueue_embed_styles() {
     1067    // Back-compat for plugins that disable functionality by unhooking this action.
     1068    if ( ! has_action( 'embed_head', 'print_embed_styles' ) ) {
     1069        return;
     1070    }
     1071    remove_action( 'embed_head', 'print_embed_styles' );
     1072
     1073    $suffix = wp_scripts_get_suffix();
     1074    $handle = 'wp-embed-template';
     1075    wp_register_style( $handle, false );
     1076    wp_add_inline_style( $handle, file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ) );
     1077    wp_enqueue_style( $handle );
    10741078}
    10751079
Note: See TracChangeset for help on using the changeset viewer.