Created
April 22, 2024 07:40
-
-
Save andrewlimaza/e34b0fefedd249ff67952f85306e9800 to your computer and use it in GitHub Desktop.
Redirect to a default page, unless redirecting to content [Paid Memberships Pro]
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 to a default "members" page unless redirecting back to referrer. | |
* Adjust the URLS for $skip_redirects which it bypasses. | |
* | |
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_login_redirect_url( $redirect_to, $request, $user ) { | |
// Skip certain redirect_tos always | |
$skip_redirects = array( | |
site_url( '/login/' ), | |
site_url( '/wp-admin/' ) | |
); | |
// If the redirect_to is a skippable URL, let's remove the redirect_to so we can redirect to the members page. | |
if ( ! empty( $redirect_to ) && in_array( $redirect_to, $skip_redirects ) ) { | |
$redirect_to = ''; | |
} | |
//if logged in and a member, send to members page | |
if ( empty( $redirect_to ) && pmpro_hasMembershipLevel( NULL, $user->ID ) ) { | |
$redirect_to = site_url( '/members/' ); | |
} | |
return $redirect_to; | |
} | |
add_filter( 'login_redirect', 'my_pmpro_login_redirect_url', 5, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment