• montidesign

    (@montidesign)


    Hello,

    I’m trying to set up a redirect after a user registration and auto login (using Gravity Forms). The external redirect shunts the new user over to wp-admin, but I need it to go to a specific page.

    I’ve tried customizing the wplogin_redirect_control.php file in the plugin folder in the following manner:

    <?php
        // This assumes that this files sits in "wp-content/plugins/peters-login-redirect/wplogin_redirect_control.php" and that you haven't moved your wp-content folder
        if( file_exists( '../../../wp-load.php' ) )
        {
            include '../../../wp-load.php';
        }
        else
        {
            print 'Plugin paths not configured correctly.';
        }
    
        $current_user = wp_get_current_user();
    
        function get_current_user_role() {
    	global $wp_roles;
    	$roles = $current_user->roles;
    	$role = array_shift($roles);
    	return isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false;
        }
    
        $current_user_role = get_current_user_role();
    
        if ( $current_user_role == 'WordPress Training User' ) {
        	$redirect_to = site_url( '/wordpress-tutorial-videos/' );
        } else {
        	$redirect_to = admin_url();
        }
    
        $redirect_url = redirect_wrapper( $redirect_to, '', $current_user );
        wp_redirect( $redirect_url );
        die();
    ?>

    I’ve used several different methods of detecting the user role, but the result is always the same. The redirect goes to WP admin.

    Is there something I am missing?

    https://wordpress.org/plugins/peters-login-redirect/

  • The topic ‘External Redirect and User Role’ is closed to new replies.