mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -122,13 +122,13 @@ class WP_User {
|
||||
*/
|
||||
public function __construct( $id = 0, $name = '', $site_id = '' ) {
|
||||
if ( ! isset( self::$back_compat_keys ) ) {
|
||||
$prefix = $GLOBALS['wpdb']->prefix;
|
||||
$prefix = $GLOBALS['wpdb']->prefix;
|
||||
self::$back_compat_keys = array(
|
||||
'user_firstname' => 'first_name',
|
||||
'user_lastname' => 'last_name',
|
||||
'user_description' => 'description',
|
||||
'user_level' => $prefix . 'user_level',
|
||||
$prefix . 'usersettings' => $prefix . 'user-settings',
|
||||
'user_firstname' => 'first_name',
|
||||
'user_lastname' => 'last_name',
|
||||
'user_description' => 'description',
|
||||
'user_level' => $prefix . 'user_level',
|
||||
$prefix . 'usersettings' => $prefix . 'user-settings',
|
||||
$prefix . 'usersettingstime' => $prefix . 'user-settings-time',
|
||||
);
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class WP_User {
|
||||
|
||||
if ( ! empty( $id ) && ! is_numeric( $id ) ) {
|
||||
$name = $id;
|
||||
$id = 0;
|
||||
$id = 0;
|
||||
}
|
||||
|
||||
if ( $id ) {
|
||||
@@ -169,7 +169,7 @@ class WP_User {
|
||||
*/
|
||||
public function init( $data, $site_id = '' ) {
|
||||
$this->data = $data;
|
||||
$this->ID = (int) $data->ID;
|
||||
$this->ID = (int) $data->ID;
|
||||
|
||||
$this->for_site( $site_id );
|
||||
}
|
||||
@@ -199,34 +199,37 @@ class WP_User {
|
||||
if ( 'id' == $field ) {
|
||||
// Make sure the value is numeric to avoid casting objects, for example,
|
||||
// to int 1.
|
||||
if ( ! is_numeric( $value ) )
|
||||
if ( ! is_numeric( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
$value = intval( $value );
|
||||
if ( $value < 1 )
|
||||
if ( $value < 1 ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$value = trim( $value );
|
||||
}
|
||||
|
||||
if ( !$value )
|
||||
if ( ! $value ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( $field ) {
|
||||
case 'id':
|
||||
$user_id = $value;
|
||||
$user_id = $value;
|
||||
$db_field = 'ID';
|
||||
break;
|
||||
case 'slug':
|
||||
$user_id = wp_cache_get($value, 'userslugs');
|
||||
$user_id = wp_cache_get( $value, 'userslugs' );
|
||||
$db_field = 'user_nicename';
|
||||
break;
|
||||
case 'email':
|
||||
$user_id = wp_cache_get($value, 'useremail');
|
||||
$user_id = wp_cache_get( $value, 'useremail' );
|
||||
$db_field = 'user_email';
|
||||
break;
|
||||
case 'login':
|
||||
$value = sanitize_user( $value );
|
||||
$user_id = wp_cache_get($value, 'userlogins');
|
||||
$value = sanitize_user( $value );
|
||||
$user_id = wp_cache_get( $value, 'userlogins' );
|
||||
$db_field = 'user_login';
|
||||
break;
|
||||
default:
|
||||
@@ -234,14 +237,18 @@ class WP_User {
|
||||
}
|
||||
|
||||
if ( false !== $user_id ) {
|
||||
if ( $user = wp_cache_get( $user_id, 'users' ) )
|
||||
if ( $user = wp_cache_get( $user_id, 'users' ) ) {
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$user = $wpdb->get_row( $wpdb->prepare(
|
||||
"SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
|
||||
) ) )
|
||||
if ( ! $user = $wpdb->get_row(
|
||||
$wpdb->prepare(
|
||||
"SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
|
||||
)
|
||||
) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
update_user_caches( $user );
|
||||
|
||||
@@ -258,7 +265,8 @@ class WP_User {
|
||||
*/
|
||||
public function __isset( $key ) {
|
||||
if ( 'id' == $key ) {
|
||||
_deprecated_argument( 'WP_User->id', '2.1.0',
|
||||
_deprecated_argument(
|
||||
'WP_User->id', '2.1.0',
|
||||
sprintf(
|
||||
/* translators: %s: WP_User->ID */
|
||||
__( 'Use %s instead.' ),
|
||||
@@ -268,11 +276,13 @@ class WP_User {
|
||||
$key = 'ID';
|
||||
}
|
||||
|
||||
if ( isset( $this->data->$key ) )
|
||||
if ( isset( $this->data->$key ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( isset( self::$back_compat_keys[ $key ] ) )
|
||||
if ( isset( self::$back_compat_keys[ $key ] ) ) {
|
||||
$key = self::$back_compat_keys[ $key ];
|
||||
}
|
||||
|
||||
return metadata_exists( 'user', $this->ID, $key );
|
||||
}
|
||||
@@ -287,7 +297,8 @@ class WP_User {
|
||||
*/
|
||||
public function __get( $key ) {
|
||||
if ( 'id' == $key ) {
|
||||
_deprecated_argument( 'WP_User->id', '2.1.0',
|
||||
_deprecated_argument(
|
||||
'WP_User->id', '2.1.0',
|
||||
sprintf(
|
||||
/* translators: %s: WP_User->ID */
|
||||
__( 'Use %s instead.' ),
|
||||
@@ -300,8 +311,9 @@ class WP_User {
|
||||
if ( isset( $this->data->$key ) ) {
|
||||
$value = $this->data->$key;
|
||||
} else {
|
||||
if ( isset( self::$back_compat_keys[ $key ] ) )
|
||||
if ( isset( self::$back_compat_keys[ $key ] ) ) {
|
||||
$key = self::$back_compat_keys[ $key ];
|
||||
}
|
||||
$value = get_user_meta( $this->ID, $key, true );
|
||||
}
|
||||
|
||||
@@ -325,7 +337,8 @@ class WP_User {
|
||||
*/
|
||||
public function __set( $key, $value ) {
|
||||
if ( 'id' == $key ) {
|
||||
_deprecated_argument( 'WP_User->id', '2.1.0',
|
||||
_deprecated_argument(
|
||||
'WP_User->id', '2.1.0',
|
||||
sprintf(
|
||||
/* translators: %s: WP_User->ID */
|
||||
__( 'Use %s instead.' ),
|
||||
@@ -348,7 +361,8 @@ class WP_User {
|
||||
*/
|
||||
public function __unset( $key ) {
|
||||
if ( 'id' == $key ) {
|
||||
_deprecated_argument( 'WP_User->id', '2.1.0',
|
||||
_deprecated_argument(
|
||||
'WP_User->id', '2.1.0',
|
||||
sprintf(
|
||||
/* translators: %s: WP_User->ID */
|
||||
__( 'Use %s instead.' ),
|
||||
@@ -486,13 +500,14 @@ class WP_User {
|
||||
$wp_roles = wp_roles();
|
||||
|
||||
//Filter out caps that are not role names and assign to $this->roles
|
||||
if ( is_array( $this->caps ) )
|
||||
if ( is_array( $this->caps ) ) {
|
||||
$this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) );
|
||||
}
|
||||
|
||||
//Build $allcaps from role caps, overlay user's $caps
|
||||
$this->allcaps = array();
|
||||
foreach ( (array) $this->roles as $role ) {
|
||||
$the_role = $wp_roles->get_role( $role );
|
||||
$the_role = $wp_roles->get_role( $role );
|
||||
$this->allcaps = array_merge( (array) $this->allcaps, (array) $the_role->capabilities );
|
||||
}
|
||||
$this->allcaps = array_merge( (array) $this->allcaps, (array) $this->caps );
|
||||
@@ -518,7 +533,7 @@ class WP_User {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->caps[$role] = true;
|
||||
$this->caps[ $role ] = true;
|
||||
update_user_meta( $this->ID, $this->cap_key, $this->caps );
|
||||
$this->get_role_caps();
|
||||
$this->update_user_level_from_caps();
|
||||
@@ -542,9 +557,10 @@ class WP_User {
|
||||
* @param string $role Role name.
|
||||
*/
|
||||
public function remove_role( $role ) {
|
||||
if ( !in_array($role, $this->roles) )
|
||||
if ( ! in_array( $role, $this->roles ) ) {
|
||||
return;
|
||||
unset( $this->caps[$role] );
|
||||
}
|
||||
unset( $this->caps[ $role ] );
|
||||
update_user_meta( $this->ID, $this->cap_key, $this->caps );
|
||||
$this->get_role_caps();
|
||||
$this->update_user_level_from_caps();
|
||||
@@ -572,16 +588,18 @@ class WP_User {
|
||||
* @param string $role Role name.
|
||||
*/
|
||||
public function set_role( $role ) {
|
||||
if ( 1 == count( $this->roles ) && $role == current( $this->roles ) )
|
||||
if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( (array) $this->roles as $oldrole )
|
||||
unset( $this->caps[$oldrole] );
|
||||
foreach ( (array) $this->roles as $oldrole ) {
|
||||
unset( $this->caps[ $oldrole ] );
|
||||
}
|
||||
|
||||
$old_roles = $this->roles;
|
||||
if ( !empty( $role ) ) {
|
||||
$this->caps[$role] = true;
|
||||
$this->roles = array( $role => true );
|
||||
if ( ! empty( $role ) ) {
|
||||
$this->caps[ $role ] = true;
|
||||
$this->roles = array( $role => true );
|
||||
} else {
|
||||
$this->roles = false;
|
||||
}
|
||||
@@ -655,7 +673,7 @@ class WP_User {
|
||||
* @param bool $grant Whether to grant capability to user.
|
||||
*/
|
||||
public function add_cap( $cap, $grant = true ) {
|
||||
$this->caps[$cap] = $grant;
|
||||
$this->caps[ $cap ] = $grant;
|
||||
update_user_meta( $this->ID, $this->cap_key, $this->caps );
|
||||
$this->get_role_caps();
|
||||
$this->update_user_level_from_caps();
|
||||
@@ -723,8 +741,9 @@ class WP_User {
|
||||
|
||||
// Multisite super admin has all caps by definition, Unless specifically denied.
|
||||
if ( is_multisite() && is_super_admin( $this->ID ) ) {
|
||||
if ( in_array('do_not_allow', $caps) )
|
||||
if ( in_array( 'do_not_allow', $caps ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -749,8 +768,9 @@ class WP_User {
|
||||
|
||||
// Must have ALL requested caps.
|
||||
foreach ( (array) $caps as $cap ) {
|
||||
if ( empty( $capabilities[ $cap ] ) )
|
||||
if ( empty( $capabilities[ $cap ] ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user