Need help with redirecting specific login

I had one of your colleagues help me redirect my Membership subscribers to a specific page. Now that I am considering the Affiliates plugin also, I don't want my affiliates going to that same page. I have my affiliates doing everything from http://schoolofbookkeeping.com/affiliates. The link there takes them to reg or login and currently still redirects to /enrolled-student-home. I need these and only these folks to end up at /affiliates again. Advice?

Here's my code currently all in functions.php

/*** HIDE DASHBOARD AND REDIRECT LOGIN TO ESH EDG
****************************************************************/
add_action('admin_init', 'no_mo_dashboard');
function no_mo_dashboard() {
if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
wp_redirect( 'http://schoolofbookkeeping.com/enrolled-student-home' ); exit;
}
}

/*** REMOVE REMEMBER ME EDG
****************************************************************/
add_action('login_head', 'remove_remember_me');
function remove_remember_me()
{
echo '<style type="text/css">.forgetmenot { display:none; }</style>';
}

/*** ADMIN BAR ADMIN ONLY EDG
****************************************************************/
// show admin bar only for admins
if (!current_user_can('manage_options')) {
add_filter('show_admin_bar', '__return_false');
}

The first one is the key. I'd need something that says "if you are just a lowly affiliate, then go to /affiliates. Is there even a way to determine that? All other users are membership subscribers or a couple of admins if that helps.

  • Ash

    Hello @schoolofbookkeeping.com

    I hope you are well today.

    Please try the following code:

    add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );
    function custom_login_redirect( $redirect_to, $request, $user ){
    	global $user;
    	$member = new Membership_Model_Member( $user->ID );
    	if( $member->is_member() == '' ){
    		return home_url() . '/affiliates';
    	}
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.