This page explains how to change user level with a SQL query directly in the WordPress database.
What is user level and what it does
Although user levels have been oficially deprecated since WordPress 3.0, they are still supported for back compatibility and may still have a meaning in some WordPress themes or plugins.
Generally, user level is a number from 0 to 10, which decides how much a user can do in WordPress admin.
For instance, level 1 can create draft posts only, level 2 can write and publish posts, level 4 can also manage categories and moderate comments, and level 10 can do everything.
A higher level can always do everything that lower levels do, plus some more. Levels 5 and up can also manage other users. For full specifications, see the official documentation.
For new code, user hierrarchy has been handled by Roles and Capabilities.
How user level is stored in WordPress database
User level is not stored directly in the wp_users
table. Instead, it is one of user meta records, which are stored in wp_usermeta
.
In this table, each meta record has its own row, so there are multiple rows for each user. To find the correct meta value, we need to specify two things in the SQL query WHERE clause:
- user ID number (the column
user_id
) - usermeta key (the column
meta_key
)
SQL to change user level for given user ID
The following SQL query changes user level to 10 for the user with ID = 123:
UPDATE `wp_usermeta`
SET `meta_value` = 10
WHERE `meta_key` = 'wp_user_level'
AND `user_id` = 123;
How the SQL changes with different table prefix
The above example assumes the default WordPress database table prefix wp_
.
If your database uses a different table prefix, you need to change the query in two places: Not only the wp_usermeta
table name, but also the value of the meta_key
column in the WHERE clause (wp_user_level
), because user level (and several other usermeta records) have the table prefix prepended to their meta_key.
For example, if your table prefix is blog_
, the query will look like this:
UPDATE `blog_usermeta`
SET `meta_value` = 10
WHERE `meta_key` = 'blog_user_level'
AND `user_id` = 123;