Forked from andrewlimaza/my-template-redirect-example.php
Last active
January 22, 2020 16:36
-
-
Save femiyb/8d7b635eaa949f1ce1a2f24d98bf5f1f to your computer and use it in GitHub Desktop.
Redirect non-members to homepage but allow access to PMPro checkout pages.
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 | |
| /** | |
| * Redirect non-members (including logged-in non-members) away from restricted pages and to home page. | |
| * This allows non-members to access Paid Memberships Pro checkout/levels pages as well as the default WordPress login page. | |
| * | |
| * Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_redirect_non_members_example() { | |
| // Check if a non-member is trying to access any other page besides the above or home page. | |
| if ( is_page( 'events' ) && ! pmpro_hasMembershipLevel() ) { | |
| wp_redirect( home_url('login') ); //redirect to home page. Change home_url() to home_url( '/page-slug' ) to redirect to specific page. | |
| exit; | |
| } | |
| } | |
| add_action( 'template_redirect', 'my_redirect_non_members_example' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment