Make WordPress Core

Changeset 55092


Ignore:
Timestamp:
01/18/2023 09:58:00 PM (2 years ago)
Author:
hellofromTonya
Message:

Themes: Revert caching from r55086.

Calls to wp-admin/load-styles.php do not include the loading of wp_cache_*() functions. With [55086], this caused a fatal error:

Fatal error: Uncaught Error: Call to undefined function wp_cache_get() in /wp-includes/global-styles-and-settings.php on line 285

In some production and local environments running trunk, the admin area looked broken as the styling was not loaded as there were no HTTP requests.

This commit reverts the caching from [55086] to restore sites running trunk until a solution is found.

Follow-up to [55086].

Props Otto42, dmsnell, costdev.
See #56975.

Location:
trunk
Files:
4 edited

Legend:

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

    r55086 r55092  
    265265 */
    266266function wp_theme_has_theme_json() {
    267     /*
    268      * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
    269      * @see `wp_cache_add_non_persistent_groups()`.
    270      *
    271      * The rationale for this is to make sure derived data from theme.json
    272      * is always fresh from the potential modifications done via hooks
    273      * that can use dynamic data (modify the stylesheet depending on some option,
    274      * settings depending on user permissions, etc.).
    275      * For some of the existing hooks to modify theme.json behavior:
    276      * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
    277      *
    278      * A different alternative considered was to invalidate the cache upon certain
    279      * events such as options add/update/delete, user meta, etc.
    280      * It was judged not enough, hence this approach.
    281      * @see https://github.com/WordPress/gutenberg/pull/45372
    282      */
    283     $cache_group       = 'theme_json';
    284     $cache_key         = 'wp_theme_has_theme_json';
    285     $theme_has_support = wp_cache_get( $cache_key, $cache_group );
    286 
    287     /*
    288      * $theme_has_support is stored as an int in the cache.
    289      *
    290      * The reason not to store it as a boolean is to avoid working
    291      * with the $found parameter which apparently had some issues in some implementations
    292      * @see https://developer.wordpress.org/reference/functions/wp_cache_get/
    293      *
    294      * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme
    295      * developer's workflow.
    296      *
    297      * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
    298      */
    299     if ( ! WP_DEBUG && is_int( $theme_has_support ) ) {
    300         return (bool) $theme_has_support;
    301     }
    302 
    303267    // Does the theme have its own theme.json?
    304268    $theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' );
     
    309273    }
    310274
    311     $theme_has_support = $theme_has_support ? 1 : 0;
    312 
    313     wp_cache_set( $cache_key, $theme_has_support, $cache_group );
    314 
    315     return (bool) $theme_has_support;
     275    return $theme_has_support;
    316276}
    317277
     
    322282 */
    323283function wp_clean_theme_json_cache() {
    324     wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' );
    325284    WP_Theme_JSON_Resolver::clean_cached_data();
    326285}
  • trunk/src/wp-includes/load.php

    r55086 r55092  
    754754        );
    755755
    756         wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
     756        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    757757    }
    758758
  • trunk/src/wp-includes/ms-blogs.php

    r55086 r55092  
    576576            }
    577577
    578             wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
     578            wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    579579        }
    580580    }
     
    667667            }
    668668
    669             wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
     669            wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    670670        }
    671671    }
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r55086 r55092  
    402402        );
    403403
    404         wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
     404        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    405405    }
    406406
Note: See TracChangeset for help on using the changeset viewer.