Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4a44a52
Build/Test Tools: Stop PHPStan remembering possibly impure return val…
westonruter Nov 14, 2026
76e0747
Code Quality: Define variables that a repeated conditional guards.
westonruter Nov 3, 2026
6070ae2
Code Quality: Read `WP_Theme::errors()` once before using it.
westonruter Nov 3, 2026
0bc667c
Code Quality: Mark `WP_Theme::parent()` as pure.
westonruter Nov 3, 2026
7010077
Code Quality: Read `wp_get_referer()` once before using it.
westonruter Nov 3, 2026
b05a621
Code Quality: Check for missed cron events only once in Site Health.
westonruter Nov 3, 2026
de1d9df
Code Quality: Pass the checked callback to Site Health's `perform_tes…
westonruter Nov 3, 2026
d61ea2b
Twenty Twenty-One: Read attachment captions once before printing them.
westonruter Nov 3, 2026
bbc2587
Twenty Twenty-One: Read the attachment's parent ID once.
westonruter Nov 3, 2026
36de872
Code Quality: Read theme requirement headers once.
westonruter Nov 3, 2026
171a69f
Twenty Twenty: Read the comment edit link once.
westonruter Nov 3, 2026
a495c44
Code Quality: Reuse the changeset post ID once it is checked.
westonruter Nov 3, 2026
e6f9e20
Code Quality: Read the created posts setting once in nav menus.
westonruter Nov 3, 2026
edf2123
Connectors: Read an AI provider's logo path once.
westonruter Nov 3, 2026
a13c864
Code Quality: Unslash the posted sidebars before iterating them.
westonruter Nov 3, 2026
f9dacef
Code Quality: Read `WP_Error::get_error_data()` once before using it.
westonruter Nov 3, 2026
6cf14fc
Code Quality: Read the post type query var once in 404 redirect guesses.
westonruter Nov 3, 2026
08d11b9
REST API: Read the response data once when converting it to an error.
westonruter Nov 3, 2026
8db1ba2
Code Quality: Read the illegal site names option once in signup.
westonruter Nov 3, 2026
3a1f6c1
Code Quality: Read `is_multisite()` once for the admin menu's update …
westonruter Nov 3, 2026
9c05ec4
Code Quality: Read the core update error data once after a failure.
westonruter Nov 3, 2026
c90df34
Code Quality: Remove `@phpstan-impure` tags made redundant by forgett…
westonruter Nov 14, 2026
42dd87e
Code Quality: Mark `WP_Block_Processor::find_html_comment_end()` as p…
westonruter Nov 14, 2026
27562cd
Code Quality: Initialize the auto-update list in the multisite themes…
westonruter Nov 14, 2026
72e0c73
Code Quality: Track a delimiter match in a local variable instead of …
westonruter Nov 15, 2026
86f21b9
Code Quality: Read `WP_Theme::parent()` once where it is checked and …
westonruter Nov 15, 2026
b4a9fc6
Code Quality: Remove the `@phpstan-pure` tag from `WP_Theme::parent()`.
westonruter Nov 15, 2026
136a4df
Merge branch 'trunk' into remember-impure-values
westonruter Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/wp-admin/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,18 @@
comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
}

if ( wp_get_referer() && ! $noredir && ! str_contains( wp_get_referer(), 'comment.php' ) ) {
$redir = wp_get_referer();
} elseif ( wp_get_original_referer() && ! $noredir ) {
$redir = wp_get_original_referer();
} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) {
$redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
$referer = wp_get_referer();
if ( $referer && ! $noredir && ! str_contains( $referer, 'comment.php' ) ) {
$redir = $referer;
} else {
$redir = admin_url( 'edit-comments.php' );
$original_referer = wp_get_original_referer();
if ( $original_referer && ! $noredir ) {
$redir = $original_referer;
} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) {
$redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
} else {
$redir = admin_url( 'edit-comments.php' );
}
}

$redir = remove_query_arg( array( 'spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved' ), $redir );
Expand Down
9 changes: 6 additions & 3 deletions src/wp-admin/edit-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
$doaction = $_REQUEST['action'];
} elseif ( isset( $_REQUEST['ids'] ) ) {
$comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
} elseif ( wp_get_referer() ) {
wp_safe_redirect( wp_get_referer() );
exit;
} else {
$referer = wp_get_referer();
if ( $referer ) {
wp_safe_redirect( $referer );
exit;
}
}

