• Resolved kseniyasqo

    (@kseniyasqo)


    Hello,

    There is a problem with a plugin. When a new user is added by admin, assigned role gets overwritten by the default role set in per-site plugin settings. Eg, if I want another admin from Dashboard, user gets invitation email with role of Admin, but as soon as he activates his account, his role gets overwritten as Subscriber.

    https://www.ads-software.com/plugins/join-my-multisite/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    That makes a certain amount of sense. There’s no way for the plugin to tell who sent the email for registration, so it has to default on the side of caution and protect your site (which … well for obvious reasons I don’t want to change that).

    I’m not sure if I can change that behavior. As far as WP is concerned, all new users should have a safe default role. Maybe I can tweak it to check if a role is defined in the pre-approval page.

    Thread Starter kseniyasqo

    (@kseniyasqo)

    I came up with a quick fix for this unwanted behavior. Basically, default role will get overwritten back to the original role assigned from the Dashboard.

    function assign_original_role($user_id, $password, $meta) {
    	global $wpdb;
    	$user = get_userdata($user_id);
    	$email = $user->user_email;
    	$query = $wpdb->prepare("SELECT meta from <code>wp_signups</code> where <code>user_email</code> = %s", $email);
    	$raw_meta = $wpdb->get_results($query, ARRAY_A);
    	$signup_meta = unserialize($raw_meta[0]['meta']);
    	if (array_key_exists('new_role', $signup_meta)) {
    		$user->set_role($signup_meta['new_role']);
    	}
    }
    add_action('wpmu_activate_user', 'assign_original_role', 99);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘When a user is added from Dashboard, role gets overwritten with default role’ is closed to new replies.