Make WordPress Core


Ignore:
Timestamp:
09/25/2023 05:04:41 PM (22 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/deprecated.php

    r56664 r56682  
    58735873
    58745874/**
     5875 * Prints the CSS in the embed iframe header.
     5876 *
     5877 * @since 4.4.0
     5878 * @deprecated 6.4.0 Use wp_enqueue_embed_styles() instead.
     5879 */
     5880function print_embed_styles() {
     5881    _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_embed_styles' );
     5882
     5883    $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
     5884    $suffix    = SCRIPT_DEBUG ? '' : '.min';
     5885    ?>
     5886    <style<?php echo $type_attr; ?>>
     5887        <?php echo file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ); ?>
     5888    </style>
     5889    <?php
     5890}
     5891
     5892/**
     5893 * Prints the important emoji-related styles.
     5894 *
     5895 * @since 4.2.0
     5896 * @deprecated 6.4.0 Use wp_enqueue_emoji_styles() instead.
     5897 */
     5898function print_emoji_styles() {
     5899    _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_emoji_styles' );
     5900    static $printed = false;
     5901
     5902    if ( $printed ) {
     5903        return;
     5904    }
     5905
     5906    $printed = true;
     5907
     5908    $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
     5909    ?>
     5910    <style<?php echo $type_attr; ?>>
     5911    img.wp-smiley,
     5912    img.emoji {
     5913        display: inline !important;
     5914        border: none !important;
     5915        box-shadow: none !important;
     5916        height: 1em !important;
     5917        width: 1em !important;
     5918        margin: 0 0.07em !important;
     5919        vertical-align: -0.1em !important;
     5920        background: none !important;
     5921        padding: 0 !important;
     5922    }
     5923    </style>
     5924    <?php
     5925}
     5926
     5927/**
     5928 * Prints style and scripts for the admin bar.
     5929 *
     5930 * @since 3.1.0
     5931 * @deprecated 6.4.0 Use wp_enqueue_admin_bar_header_styles() instead.
     5932 */
     5933function wp_admin_bar_header() {
     5934    _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_header_styles' );
     5935    $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
     5936    ?>
     5937    <style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style>
     5938    <?php
     5939}
     5940
     5941/**
     5942 * Prints default admin bar callback.
     5943 *
     5944 * @since 3.1.0
     5945 * @deprecated 6.4.0 Use wp_enqueue_admin_bar_bump_styles() instead.
     5946 */
     5947function _admin_bar_bump_cb() {
     5948    _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_bump_styles' );
     5949    $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
     5950    ?>
     5951    <style<?php echo $type_attr; ?> media="screen">
     5952    html { margin-top: 32px !important; }
     5953    @media screen and ( max-width: 782px ) {
     5954      html { margin-top: 46px !important; }
     5955    }
     5956    </style>
     5957    <?php
     5958}
     5959
     5960/**
    58755961 * Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.
    58765962 *
Note: See TracChangeset for help on using the changeset viewer.