Last active
November 3, 2021 18:20
-
-
Save dparker1005/de9678ba99a9e4488f9b8167fa0b923a to your computer and use it in GitHub Desktop.
Will redirect users without a $required_levels away from pages where the request uri begins with '/places/'. Useful to lock down the archive page and CPTs of GeoDirectory plugin.
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 from below here | |
/** | |
* Will redirect users without a $required_levels away from pages where the request uri begins with '/places/'. | |
* Useful to lock down the archive page and CPTs of GeoDirectory plugin. | |
*/ | |
function my_pmpro_redirect_places() { | |
$request_uri_to_redirect = '/places/'; | |
$required_levels = array( 2, 3 ); | |
if ( ! is_admin() && | |
substr(strtolower( $_SERVER['REQUEST_URI'] ), 0, strlen($request_uri_to_redirect) ) === $request_uri_to_redirect && | |
! pmpro_hasMembershipLevel( $required_levels ) | |
) { | |
wp_redirect(home_url("membership-account/membership-levels")); | |
exit; | |
} | |
} | |
add_action('template_redirect', 'my_pmpro_redirect_places'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment