Created
April 4, 2025 11:55
-
-
Save dwanjuki/e731fff96745f0969ccb5cf60b2a4920 to your computer and use it in GitHub Desktop.
Redirect visitors without membership access form the The Events Calendar archive 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 | |
/** | |
* Redirect visitors without membership access form the The Events Calendar archive page | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_tribe_events_archive_require_membership() { | |
if ( is_post_type_archive( 'tribe_events' ) && function_exists( 'pmpro_hasMembershipLevel' ) && ! pmpro_hasMembershipLevel( array( 1, 2, 3 ) ) ) { | |
$location = home_url( '/path-to-redirect/' ); | |
$location = wp_sanitize_redirect( $location ); | |
header( 'Location: '. $location, true, 302 ); | |
} | |
} | |
add_action( 'template_redirect', 'my_tribe_events_archive_require_membership' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
header()
aswp_redirect()
isn't working with the tribe_events post type.