Forum Replies Created

Viewing 1 replies (of 1 total)
  • I’ve just create a new WP with different roles:
    Editors – 1 user called editor01
    Sales – 1 user called sale01

    (in future multiple users for thes roles)…

    I must redirect after login page to specific homepage conditionned by role… I write the following code:

    ————-SOURCE CODE HERE—————
    add_action(‘wp_logout’,’auto_redirect_after_logout’);
    function auto_redirect_after_logout(){
    wp_redirect( home_url() );
    exit();
    }

    add_action(‘wp_login’,’login_redirect’);
    function login_redirect() {
    $user = wp_get_current_user();
    $roles = $user->roles;
    if (isset($roles) && is_array($roles)) {
    if (in_array(‘administrator’, $roles)) {
    // redirect them to the default place
    wp_redirect(home_url() . ‘/wp-admin/’);
    exit();
    }
    if (in_array(‘Sales’, $roles, true)) {
    wp_redirect(home_url() . ‘/wepos/#/’);
    exit();
    }
    // ….. for other roles if then ….
    } else {
    wp_redirect(home_url() . ‘/wepos/#/’);
    exit();
    }
    }
    ————-SOURCE CODE END—————
    Redirect doesnt work and return to original page of user informations

Viewing 1 replies (of 1 total)