title: Change user role via URL [WordPress]
body: <p>I'm creating plugin which will register all new users as role = unverified and stop user from login until email verification. I want to send url on their email which will change the current unverified role to author. I know how to send email etc all of that in WordPress but can't figure out how to create url which will change the role. I'm using custom ajax form to login,register and lostpassword because of it i'm unable to use pie register and register-plus-redux plugins.</p>
  
  <p>Current code</p>
  
  <pre><code>function add_roles_on_plugin_activation() {
      add_role( 'custom_role', 'Unverified', array( 'read' =&gt; true, 'level_0' =&gt; true ) );
  }
  register_activation_hook( __FILE__, 'add_roles_on_plugin_activation' ); 
  
  function remove_roles_on_plugin_deactivation() {
      remove_role( 'custom_role' );
  }
  register_deactivation_hook( __FILE__, 'remove_roles_on_plugin_deactivation' ); 
  
  add_filter('pre_option_default_role', function($default_role){
      return 'custom_role'; 
      return $default_role; 
  });
  
  
  function error_email_verify() {
  $user = wp_get_current_user();
  if ( in_array( 'custom_role', (array) $user-&gt;roles ) ) {
  
         $logout_url = wp_login_url().'?mode=emailverify';
         wp_logout();
         wp_redirect( $logout_url );
         exit();
      }     
  }
  add_action('wp_loaded', 'error_email_verify');
  
  function my_login_message() {
  
      if( $_GET['mode'] == 'emailverify' ){
          $message = '&lt;p id="login_error"&gt;&lt;b&gt;Verify your email.&lt;/b&gt;&lt;/p&gt;';
          return $message;
      }
  
  }
  add_filter('login_message', 'my_login_message');
  </code></pre>