Created
March 13, 2024 06:39
-
-
Save ipokkel/ec5e06137a85a45a95ddef3b0732ffbc to your computer and use it in GitHub Desktop.
Redirect members to their account page from a page with the PMPro Signup Shortcode
This file contains 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 users who are already members away from the PMPro Signup Shortcode. | |
* | |
* 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_pmprosus_redirect_members() { | |
global $current_user; | |
// Let's first check if we should do this. | |
if ( ! function_exists( 'pmprosus_signup_shortcode' ) || ! function_exists( 'pmpro_url' ) || ! has_shortcode( get_post()->post_content, 'pmpro_signup' ) ) { | |
return; | |
} | |
// Redirect to the PMPro Account page. | |
$location = pmpro_url( 'account' ); // Replace "account" with "levels" if you want to redirect to the levels page. | |
// Redirect members away from the PMPro Signup Shortcode. | |
if ( ! empty( $current_user->ID ) && pmpro_hasMembershipLevel() ) { | |
wp_safe_redirect( $location ); | |
exit; | |
} | |
} | |
add_action( 'template_redirect', 'my_pmprosus_redirect_members' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment