[wp-trac] [WordPress Trac] #28468: wp_capabilities (wp_usermeta table) actually serialized array of user_role (was: wp_capabalities (wp_usermeta table) actually serialized array of user_role)
WordPress Trac
noreply at wordpress.org
Fri Jul 18 19:09:41 UTC 2014
#28468: wp_capabilities (wp_usermeta table) actually serialized array of user_role
--------------------------+----------------------
Reporter: Nukeface | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Users | Version: 3.9.1
Severity: normal | Resolution: invalid
Keywords: | Focuses:
--------------------------+----------------------
Changes (by SergeyBiryukov):
* milestone: Awaiting Review =>
Old description:
> Setup: WP3.9.1 Dutch Multi-site
> Plugin (activated but un-used): Advanced Custom Fields - Problem persists
> without plugin.
>
> The user_role assigned to users of a blog gets stored in a weird format
> with an incorrectly named meta_key.
>
> When searching for users from a certain user_role a little trickery has
> to be used to be able to find the correct users.
>
> table wp_usermeta
> [meta_key] => [wp_capabilities]
> [meta_value] => [a:1:{s:13:"administrator";b:1;}]
>
> Not only is this a weird way to store this value, with an incorrect
> meta_key assigned, in this case it's also an incorrect value.
>
> This is the value assigned to a super-admin. So why is it labelled
> "administrator" instead of "super-admin"? And why is it stored with
> "wp_capabilities" and not something along the lines of "wp_user_role"?
>
> Also, why is the value stored like this?
>
> serialize(
> array(
> [administrator]=>true
> )
> )
>
> Why not plain-text, like pretty much any value in the wp_usermeta table?
>
> To get the correct users to be returned a query now has to be submitted
> with a meta_query like so:
>
> $roles[ 'relation' ] = 'OR' ;
> foreach( $user_roles as $role ){
> $roles[] = array(
> 'key' => 'wp_capabilities',
> 'value' => serialize(array($role=>true)), /* This value gets
> stored as: serialize(array(1){[$key]=>bool(true)) when it's created */
> 'compare' => '='
> );
> }
>
> Also, the record underneath (with every user apart from 'super-admin'
> roles) shows [meta_key]=>0, with super-admins: [meta_key]=>10. The usage
> of wp_user_level has been deprecated since WP3.0, so why is that still
> being used? (source: http://codex.wordpress.org/User_Levels).
>
> When using custom user_roles with custom capabilities this is very much
> so annoying to work through. Especially since there appears to be no
> reliable way to get the users of a specific user_role.
>
> Paired with the WP_User_Query class to get the data in mixed formats (of
> Object, StdClass and Array) and which doesn't properly get the meta-data
> promised in the codex when using 'all_with_meta' in the 'fields' key for
> the query, this gets really frustrating (source:
> http://codex.wordpress.org/Class_Reference/WP_User_Query - Return Fields
> Parameter).
New description:
Setup: WP3.9.1 Dutch Multi-site
Plugin (activated but un-used): Advanced Custom Fields - Problem persists
without plugin.
The user_role assigned to users of a blog gets stored in a weird format
with an incorrectly named meta_key.
When searching for users from a certain user_role a little trickery has to
be used to be able to find the correct users.
{{{
table wp_usermeta
[meta_key] => [wp_capabilities]
[meta_value] => [a:1:{s:13:"administrator";b:1;}]
}}}
Not only is this a weird way to store this value, with an incorrect
meta_key assigned, in this case it's also an incorrect value.
This is the value assigned to a super-admin. So why is it labelled
"administrator" instead of "super-admin"? And why is it stored with
"wp_capabilities" and not something along the lines of "wp_user_role"?
Also, why is the value stored like this?
{{{
serialize(
array(
[administrator] => true
)
)
}}}
Why not plain-text, like pretty much any value in the wp_usermeta table?
To get the correct users to be returned a query now has to be submitted
with a meta_query like so:
{{{
$roles[ 'relation' ] = 'OR' ;
foreach( $user_roles as $role ){
$roles[] = array(
'key' => 'wp_capabilities',
'value' => serialize(array($role=>true)), /* This value gets
stored as: serialize(array(1){[$key]=>bool(true)) when it's created */
'compare' => '='
);
}
}}}
Also, the record underneath (with every user apart from 'super-admin'
roles) shows `[meta_key] => 0`, with super-admins: `[meta_key] => 10`. The
usage of wp_user_level has been deprecated since WP3.0, so why is that
still being used? (source: http://codex.wordpress.org/User_Levels).
When using custom user_roles with custom capabilities this is very much so
annoying to work through. Especially since there appears to be no reliable
way to get the users of a specific user_role.
Paired with the WP_User_Query class to get the data in mixed formats (of
Object, StdClass and Array) and which doesn't properly get the meta-data
promised in the codex when using 'all_with_meta' in the 'fields' key for
the query, this gets really frustrating (source:
http://codex.wordpress.org/Class_Reference/WP_User_Query - Return Fields
Parameter).
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28468#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list