Make WordPress Core

Changeset 56094


Ignore:
Timestamp:
06/28/2023 05:12:46 PM (12 months ago)
Author:
spacedmonkey
Message:

Themes: Use improved support for child themes in wp_theme_has_theme_json().

Improve logic in wp_theme_has_theme_json(), to only check to see if theme.json exists in child theme, if the current theme is a child theme. Without this change, file_exists would be called twice on every request, which is wasteful.

Follow up to [56085].

Props spacedmonkey, SergeyBiryukov.
Fixes #57629.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/global-styles-and-settings.php

    r56085 r56094  
    408408    }
    409409
     410    $stylesheet_directory = get_stylesheet_directory();
     411    $template_directory   = get_template_directory();
     412
    410413    // This is the same as get_theme_file_path(), which isn't available in load-styles.php context
    411     if ( file_exists( get_stylesheet_directory() . '/theme.json' ) ) {
    412         $path = get_stylesheet_directory() . '/theme.json';
     414    if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) {
     415        $path = $stylesheet_directory . '/theme.json';
    413416    } else {
    414         $path = get_template_directory() . '/theme.json';
     417        $path = $template_directory . '/theme.json';
    415418    }
    416419
     
    418421    $path = apply_filters( 'theme_file_path', $path, 'theme.json' );
    419422
    420     if ( file_exists( $path ) ) {
    421         $theme_has_support = true;
    422     } else {
    423         $theme_has_support = false;
    424     }
     423    $theme_has_support = file_exists( $path );
    425424
    426425    return $theme_has_support;
Note: See TracChangeset for help on using the changeset viewer.