Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created April 10, 2018 15:02
Show Gist options
  • Save pbrocks/494e5dbf7539d1d909420d2b11680b68 to your computer and use it in GitHub Desktop.
Save pbrocks/494e5dbf7539d1d909420d2b11680b68 to your computer and use it in GitHub Desktop.
A function that will redirect users based on their PMPro membership level during confirmation.
<?php
/**
* The function some_kind_of_pmpro_redirection is an arbitrary name given to the
* function created to run this specific bit of code. You can name it anything
* meaningful that you like, assuming that it is unique to the code on the site.
*
* The name of the filter hook, however, is not arbitrary as this is something
* created by the PMPro plugin. In this case, pmpro_confirmation_url, tells
* WordPress when to run this code in the some_kind_of_pmpro_redirection function.
*
* For this to run properly, WordPress requires that you have 3 arguments specified:
* the URL the user will be directed to, the URL the user is coming from and the
* logged in user's data. PMPro alters this in the context of membership revealing:
*
* @param string $return_url the URL the user will be directed to
* @param string $user_id the ID of the current user
* @param string $pmpro_level the ID of the current user's level
* @return string the URL the user will be directed to adjusted for appropriate level
*/
function some_kind_of_pmpro_redirection( $return_url, $user_id, $pmpro_level ) {
if ( pmpro_hasMembershipLevel( 1 ) ) {
$return_url = home_url( 'page-name-for-level-1' );
} elseif ( pmpro_hasMembershipLevel( 2 ) ) {
$return_url = home_url( 'page-name-for-level-2' );
} elseif ( pmpro_hasMembershipLevel( 3 ) ) {
$return_url = home_url( 'page-name-for-level-3' );
}
return $return_url;
}
add_filter( 'pmpro_confirmation_url', 'some_kind_of_pmpro_redirection', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment