Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Last active November 3, 2021 18:20
Show Gist options
  • Save dparker1005/de9678ba99a9e4488f9b8167fa0b923a to your computer and use it in GitHub Desktop.
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.
<?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