Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress仅通过访问页面将订阅者升级为贡献者_Php_Wordpress_User Roles - Fatal编程技术网

Php Wordpress仅通过访问页面将订阅者升级为贡献者

Php Wordpress仅通过访问页面将订阅者升级为贡献者,php,wordpress,user-roles,Php,Wordpress,User Roles,当我的Wordpress用户访问某个链接时,我试图提升他们,但我不知道该怎么做 我找到了这个函数,并将它放在我希望进行更改的页面上。我认为这可能会奏效,但不会: function update_roles() { global $wpdb; $author = wp_get_current_user(); $author->remove_role( 'subscriber' ); $author->add_role( 'contributor' ); } 有没

当我的Wordpress用户访问某个链接时,我试图提升他们,但我不知道该怎么做

我找到了这个函数,并将它放在我希望进行更改的页面上。我认为这可能会奏效,但不会:

function update_roles() {
   global $wpdb;
   $author = wp_get_current_user();

  $author->remove_role( 'subscriber' );
  $author->add_role( 'contributor' );
}
有没有关于如何做到这一点的线索

wp_update_user( [ 'ID' =>get_current_user_id(), 'role' => 'contributor' ] ); 

您可以在页面模板中使用此代码来更改用户角色。

如何调用此函数?@Phillhealy我刚刚将其放入了一个快捷代码中,并显示在我的页面上。我需要一些onload参数才能工作吗?我对PHPIn不太了解,所以我需要查看所有相关代码。你能设置一个gist或codepen并将其全部放在那里,然后我和其他人就可以确切地看到你在做什么。@Phillhealy我会的,但基本上就是这样:)我从这里取下它并去掉posts条件,因为我真的不需要条件,因为我唯一的条件是它们位于正确的位置:那么如何调用函数?你的短代码是什么?您如何使用短代码&在哪里使用短代码?我们需要看看代码。