Quantcast
Channel: Topic Tag: plugin | WordPress.org
Viewing all articles
Browse latest Browse all 26892

Evan Herman on "Change User Role by visiting site"

$
0
0

You'll need to write a custom function. This isn't something that is just going to work by installing a plugin or something similar. This seems more along the lines of custom development. But here is some code to get you pointed in the right direction:

global $post;
if( is_user_logged_in() ) { // check if user is logged in
   $current_user = wp_get_current_user(); // store user data
   $roles = $current_user->roles; // store user role
   if ( in_array( 'editor' , $roles ) ) { // check if user is an editor
     // user is an editor
     wp_update_user( array( 'ID' => $current_user->ID, 'role' => 'New role' ) ); // update user role
   }
}

That should help boost you in the right direction.


Viewing all articles
Browse latest Browse all 26892

Trending Articles