在绝望中,我也在这个论坛上寻求帮助——如果有人(任何人!)如果你能看看这篇文章,看看他们是否能帮上忙,我将永远感激你
http://wordpress.org/support/topic/wp_update_user-not-updating?replies=11
基本上-我正在通过脚本更新用户的角色和功能,但只有当我进入该用户并点击“保存”时,更改才会生效(即用户可以看到特定的菜单项)
期待您的光临!!
克里斯
UPDATE:
也许这有助于解决问题?
This is the WP_User object I have echoed out on screen when logged in as the newly changed user:
WP_User Object ( [data] => stdClass Object ( [ID] => 130 [user_login] => test [user_pass] => $P$BuHO1ABLCNQ716tktgyes4jqqkfVxG. [user_nicename] => test [user_email] => [email protected] [user_url] => [user_registered] => 2012-07-19 12:07:52 [user_activation_key] => [user_status] => 0 [display_name] => test ) [ID] => 130 [caps] => Array ( [editor] => 1 ) [cap_key] => wp_capabilities [roles] => Array ( [0] => editor ) [allcaps] => Array ( [upload_files] => 1 [unfiltered_html] => 1 [edit_posts] => 1 [edit_published_posts] => 1 [publish_posts] => 1 [edit_pages] => 1 [read] => 1 [level_7] => 1 [level_6] => 1 [level_5] => 1 [level_4] => 1 [level_3] => 1 [level_2] => 1 [level_1] => 1 [level_0] => 1 [edit_published_pages] => 1 [publish_pages] => 1 [manage_options] => 1 [view_menu] => 1 [editor] => 1 ) [filter] => )
This is how the menu item is being created in my plugin file (which should display to the user):
add_menu_page(\'Welcome\', \'Welcome\',\'edit_posts\', \'welcome\', \'welcome_page\', get_bloginfo(\'template_url\').\'/images/icon.png\', 0);
This is the function / page that the menu item returns:
function welcome_page()
{
global $currrent_user;
if(!current_user_can(\'edit_posts\'))
{
print \'<div class="wrap"><h2>Your account has been restricted, most likely due to an unpaid subscription.</div>\';
}
else
{
include \'welcome-page.php\';
}
}
如您所见,用户只需要edit\\u posts功能即可查看菜单项并返回欢迎页面。用户确实有这个功能,但不能做这两件事-除非我在用户编辑页面中单击“另存为管理员”??
Edit 2
一
function welcome_page()
{
global $currrent_user;
if(!current_user_can(\'edit_posts\'))
{
print \'<div class="wrap"><h2>Your account has been restricted, most likely due to an unpaid subscription.</div>\';
}
else
{
include \'welcome-page.php\';
}
}
UPDATE AGAIN!
我刚刚尝试了这一点,然后又一次,数据库被更新了,甚至在管理面板中显示“编辑器”,但是用户仍然看不到相应的菜单项,除非我在他们的个人资料上单击“更新”!$new = new WP_User($current_user->ID);
$new->set_role(\'editor\');
wp_cache_delete( $new->ID, \'users\' );
wp_cache_delete( $new->user_login, \'userlogins\' );
wp_cache_delete( $new->user_email, \'useremail\' );
wp_cache_delete( $new->user_nicename, \'userslugs\' );
do_action(\'profile_update\');
有什么想法吗?