将 wordpress 用户更改为管理员
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13094601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing a wordpress user to an admin
提问by amandawulf
I am trying to set up a local copy of a production Wordpress blog. On production, I am a user but not an admin, so I am trying to change myself to an admin locally. I was following the directions on thisblog post to make myself an admin, so I performed the following SQL queries:
我正在尝试设置生产 Wordpress 博客的本地副本。在生产中,我是用户但不是管理员,所以我试图在本地将自己更改为管理员。我按照这篇博文中的说明让自己成为管理员,因此我执行了以下 SQL 查询:
INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'wp_user_level', 10);
Then I cleared my browser cookies and logged in again, but when I tried to navigate to http://localhost/wp-admin
I still got "You do not have sufficient permissions to access this page." I even went so far as to delete my APC cache files and reload Nginx and PHP-FPM, which also didn't change anything. Does anyone know of anything else to try?
然后我清除了浏览器 cookie 并再次登录,但是当我尝试导航到时,http://localhost/wp-admin
我仍然收到“您没有足够的权限访问此页面”。我什至删除了我的 APC 缓存文件并重新加载了 Nginx 和 PHP-FPM,这也没有改变任何东西。有谁知道还有什么可以尝试的吗?
回答by doublesharp
To set the capabilities
and user_level
your meta_key
value needs to match your database prefix. By default this is wp_
(resulting in wp_capabilities
and wp_user_level
) however it would be different in your case as you don't have a prefix. The proper capabilities
value is a:1:{s:13:"administrator";s:1:"1";}
.
要设置capabilities
和user_level
您的meta_key
值需要匹配您的数据库前缀。默认情况下,这是wp_
(导致wp_capabilities
和wp_user_level
),但是在您的情况下会有所不同,因为您没有前缀。正确的capabilities
值为a:1:{s:13:"administrator";s:1:"1";}
。
-- delete any existing values for this user
DELETE FROM usermeta WHERE user_id=376 AND (meta_key LIKE '%capabilities' OR meta_key LIKE '%user_level')
-- insert the capabilities and user_level for user_id 376
INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'user_level', 10);
回答by jambroseclarke
Here is how to change assign a User to the Admin Role in WordPress using MySQL statements:
以下是如何使用 MySQL 语句在 WordPress 中更改将用户分配给管理员角色的方法:
-- Look at the field called "id" in the result set
---
select * from wp_users
where user_login = 'WORDPRESS_USERNAME_GOES_HERE';
-- Substitute the above "id" value in the "user_id" field below.
-- This is an integer value so do not use quotes around it
-- For example if the above "id" is the value 10 then the resulting line would be: where user_id = 10
--
update wp_usermeta
set meta_value = 'a:1:{s:13:"administrator";s:1:"1";}'
where user_id = USER_ID_GOES_HERE
and meta_key = 'wp_capabilities';
-- Lastly execute this statement remembering to substitute the same "id" value
update wp_usermeta
set meta_value = '10'
where user_id = USER_ID_GOES_HERE
and meta_key = 'wp_user_level';
回答by Kamal Joshi
If you have already have your username and password then you just need to update capability and role into database.
如果您已经有了用户名和密码,那么您只需要将能力和角色更新到数据库中。
Go to wp_user table and locate your ID from there i.e. in my case its 2. And then go to wp_usermeta and look for meta_key = wp_capabilities and user_id - 2. Edit that row and change meta_value to
转到 wp_user 表并从那里找到您的 ID,即在我的情况下为 2。然后转到 wp_usermeta 并查找 meta_key = wp_capabilities 和 user_id - 2。编辑该行并将 meta_value 更改为
a:1:{s:13:"administrator";s:1:"1";}.
Again go for meta_key = wp_user_level and user_id = 2. Edit that row and change meta_value to 10. Don't change other rows where user_id is not your own.
再次选择 meta_key = wp_user_level 和 user_id = 2。编辑该行并将 meta_value 更改为 10。不要更改 user_id 不是您自己的其他行。
See my wp_users table.
查看我的 wp_users 表。
See my wp_usermeta table.
查看我的 wp_usermeta 表。
Two queries will be fired something like these:
将触发两个查询,如下所示:
UPDATE `wp_usermeta` SET `meta_value` = '10' WHERE `wp_usermeta`.`umeta_id` =27;
UPDATE `wp_usermeta` SET `meta_value` = 'a:1:{s:13:"administrator";s:1:"1";}' WHERE `wp_usermeta`.`umeta_id` =26;