将wordpress用户更改为管理员

ama*_*ulf 6 wordpress

我正在尝试设置生产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);
Run Code Online (Sandbox Code Playgroud)

然后我清除了我的浏览器cookie并再次登录,但是当我尝试导航时,http://localhost/wp-admin我仍然"你没有足够的权限来访问这个页面." 我甚至删除了我的APC缓存文件并重新加载Nginx和PHP-FPM,这也没有改变任何东西.有没有人知道还有什么要尝试?

dou*_*arp 9

设置capabilitiesuser_level您的meta_key值需要匹配您的数据库前缀.默认情况下,这是wp_(导致wp_capabilitieswp_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);
Run Code Online (Sandbox Code Playgroud)


jam*_*rke 5

以下是如何使用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';
Run Code Online (Sandbox Code Playgroud)