From 4a44a52811e332cc4ae71ad2c4bae4655fd768c2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 13 Nov 2026 23:33:03 -0800 Subject: [PATCH 01/27] Build/Test Tools: Stop PHPStan remembering possibly impure return values. By default, PHPStan assumes a call returns the same value every time unless the function is marked `@phpstan-impure`, so a repeated check is reported as always true or always false even when global state has changed in between. Silencing such a report tends to mean deleting a check that is needed. Set `rememberPossiblyImpureFunctionValues: false`, so that only calls marked `@phpstan-pure` are remembered. Errors then lean conservative: a value read twice is not assumed to be the same. This retires reports that relied on the assumption: * Five baseline entries for `if.alwaysTrue`, `booleanNot.alwaysTrue`, and `booleanAnd.leftAlwaysTrue`, emptying the last of those baselines. * Three of the HTML Processor's ignored errors. * The inline ignore in Twenty Nineteen's `header.php`, which was needed only because `twentynineteen_can_show_post_thumbnail()` was assumed unchanged by `the_post()`. It also exposes nine `variable.undefined` errors, where a variable is assigned under one call of a conditional and read under a second call of it. These are baselined here and fixed in a follow-up. Co-Authored-By: Claude Opus 5.5 (medium effort) Claude-Code-Session-Id: dfb24569-a61a-4404-8588-60a387d2cccb --- phpstan.neon.dist | 20 ++++++----- .../themes/twentynineteen/header.php | 2 +- .../baselines/booleanAnd.leftAlwaysTrue.neon | 25 ------------- .../baselines/booleanNot.alwaysTrue.neon | 10 ------ tests/phpstan/baselines/if.alwaysTrue.neon | 10 ------ .../phpstan/baselines/variable.undefined.neon | 35 +++++++++++++++++++ 6 files changed, 48 insertions(+), 54 deletions(-) delete mode 100644 tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon diff --git a/phpstan.neon.dist b/phpstan.neon.dist index cbaa19f3e8db1..acc8de94499fc 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -28,7 +28,6 @@ includes: - tests/phpstan/baselines/argument.unresolvableType.neon - tests/phpstan/baselines/assign.propertyType.neon - tests/phpstan/baselines/binaryOp.invalid.neon - - tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon - tests/phpstan/baselines/booleanNot.alwaysTrue.neon - tests/phpstan/baselines/class.notFound.neon - tests/phpstan/baselines/deadCode.unreachable.neon @@ -77,6 +76,16 @@ parameters: level: 5 reportUnmatchedIgnoredErrors: true + # Do not assume that a function or method returns the same value each time it is called with the same + # arguments, unless it is marked `@phpstan-pure`. By default, PHPStan remembers the return value of any call + # not marked `@phpstan-impure`, so that checking it again, even after global state has changed (for example + # by `the_post()` or a filter), is reported as always true or always false. When that assumption is wrong, + # the natural way to silence the error is to delete a check that is in fact needed. With remembering + # disabled, the failure mode is conservative instead: a value read twice is not assumed to be the same, so + # the fix is to read it once into a variable. Few functions in core can be `@phpstan-pure`, since most read + # global state or apply filters. + # https://phpstan.org/blog/remembering-and-forgetting-returned-values + rememberPossiblyImpureFunctionValues: false # The following ignored errors are not intended to be fixed, as distinct from the baselines # included above. @@ -175,20 +184,15 @@ parameters: identifier: greaterOrEqual.alwaysFalse count: 1 path: src/wp-includes/html-api/class-wp-html-processor.php - - - message: '#^Left side of && is always true\.$#' - identifier: booleanAnd.leftAlwaysTrue - count: 1 - path: src/wp-includes/html-api/class-wp-html-processor.php - message: '#^Unreachable statement \- code above always terminates\.$#' identifier: deadCode.unreachable - count: 15 + count: 14 path: src/wp-includes/html-api/class-wp-html-processor.php - message: '#^If condition is always true\.$#' identifier: if.alwaysTrue - count: 2 + count: 1 path: src/wp-includes/html-api/class-wp-html-processor.php - # The early return at the start of step() narrows $last_error to null, and PHPStan does not see that diff --git a/src/wp-content/themes/twentynineteen/header.php b/src/wp-content/themes/twentynineteen/header.php index 0212e46d34311..483355892799e 100644 --- a/src/wp-content/themes/twentynineteen/header.php +++ b/src/wp-content/themes/twentynineteen/header.php @@ -41,7 +41,7 @@ responses ) > 0 ) { diff --git a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon deleted file mode 100644 index 10ed28f6b433d..0000000000000 --- a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon +++ /dev/null @@ -1,25 +0,0 @@ -# PHPStan baseline for the `booleanAnd.leftAlwaysTrue` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/booleanAnd.leftAlwaysTrue -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=booleanAnd.leftAlwaysTrue -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Left side of && is always true\.$#' - identifier: booleanAnd.leftAlwaysTrue - count: 1 - path: ../../../src/wp-includes/canonical.php diff --git a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon index b61a98cef358e..8469e02898398 100644 --- a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon +++ b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon @@ -18,11 +18,6 @@ parameters: ignoreErrors: - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../src/wp-admin/includes/class-custom-image-header.php - message: '#^Negated boolean expression is always true\.$#' identifier: booleanNot.alwaysTrue @@ -33,8 +28,3 @@ parameters: identifier: booleanNot.alwaysTrue count: 1 path: ../../../src/wp-includes/general-template.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../src/wp-includes/option.php diff --git a/tests/phpstan/baselines/if.alwaysTrue.neon b/tests/phpstan/baselines/if.alwaysTrue.neon index 6f5169ee0b1e6..3caa04ec7b2e5 100644 --- a/tests/phpstan/baselines/if.alwaysTrue.neon +++ b/tests/phpstan/baselines/if.alwaysTrue.neon @@ -18,18 +18,8 @@ parameters: ignoreErrors: - - - message: '#^If condition is always true\.$#' - identifier: if.alwaysTrue - count: 1 - path: ../../../src/wp-content/themes/twentynineteen/template-parts/footer/footer-widgets.php - message: '#^If condition is always true\.$#' identifier: if.alwaysTrue count: 1 path: ../../../src/wp-content/themes/twentytwenty/functions.php - - - message: '#^If condition is always true\.$#' - identifier: if.alwaysTrue - count: 1 - path: ../../../src/wp-content/themes/twentytwenty/template-parts/modal-menu.php diff --git a/tests/phpstan/baselines/variable.undefined.neon b/tests/phpstan/baselines/variable.undefined.neon index 1192b132f2626..bb6ca5a431958 100644 --- a/tests/phpstan/baselines/variable.undefined.neon +++ b/tests/phpstan/baselines/variable.undefined.neon @@ -183,6 +183,16 @@ parameters: identifier: variable.undefined count: 5 path: ../../../src/wp-admin/includes/class-wp-plugins-list-table.php + - + message: '#^Variable \$show_network_active might not be defined\.$#' + identifier: variable.undefined + count: 2 + path: ../../../src/wp-admin/includes/class-wp-plugins-list-table.php + - + message: '#^Variable \$authors_dropdown might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: ../../../src/wp-admin/includes/class-wp-posts-list-table.php - message: '#^Variable \$badge_class might not be defined\.$#' identifier: variable.undefined @@ -283,6 +293,11 @@ parameters: identifier: variable.undefined count: 9 path: ../../../src/wp-admin/maint/repair.php + - + message: '#^Variable \$update_data might not be defined\.$#' + identifier: variable.undefined + count: 2 + path: ../../../src/wp-admin/menu.php - message: '#^Variable \$current_user might not be defined\.$#' identifier: variable.undefined @@ -478,6 +493,11 @@ parameters: identifier: variable.undefined count: 6 path: ../../../src/wp-content/themes/twentyeleven/image.php + - + message: '#^Variable \$image might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: ../../../src/wp-content/themes/twentyeleven/showcase.php - message: '#^Variable \$post might not be defined\.$#' identifier: variable.undefined @@ -688,6 +708,11 @@ parameters: identifier: variable.undefined count: 1 path: ../../../src/wp-includes/general-template.php + - + message: '#^Variable \$post_type_object might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: ../../../src/wp-includes/general-template.php - message: '#^Variable \$current_blog might not be defined\.$#' identifier: variable.undefined @@ -708,6 +733,11 @@ parameters: identifier: variable.undefined count: 3 path: ../../../src/wp-includes/ms-settings.php + - + message: '#^Variable \$children might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: ../../../src/wp-includes/post.php - message: '#^Variable \$wp_template_path might not be defined\.$#' identifier: variable.undefined @@ -733,3 +763,8 @@ parameters: identifier: variable.undefined count: 1 path: ../../../src/wp-settings.php + - + message: '#^Variable \$site_domain might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: ../../../src/wp-signup.php From 76e07474a22573d54ffbcd062e2f83c28a282bf2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 2 Nov 2026 20:44:32 -0800 Subject: [PATCH 02/27] Code Quality: Define variables that a repeated conditional guards. In these places a variable is assigned under one call of a conditional and read under a second call of the same conditional. That holds only if the conditional returns the same value both times, which PHPStan no longer assumes now that it does not remember possibly impure return values. Either initialize the variable before the first check, where the second check never reads it otherwise, or read the conditional once into a local variable: * `$show_network_active` in `WP_Plugins_List_Table::prepare_items()`. * `$authors_dropdown` in `WP_Posts_List_Table::inline_edit()`. * `$update_data` in `wp-admin/menu.php`, using the `! isset()` guard the file already uses for the Themes and Plugins submenus. * `$children` in `wp_delete_post()`. * `is_subdomain_install()` in `show_blog_form()`. * `is_post_type_archive()` in `wp_title()`. * `has_post_thumbnail()` in Twenty Eleven's showcase template. This empties the baseline entries for these errors. Co-Authored-By: Claude Opus 5.5 (medium effort) Claude-Code-Session-Id: dfb24569-a61a-4404-8588-60a387d2cccb --- .../includes/class-wp-plugins-list-table.php | 1 + .../includes/class-wp-posts-list-table.php | 3 +- src/wp-admin/menu.php | 4 +++ .../themes/twentyeleven/showcase.php | 5 +-- src/wp-includes/general-template.php | 7 ++-- src/wp-includes/post.php | 3 +- src/wp-signup.php | 9 ++--- .../phpstan/baselines/variable.undefined.neon | 35 ------------------- 8 files changed, 20 insertions(+), 47 deletions(-) diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index 7778f21b4688b..7b4f1bc096628 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -184,6 +184,7 @@ public function prepare_items() { } } + $show_network_active = false; if ( ! $screen->in_admin( 'network' ) ) { $show = current_user_can( 'manage_network_plugins' ); /** diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index d461aacd312ae..fb0309281a112 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -1815,9 +1815,8 @@ public function inline_edit() { post_type, 'author' ) ) { - $authors_dropdown = ''; - if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) { $dropdown_name = 'post_author'; $dropdown_class = 'authors'; diff --git a/src/wp-admin/menu.php b/src/wp-admin/menu.php index 36b10211daa1b..a188cf7e70efd 100644 --- a/src/wp-admin/menu.php +++ b/src/wp-admin/menu.php @@ -40,6 +40,10 @@ } if ( ! is_multisite() ) { + if ( ! isset( $update_data ) ) { + $update_data = wp_get_update_data(); + } + if ( current_user_can( 'update_core' ) ) { $capability = 'update_core'; } elseif ( current_user_can( 'update_plugins' ) ) { diff --git a/src/wp-content/themes/twentyeleven/showcase.php b/src/wp-content/themes/twentyeleven/showcase.php index 349a1cb2c668b..ffbf2c3ef0f9a 100644 --- a/src/wp-content/themes/twentyeleven/showcase.php +++ b/src/wp-content/themes/twentyeleven/showcase.php @@ -105,7 +105,8 @@ */ $feature_class = 'feature-text'; - if ( has_post_thumbnail() ) { + $has_post_thumbnail = has_post_thumbnail(); + if ( $has_post_thumbnail ) { // ...but if it has a featured image let's add some class. $feature_class = 'feature-image small'; @@ -127,7 +128,7 @@ * If the thumbnail is as big as the header image * make it a large featured post, otherwise render it small */ - if ( has_post_thumbnail() ) { + if ( $has_post_thumbnail ) { if ( $image[1] >= $header_image_width ) { $thumbnail_size = 'large-feature'; } else { diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index bfb400cbda4cd..5833c1e3cd478 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -1606,7 +1606,8 @@ function wp_title( $sep = '»', $display = true, $seplocation = '' ) { } // If there's a post type archive. - if ( is_post_type_archive() ) { + $is_post_type_archive = is_post_type_archive(); + if ( $is_post_type_archive ) { $post_type = get_query_var( 'post_type' ); if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); @@ -1632,7 +1633,7 @@ function wp_title( $sep = '»', $display = true, $seplocation = '' ) { } // If there's an author. - if ( is_author() && ! is_post_type_archive() ) { + if ( is_author() && ! $is_post_type_archive ) { $author = get_queried_object(); if ( $author ) { $title = $author->display_name; @@ -1640,7 +1641,7 @@ function wp_title( $sep = '»', $display = true, $seplocation = '' ) { } // Post type archives with has_archive should override terms. - if ( is_post_type_archive() && $post_type_object->has_archive ) { + if ( $is_post_type_archive && $post_type_object->has_archive ) { $title = post_type_archive_title( '', false ); } diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index e0afc05cd1b54..b7646a6f2f7be 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4085,6 +4085,7 @@ function wp_delete_post( $post_id = 0, $force_delete = false ) { $parent_data = array( 'post_parent' => $post->post_parent ); $parent_where = array( 'post_parent' => $post_id ); + $children = array(); if ( is_post_type_hierarchical( $post->post_type ) ) { // Point children of this page to its parent, also clean the cache of affected children. $children_query = $wpdb->prepare( @@ -4188,7 +4189,7 @@ function wp_delete_post( $post_id = 0, $force_delete = false ) { clean_post_cache( $post ); - if ( is_post_type_hierarchical( $post->post_type ) && $children ) { + if ( $children ) { foreach ( $children as $child ) { clean_post_cache( $child ); } diff --git a/src/wp-signup.php b/src/wp-signup.php index dd4e5d5365f74..bc6bcdf159ce6 100644 --- a/src/wp-signup.php +++ b/src/wp-signup.php @@ -130,9 +130,10 @@ function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) { $errors = new WP_Error(); } - $current_network = get_network(); + $current_network = get_network(); + $is_subdomain_install = is_subdomain_install(); // Site name. - if ( ! is_subdomain_install() ) { + if ( ! $is_subdomain_install ) { echo ''; } else { echo ''; @@ -145,7 +146,7 @@ function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) { echo '

