Created
July 29, 2016 14:32
-
-
Save andrewlimaza/773c7f5bd82c457fb2d386c96058e7d5 to your computer and use it in GitHub Desktop.
redirect users away from home page if they are already logged in to a different page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Copy lines 5 onwards into your PMPro custom plugin -> http://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
function pmproc_redirect_member(){ | |
if( is_user_logged_in() && function_exists('pmpro_hasMembershipLevel') && pmpro_hasMembershipLevel() ){ //check if user is logged in, pmpro is installed and user has an active level. | |
global $current_user; | |
$current_user->membership_level = pmpro_getMembershipLevelForUser($current_user->ID); //get current users level ID | |
//check users level and home page of the website - redirect to different page (you may use 'is_page() for non home pages') | |
if( $current_user->membership_level->ID == '1' && is_home() ) { | |
wp_redirect( '/hello-world' ); //redirect to hello-world default post | |
} | |
} | |
} | |
add_action('template_redirect', 'pmproc_redirect_member', 15); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment