#20460 closed defect (bug) (fixed)
Notice with clean_user_cache when deleting a user
Reported by: | blueyed | Owned by: | duck_ |
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | minor | Version: | 3.4 |
Component: | Multisite | Keywords: | has-patch |
Focuses: | Cc: |
Description
I just got the following error when deleting a user in a network setup site / multisite setup:
Notice: Trying to get property of non-object in /srv/wordpress/wp-includes/user.php on line 1152 Call Stack: 0.0000 342776 1. {main}() /srv/wordpress/wp-admin/network/users.php:0 0.1137 3522036 2. wpmu_delete_user() /srv/wordpress/wp-admin/network/users.php:201 0.1278 3528060 3. clean_user_cache() /srv/wordpress/wp-admin/includes/ms.php:165
This can happen when $user = WP_User::get_data_by( 'id', $id );
is "false".
The patch appears to be trivial, so I am attaching it inline:
diff --git i/wp-includes/user.php w/wp-includes/user.php index 463f311..8d99dd5 100644 --- i/wp-includes/user.php +++ w/wp-includes/user.php @@ -1149,9 +1149,11 @@ function clean_user_cache($id) { $user = WP_User::get_data_by( 'id', $id ); wp_cache_delete($id, 'users'); - wp_cache_delete($user->user_login, 'userlogins'); - wp_cache_delete($user->user_email, 'useremail'); - wp_cache_delete($user->user_nicename, 'userslugs'); + if ( is_object($user) ) { + wp_cache_delete($user->user_login, 'userlogins'); + wp_cache_delete($user->user_email, 'useremail'); + wp_cache_delete($user->user_nicename, 'userslugs'); + } } /**
Apart from that I suggest the following documentation fix:
diff --git i/wp-includes/capabilities.php w/wp-includes/capabilities.php index 19568e5..481edd8 100644 --- i/wp-includes/capabilities.php +++ w/wp-includes/capabilities.php @@ -482,7 +482,7 @@ class WP_User { * * @param string $field The field to query against: 'id', 'slug', 'email' or 'login' * @param string|int $value The field value - * @return object Raw user object + * @return object|boolean Raw user object, false on error. */ static function get_data_by( $field, $value ) { global $wpdb;
I am using WP trunk (via the Github mirror).
Attachments (2)
Change History (10)
#3
@
13 years ago
- Owner set to duck_
- Resolution set to fixed
- Status changed from new to closed
In [20522]:
#6
follow-up:
↓ 7
@
13 years ago
This code should take into account that WP_User->get_data_by
might return false.
This would lead to a fatal error then with $user->exists()
(where $user
is a non-object).
#7
in reply to:
↑ 6
@
13 years ago
Replying to blueyed:
This code should take into account that
WP_User->get_data_by
might return false.
This would lead to a fatal error then with$user->exists()
(where$user
is a non-object).
The WP_User::get_data_by() method is not used directly anymore. It was replaced with "new WP_User()" which will always return a WP_User object.
The problem with the patch is that it could leave old data in the cache.
Previously noticed by jjj on #19500 with a patch provided. Though I'm tempted to leave this ticket open as it is a separate issue really.
Similar issue with post caches at the end of #19690.