' . $errmsg_blogname . '

'; } - if ( ! is_subdomain_install() ) { + if ( ! $is_subdomain_install ) { echo ''; } else { $site_domain = preg_replace( '|^www\.|', '', $current_network->domain ); @@ -153,7 +154,7 @@ function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) { } if ( ! is_user_logged_in() ) { - if ( ! is_subdomain_install() ) { + if ( ! $is_subdomain_install ) { $site = $current_network->domain . $current_network->path . __( 'sitename' ); } else { $site = __( 'domain' ) . '.' . $site_domain . $current_network->path; diff --git a/tests/phpstan/baselines/variable.undefined.neon b/tests/phpstan/baselines/variable.undefined.neon index bb6ca5a431958..1192b132f2626 100644 --- a/tests/phpstan/baselines/variable.undefined.neon +++ b/tests/phpstan/baselines/variable.undefined.neon @@ -183,16 +183,6 @@ parameters: identifier: variable.undefined count: 5 path: ../../../src/wp-admin/includes/class-wp-plugins-list-table.php - - - message: '#^Variable \$show_network_active might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: ../../../src/wp-admin/includes/class-wp-plugins-list-table.php - - - message: '#^Variable \$authors_dropdown might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../src/wp-admin/includes/class-wp-posts-list-table.php - message: '#^Variable \$badge_class might not be defined\.$#' identifier: variable.undefined @@ -293,11 +283,6 @@ parameters: identifier: variable.undefined count: 9 path: ../../../src/wp-admin/maint/repair.php - - - message: '#^Variable \$update_data might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: ../../../src/wp-admin/menu.php - message: '#^Variable \$current_user might not be defined\.$#' identifier: variable.undefined @@ -493,11 +478,6 @@ parameters: identifier: variable.undefined count: 6 path: ../../../src/wp-content/themes/twentyeleven/image.php - - - message: '#^Variable \$image might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../src/wp-content/themes/twentyeleven/showcase.php - message: '#^Variable \$post might not be defined\.$#' identifier: variable.undefined @@ -708,11 +688,6 @@ parameters: identifier: variable.undefined count: 1 path: ../../../src/wp-includes/general-template.php - - - message: '#^Variable \$post_type_object might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../src/wp-includes/general-template.php - message: '#^Variable \$current_blog might not be defined\.$#' identifier: variable.undefined @@ -733,11 +708,6 @@ parameters: identifier: variable.undefined count: 3 path: ../../../src/wp-includes/ms-settings.php - - - message: '#^Variable \$children might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../src/wp-includes/post.php - message: '#^Variable \$wp_template_path might not be defined\.$#' identifier: variable.undefined @@ -763,8 +733,3 @@ parameters: identifier: variable.undefined count: 1 path: ../../../src/wp-settings.php - - - message: '#^Variable \$site_domain might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../src/wp-signup.php From 6070ae27ed55a51021cc87aad8d3bac818d41293 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 2 Nov 2026 20:48:15 -0800 Subject: [PATCH 03/27] Code Quality: Read `WP_Theme::errors()` once before using it. A common pattern checks `$theme->errors()` and then calls a method on a second `$theme->errors()`, such as `get_error_message()`. Now that PHPStan no longer remembers possibly impure return values, it does not assume the second call returns the `WP_Error` that the first one did, and reports calling a method on `WP_Error|false`. `errors()` cannot be marked `@phpstan-pure`, since it calls `is_wp_error()`, which fires the `is_wp_error_instance` action. So read it once into a variable instead, and use that for both the check and the call. Co-Authored-By: Claude Opus 5.5 (medium effort) Claude-Code-Session-Id: dfb24569-a61a-4404-8588-60a387d2cccb --- src/wp-admin/includes/class-theme-installer-skin.php | 5 +++-- .../includes/class-wp-ms-themes-list-table.php | 5 +++-- src/wp-admin/includes/file.php | 5 +++-- src/wp-admin/theme-editor.php | 12 +++++++----- src/wp-admin/themes.php | 5 +++-- src/wp-includes/class-wp-customize-manager.php | 5 +++-- src/wp-includes/class-wp-theme.php | 9 ++++++--- src/wp-includes/template-loader.php | 7 ++++--- 8 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/wp-admin/includes/class-theme-installer-skin.php b/src/wp-admin/includes/class-theme-installer-skin.php index bd320ccb401c2..33c13d6c7de67 100644 --- a/src/wp-admin/includes/class-theme-installer-skin.php +++ b/src/wp-admin/includes/class-theme-installer-skin.php @@ -248,8 +248,9 @@ private function do_overwrite() { echo '

