Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created August 6, 2018 08:13
Show Gist options
  • Save andrewlimaza/df4ff6e00886a748a62865b4aa2b241d to your computer and use it in GitHub Desktop.
Save andrewlimaza/df4ff6e00886a748a62865b4aa2b241d to your computer and use it in GitHub Desktop.
redirect user away from the page if they do not have a specific membership level.
<?php
/**
* This will redirect members with level 1 from site.com/page-slug to the home page.
* Please adjust accordingly and add to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function redirect_member_from_page_x() {
if ( is_page( 'page-slug' ) && pmpro_hasMembershipLevel( 1 ) ) {
wp_redirect( home_url() ); //redirect to home page. Change home_url() to home_url( '/page-slug' ) to redirect to specific page.
exit;
}
}
add_action( 'template_redirect', 'redirect_member_from_page_x' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment