Make WordPress Core

Changeset 55427


Ignore:
Timestamp:
02/27/2023 05:30:07 PM (12 months ago)
Author:
flixos90
Message:

Twenty Twenty: Avoid PHP warnings in 8.1 due to incorrect usage of wp_add_inline_style().

This changeset adjusts the logic to use a more defensive approach, to avoid passing potentially invalid values to wp_add_inline_style().

Props flixos90, mukesh27, costdev, swissspidy, poena, sabernhardt.
Fixes #57777.

Location:
trunk/src/wp-content/themes/twentytwenty
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-non-latin-languages.php

    r54314 r55427  
    2626         *
    2727         * @param string $type Whether to return CSS for the "front-end", "block-editor", or "classic-editor".
    28          * @return void
     28         * @return string|null Custom CSS, or null if not applicable.
    2929         */
    3030        public static function get_non_latin_css( $type = 'front-end' ) {
     
    106106            // Return if the selected language has no fallback fonts.
    107107            if ( empty( $font_family[ $locale ] ) ) {
    108                 return;
     108                return null;
    109109            }
    110110
     
    127127            // Return if the specified type doesn't exist.
    128128            if ( empty( $elements[ $type ] ) ) {
    129                 return;
     129                return null;
    130130            }
    131131
  • trunk/src/wp-content/themes/twentytwenty/functions.php

    r55276 r55427  
    197197
    198198    // Add output of Customizer settings as inline style.
    199     wp_add_inline_style( 'twentytwenty-style', twentytwenty_get_customizer_css( 'front-end' ) );
     199    $customizer_css = twentytwenty_get_customizer_css( 'front-end' );
     200    if ( $customizer_css ) {
     201        wp_add_inline_style( 'twentytwenty-style', $customizer_css );
     202    }
    200203
    201204    // Add print CSS.
     
    425428
    426429    // Add inline style from the Customizer.
    427     wp_add_inline_style( 'twentytwenty-block-editor-styles', twentytwenty_get_customizer_css( 'block-editor' ) );
     430    $customizer_css = twentytwenty_get_customizer_css( 'block-editor' );
     431    if ( $customizer_css ) {
     432        wp_add_inline_style( 'twentytwenty-block-editor-styles', $customizer_css );
     433    }
    428434
    429435    // Add inline style for non-latin fonts.
    430     wp_add_inline_style( 'twentytwenty-block-editor-styles', TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' ) );
     436    $custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' );
     437    if ( $custom_css ) {
     438        wp_add_inline_style( 'twentytwenty-block-editor-styles', $custom_css );
     439    }
    431440
    432441    // Enqueue the editor script.
     
    465474
    466475    $styles = twentytwenty_get_customizer_css( 'classic-editor' );
     476
     477    if ( ! $styles ) {
     478        return $mce_init;
     479    }
    467480
    468481    if ( ! isset( $mce_init['content_style'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.