For my own reference, hereās the code you are wanting to modify:
add_action( 'wpdc_sso_provider_before_sso_redirect', 'wpdc_custom_check_user_membership', 10, 2 );
function wpdc_custom_check_user_membership( $user_id, $user ) {
if ( /* some condition */ ) {
wp_safe_redirect( home_url() );
exit;
}
}
What you need to do is replace the codeās /* some condition */
comment with a condition that will return true
for users who do not have paid memberships. These users can then be redirected to your membership signup page.
I donāt currently have the Paid Memberships Pro plugin installed on my test site, but from their documentation, it looks like you can use their pmpro_hasMembershipLevel
function to check if a user has a given membership level: https://www.paidmembershipspro.com/documentation/content-controls/require-membership-function/.
To use the pmpro_hasMembershipLevel
function, you need to know the IDs (or the names) of your two paid membership levels. You can get those ids from the pmp āMembership Levelsā admin page. For example, if the IDs of your two paid levels are 1 and 2, you could use the following condition:
if (! pmpro_hasMembershipLevel(array(1, 2), $user_id))
Substituted into the code, that would be:
add_action( 'wpdc_sso_provider_before_sso_redirect', 'wpdc_custom_check_user_membership', 10, 2 );
function wpdc_custom_check_user_membership( $user_id, $user ) {
if (! pmpro_hasMembershipLevel( array( 1, 2 ), $user_id ) ) {
wp_safe_redirect( home_url() );
exit;
}
}
The other line you will need to change is:
wp_safe_redirect( home_url() );
It is currently set to redirect users to the siteās homepage. You will need to change it to redirect to either the path or the full URL of your siteās sign-up page:
wp_safe_redirect( /* path_to_your_signup_page */ );
Note that I havenāt tested this code. If you are making changes directly to your live siteās functions.php
file, make sure that you are able to access the siteās functions.php
file from the siteās backend, just in case there are any mistakes or typos in the code.