Change user role on plugin activation
-
Hello,
When a user registers, I am first setting their role to Editor, but once my plugin activates, I need to change their role to Administrator.
Below is my current code:
function ap_change_role() { global $wpdb; $blog_id = get_current_blog_id(); $query = $wpdb->prepare(" SELECT 'user_id' FROM '%susermeta' WHERE ( meta_key LIKE 'primary_blog' AND meta_value LIKE %d ) LIMIT 1", $wpdb->base_prefix, $blog_id); $blog_owner_id = $wpdb->get_var( $query ); $user = new WP_User( $blog_owner_id ); // Remove role $user->remove_role( 'editor' ); // Add role $user->add_role( 'administrator' ); } register_activation_hook( __FILE__, 'ap_change_role');
But the site owners role is not changing after activation.
Any help with getting this to work will be much appreciated.
Thanks
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Change user role on plugin activation’ is closed to new replies.