Commit 7c82fff54b for wordpress.org
commit 7c82fff54b258e0e062befbb597cdd69ced26b46
Author: westonruter <westonruter@git.wordpress.org>
Date: Tue Oct 13 18:06:57 2026 +0000
Code Quality: Mark `current_user_can()` and `chmod()` as "impure".
PHPStan infers `current_user_can()` and `WP_Filesystem_Base::chmod()` as pure, so it remembers what each returned and reuses that value at a later call in the same scope, reporting the second check as always true or always false. Yet a capability check can legitimately answer differently the second time, since it reads the current user and applies the `user_has_cap` filter, so a plugin hooked in between (for example during the `admin-header.php` load in `wp-admin/link-manager.php`) can change the result. Similarly, `chmod()` changes the permissions that a following `is_writable()` reports. The annotation goes on the call that invalidates the remembered value rather than on read-only accessors like `is_writable()`, and on `current_user_can()` itself since annotating `WP_User::has_cap()` cleared nothing. This resolves 13 baselined errors across five identifiers.
Developed in https://github.com/WordPress/wordpress-develop/pull/13074.
Follow-up to r63023, r63301, r63357, r64335.
Props tstokes8040.
See #65817.
Built from https://develop.svn.wordpress.org/trunk@64336
git-svn-id: http://core.svn.wordpress.org/trunk@63486 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/includes/class-wp-filesystem-base.php b/wp-admin/includes/class-wp-filesystem-base.php
index 4972c8421c..75ab85cd63 100644
--- a/wp-admin/includes/class-wp-filesystem-base.php
+++ b/wp-admin/includes/class-wp-filesystem-base.php
@@ -606,6 +606,8 @@ class WP_Filesystem_Base {
* @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;
diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php
index 6f8b57d50b..a1193dc336 100644
--- a/wp-includes/capabilities.php
+++ b/wp-includes/capabilities.php
@@ -909,6 +909,8 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
* @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
* passed, whether the current user has the given meta capability for the given object.
+ *
+ * @phpstan-impure
*/
function current_user_can( $capability, ...$args ) {
return user_can( wp_get_current_user(), $capability, ...$args );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 6252d87a85..4943ec7a33 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-64335';
+$wp_version = '7.2-alpha-64336';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.