Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/ec5e06137a85a45a95ddef3b0732ffbc to your computer and use it in GitHub Desktop.
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
<?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