• Resolved David Junior

    (@pondwar)


    Hi, thanks for producing a great plugin, but I have a problem and I would like to know if anyone can help me.

    I created several roles to separate each user by a certain role and thus to release the access of certain pages only to the user that is of that role.

    I have done is ready all the part of setting the roles and blocking or releasing page that each role belongs to, but now I have a problem:

    I need a function so that as soon as the user registers he can click somewhere he switches his function, so he stops being an editor and becomes a salesman only with the click of a button, or marking any option of your registration.

    Ex. You register in the portal and at first it is a simple user, but you want to be a salesperson and to avoid having to send contact to the site developer, the user clicks a button and calls the certain function so that he can become a seller.

    I am not sure how I create this interaction with the plugin of yours.

    Someone can help me.

    Thank you for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Hi,

    You don’t need any interaction with URE here. URE does not include conditional assignment of user role according to a user selection on user registration point or later.

    Custom form elements and custom code to process user selection is required.

    Thread Starter David Junior

    (@pondwar)

    Hi Everyone

    O Solved my job with this code:

    <?php
    define('WP_USE_THEMES', false);
     require('wp-load.php'); //need this do work
    add_action( 'profile_update', 'my_profile_update', 10, 2 );
    
    if (is_user_logged_in()){ //verify if user is logged
    
    $user = my_profile_update(wp_get_current_user()->ID); //get user ID
    
    echo array_shift($user->roles);
    }else{ //If user is not logged
    	Header( "location: https://mysite.com");
    }	
    function my_profile_update( $user_id ) { //if user is logged
    	$u = new WP_User( $user_id ); //pick a past user Role	
    	$u->set_role('role-created'); //Set a new user-role for user->ID
    	Header( "location: https://mysite.com");//redirect to page
    	return $u;	
    }
    ?>

    I create a new page user-role.php and call this page on a button and every user who call the function change de user-role.

    This work fine to me and and must be help for more programers.

    Tanks!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Changing a user’s role with a button’ is closed to new replies.