$approved = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2301,9 +2301,10 @@ function wp_ajax_widgets_order() {

// Save widgets order for all sidebars.
if ( is_array( $_POST['sidebars'] ) ) {
$sidebars = array();
$sidebars = array();
$posted_sidebars = wp_unslash( $_POST['sidebars'] );

foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) {
foreach ( $posted_sidebars as $key => $val ) {
$sidebar = array();

if ( ! empty( $val ) ) {
Expand Down
7 changes: 4 additions & 3 deletions src/wp-admin/includes/class-bulk-upgrader-skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public function error( $errors ) {
}

if ( is_wp_error( $errors ) ) {
$messages = array();
$messages = array();
$error_data = $errors->get_error_data();
foreach ( $errors->get_error_messages() as $emessage ) {
if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
$messages[] = $emessage . ' ' . esc_html( strip_tags( $errors->get_error_data() ) );
if ( $error_data && is_string( $error_data ) ) {
$messages[] = $emessage . ' ' . esc_html( strip_tags( $error_data ) );
} else {
$messages[] = $emessage;
}
Expand Down
5 changes: 3 additions & 2 deletions src/wp-admin/includes/class-theme-installer-skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ private function do_overwrite() {
echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This theme is already installed.' ) . '</h2>';

// 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'], '>' );
Expand Down
7 changes: 4 additions & 3 deletions src/wp-admin/includes/class-theme-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ public function check_parent_theme_filter( $install_result, $hook_extra, $child_
// Check to see if we need to install a parent theme.
$theme_info = $this->theme_info();

if ( ! $theme_info->parent() ) {
$parent_theme = $theme_info->parent();
if ( ! $parent_theme ) {
return $install_result;
}

$this->skin->feedback( 'parent_theme_search' );

if ( ! $theme_info->parent()->errors() ) {
$this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) );
if ( ! $parent_theme->errors() ) {
$this->skin->feedback( 'parent_theme_currently_installed', $parent_theme->display( 'Name' ), $parent_theme->display( 'Version' ) );
// We already have the theme, fall through.
return $install_result;
}
Expand Down
9 changes: 5 additions & 4 deletions src/wp-admin/includes/class-wp-automatic-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ protected function after_core_update( $update_result ) {
}

$error_code = $result->get_error_code();
$error_data = $result->get_error_data();

/*
* Any of these WP_Error codes are critical failures, as in they occurred after we started to copy core files.
Expand All @@ -943,10 +944,10 @@ protected function after_core_update( $update_result ) {
$critical = false;
if ( 'disk_full' === $error_code || str_contains( $error_code, '__copy_dir' ) ) {
$critical = true;
} elseif ( 'rollback_was_required' === $error_code && is_wp_error( $result->get_error_data()->rollback ) ) {
} elseif ( 'rollback_was_required' === $error_code && is_wp_error( $error_data->rollback ) ) {
// A rollback is only critical if it failed too.
$critical = true;
$rollback_result = $result->get_error_data()->rollback;
$rollback_result = $error_data->rollback;
} elseif ( str_contains( $error_code, 'do_rollback' ) ) {
$critical = true;
}
Expand All @@ -956,7 +957,7 @@ protected function after_core_update( $update_result ) {
'attempted' => $core_update->current,
'current' => $wp_version,
'error_code' => $error_code,
'error_data' => $result->get_error_data(),
'error_data' => $error_data,
'timestamp' => time(),
'critical' => true,
);
Expand Down Expand Up @@ -1004,7 +1005,7 @@ protected function after_core_update( $update_result ) {
'attempted' => $core_update->current,
'current' => $wp_version,
'error_code' => $error_code,
'error_data' => $result->get_error_data(),
'error_data' => $error_data,
'timestamp' => time(),
'retry' => in_array( $error_code, $transient_failures, true ),
)
Expand Down
2 changes: 0 additions & 2 deletions src/wp-admin/includes/class-wp-filesystem-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,6 @@ public function chgrp( $file, $group, $recursive = false ) {
* @param bool $recursive Optional. If set to true, changes file permissions recursively.
* Default false.
* @return bool True on success, false on failure.
*
* @phpstan-impure
*/
public function chmod( $file, $mode = false, $recursive = false ) {
return false;
Expand Down
11 changes: 7 additions & 4 deletions src/wp-admin/includes/class-wp-ms-themes-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function prepare_items() {
'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
);

$auto_updates = array();
if ( $this->show_autoupdates ) {
$auto_updates = (array) get_site_option( 'auto_update_themes', array() );

Expand Down Expand Up @@ -731,10 +732,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 ? '<strong class="error-message">' . __( 'Broken Theme:' ) . '</strong> ' : '';
wp_admin_notice(
$pre . $theme->errors()->get_error_message(),
$pre . $theme_errors->get_error_message(),
array(
'type' => 'error',
'additional_classes' => array( 'inline' ),
Expand Down Expand Up @@ -779,11 +781,12 @@ public function column_description( $theme ) {
);
}

if ( $theme->parent() ) {
$parent_theme = $theme->parent();
if ( $parent_theme ) {
$theme_meta[] = sprintf(
/* translators: %s: Theme name. */
__( 'Child theme of %s' ),
'<strong>' . $theme->parent()->display( 'Name' ) . '</strong>'
'<strong>' . $parent_theme->display( 'Name' ) . '</strong>'
);
}

Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function prepare_items() {
}
}

$show_network_active = false;
if ( ! $screen->in_admin( 'network' ) ) {
$show = current_user_can( 'manage_network_plugins' );
/**
Expand Down
3 changes: 1 addition & 2 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1815,9 +1815,8 @@ public function inline_edit() {
<?php endif; // $bulk ?>

<?php
$authors_dropdown = '';
if ( post_type_supports( $screen->post_type, 'author' ) ) {
$authors_dropdown = '';

if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) {
$dropdown_name = 'post_author';
$dropdown_class = 'authors';
Expand Down
24 changes: 14 additions & 10 deletions src/wp-admin/includes/class-wp-site-health.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ public function enqueue_scripts() {
$test['test']
);

if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
$health_check_js_variables['site_status']['direct'][] = $this->perform_test( array( $this, $test_function ) );
$test_callback = array( $this, $test_function );
if ( method_exists( $this, $test_function ) && is_callable( $test_callback ) ) {
$health_check_js_variables['site_status']['direct'][] = $this->perform_test( $test_callback );
continue;
}
}
Expand Down Expand Up @@ -621,7 +622,8 @@ public function get_test_theme_version() {
if ( $has_unused_themes && ! is_multisite() ) {

// This is a child theme, so we want to be a bit more explicit in our messages.
if ( $active_theme->parent() ) {
$parent_theme = $active_theme->parent();
if ( $parent_theme ) {
// Recommend removing inactive themes, except a default theme, your current one, and the parent theme.
$result['status'] = 'recommended';

Expand All @@ -643,7 +645,7 @@ public function get_test_theme_version() {
/* translators: 1: The currently active theme. 2: The active theme's parent theme. */
__( 'To enhance your site&#8217;s security, you should consider removing any themes you are not using. You should keep your active theme, %1$s, and %2$s, its parent theme.' ),
$active_theme->name,
$active_theme->parent()->name
$parent_theme->name
)
);
} else {
Expand All @@ -663,7 +665,7 @@ public function get_test_theme_version() {
__( 'To enhance your site&#8217;s security, you should consider removing any themes you are not using. You should keep %1$s, the default WordPress theme, %2$s, your active theme, and %3$s, its parent theme.' ),
$default_theme ? $default_theme->name : WP_DEFAULT_THEME,
$active_theme->name,
$active_theme->parent()->name
$parent_theme->name
)
);
}
Expand Down Expand Up @@ -1679,7 +1681,8 @@ public function get_test_scheduled_events() {

$this->wp_schedule_test_init();

if ( is_wp_error( $this->has_missed_cron() ) ) {
$has_missed_cron = $this->has_missed_cron();
if ( is_wp_error( $has_missed_cron ) ) {
$result['status'] = 'critical';

$result['label'] = __( 'It was not possible to check your scheduled events' );
Expand All @@ -1689,10 +1692,10 @@ public function get_test_scheduled_events() {
sprintf(
/* translators: %s: The error message returned while from the cron scheduler. */
__( 'While trying to test your site&#8217;s scheduled events, the following error was returned: %s' ),
$this->has_missed_cron()->get_error_message()
$has_missed_cron->get_error_message()
)
);
} elseif ( $this->has_missed_cron() ) {
} elseif ( $has_missed_cron ) {
$result['status'] = 'recommended';

$result['label'] = __( 'A scheduled event has failed' );
Expand Down Expand Up @@ -3379,8 +3382,9 @@ public function wp_cron_scheduled_check() {
$test['test']
);

if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
$results[] = $this->perform_test( array( $this, $test_function ) );
$test_callback = array( $this, $test_function );
if ( method_exists( $this, $test_function ) && is_callable( $test_callback ) ) {
$results[] = $this->perform_test( $test_callback );
continue;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/wp-admin/includes/class-wp-upgrader-skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ public function error( $errors ) {
if ( is_string( $errors ) ) {
$this->feedback( $errors );
} elseif ( is_wp_error( $errors ) && $errors->has_errors() ) {
$error_data = $errors->get_error_data();
foreach ( $errors->get_error_messages() as $message ) {
if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
$this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
if ( $error_data && is_string( $error_data ) ) {
$this->feedback( $message . ' ' . esc_html( strip_tags( $error_data ) ) );
} else {
$this->feedback( $message );
}
Expand Down
5 changes: 3 additions & 2 deletions src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/wp-admin/includes/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,9 @@ function wp_reset_vars( $vars ) {
*/
function show_message( $message ) {
if ( is_wp_error( $message ) ) {
if ( $message->get_error_data() && is_string( $message->get_error_data() ) ) {
$message = $message->get_error_message() . ': ' . $message->get_error_data();
$error_data = $message->get_error_data();
if ( $error_data && is_string( $error_data ) ) {
$message = $message->get_error_message() . ': ' . $error_data;
} else {
$message = $message->get_error_message();
}
Expand Down
5 changes: 2 additions & 3 deletions src/wp-admin/includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,8 @@ function wp_prepare_themes_for_js( $themes = null ) {
$slug = $theme->get_stylesheet();
$encoded_slug = urlencode( $slug );

$parent = false;
if ( $theme->parent() ) {
$parent = $theme->parent();
$parent = $theme->parent();
if ( $parent ) {
$parents[ $slug ] = $parent->get_stylesheet();
$parent = $parent->display( 'Name' );
}
Expand Down
Loading
Loading