' . esc_html__( 'This theme is already installed.' ) . '

'; // Check errors for active theme. - if ( is_wp_error( $current_theme_data->errors() ) ) { - $this->feedback( 'current_theme_has_errors', $current_theme_data->errors()->get_error_message() ); + $current_theme_errors = $current_theme_data->errors(); + if ( is_wp_error( $current_theme_errors ) ) { + $this->feedback( 'current_theme_has_errors', $current_theme_errors->get_error_message() ); } $this->is_downgrading = version_compare( $current_theme_data['Version'], $new_theme_data['Version'], '>' ); diff --git a/src/wp-admin/includes/class-wp-ms-themes-list-table.php b/src/wp-admin/includes/class-wp-ms-themes-list-table.php index be0039b5ea965..3eb1355b1f7e6 100644 --- a/src/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -731,10 +731,11 @@ public function column_name( $theme ) { public function column_description( $theme ) { global $status, $totals; - if ( $theme->errors() ) { + $theme_errors = $theme->errors(); + if ( $theme_errors ) { $pre = 'broken' === $status ? '' . __( 'Broken Theme:' ) . ' ' : ''; wp_admin_notice( - $pre . $theme->errors()->get_error_message(), + $pre . $theme_errors->get_error_message(), array( 'type' => 'error', 'additional_classes' => array( 'inline' ), diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 79a08bb2b9cba..832be7aba9445 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -447,10 +447,11 @@ function wp_edit_theme_plugin_file( $args ) { return new WP_Error( 'nonce_failure' ); } - if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) { + $theme_errors = $theme->errors(); + if ( $theme_errors && 'theme_no_stylesheet' === $theme_errors->get_error_code() ) { return new WP_Error( 'theme_no_stylesheet', - __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() + __( 'The requested theme does not exist.' ) . ' ' . $theme_errors->get_error_message() ); } diff --git a/src/wp-admin/theme-editor.php b/src/wp-admin/theme-editor.php index 68d6f9a7e966a..54def0c7e85f2 100644 --- a/src/wp-admin/theme-editor.php +++ b/src/wp-admin/theme-editor.php @@ -73,8 +73,9 @@ wp_die( __( 'The requested theme does not exist.' ) ); } -if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) { - wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() ); +$theme_errors = $theme->errors(); +if ( $theme_errors && 'theme_no_stylesheet' === $theme_errors->get_error_code() ) { + wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme_errors->get_error_message() ); } $allowed_files = array(); @@ -293,7 +294,8 @@