Make WordPress Core

Changeset 45732


Ignore:
Timestamp:
08/04/2019 12:01:14 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Site Health: If WP_DEFAULT_THEME doesn't exist, use WP_Theme::get_core_default_theme() as a fallback.

Props ajayghaghretiya1, juliobox, SergeyBiryukov.
Fixes #47299.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r45691 r45732  
    446446        $active_theme = wp_get_theme();
    447447
     448        // If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
     449        $default_theme = wp_get_theme( WP_DEFAULT_THEME );
     450        if ( ! $default_theme->exists() ) {
     451            $default_theme = WP_Theme::get_core_default_theme();
     452        }
     453
     454        if ( $default_theme ) {
     455            $has_default_theme = true;
     456
     457            if (
     458                $active_theme->get_stylesheet() === $default_theme->get_stylesheet()
     459            ||
     460                is_child_theme() && $active_theme->get_template() === $default_theme->get_template()
     461            ) {
     462                $using_default_theme = true;
     463            }
     464        }
     465
    448466        foreach ( $all_themes as $theme_slug => $theme ) {
    449467            $themes_total++;
    450468
    451             if ( WP_DEFAULT_THEME === $theme_slug ) {
    452                 $has_default_theme = true;
    453 
    454                 if ( get_stylesheet() === $theme_slug ) {
    455                     $using_default_theme = true;
    456                 }
    457             }
    458 
    459469            if ( array_key_exists( $theme_slug, $theme_updates ) ) {
    460470                $themes_need_updates++;
     
    463473
    464474        // If this is a child theme, increase the allowed theme count by one, to account for the parent.
    465         if ( $active_theme->parent() ) {
     475        if ( is_child_theme() ) {
    466476            $allowed_theme_count++;
    467 
    468             if ( $active_theme->get_template() === WP_DEFAULT_THEME ) {
    469                 $using_default_theme = true;
    470             }
    471477        }
    472478
     
    525531
    526532            // This is a child theme, so we want to be a bit more explicit in our messages.
    527             if ( $active_theme->parent() ) {
     533            if ( is_child_theme() ) {
    528534                // Recommend removing inactive themes, except a default theme, your current one, and the parent theme.
    529535                $result['status'] = 'recommended';
     
    565571                            /* translators: 1: The default theme for WordPress. 2: The currently active theme. 3: The active theme's parent theme. */
    566572                            __( 'To enhance your site’s security, we recommend you remove any themes you’re not using. You should keep %1$s, the default WordPress theme, %2$s, your current theme, and %3$s, its parent theme.' ),
    567                             WP_DEFAULT_THEME,
     573                            $default_theme ? $default_theme->name : WP_DEFAULT_THEME,
    568574                            $active_theme->name,
    569575                            $active_theme->parent()->name
     
    603609                            ),
    604610                            $themes_inactive,
    605                             WP_DEFAULT_THEME,
     611                            $default_theme ? $default_theme->name : WP_DEFAULT_THEME,
    606612                            $active_theme->name
    607613                        ),
Note: See TracChangeset for help on using the changeset viewer.