Forked from messica/my_pmpro_login_redirect_url.php
Last active
March 15, 2022 03:30
-
-
Save travislima/014d2f45d66fed8ad4cacb1d4f3526a9 to your computer and use it in GitHub Desktop.
Redirect on login if user has any failed payments. (Requires Paid Memberships Pro Failed Payment Limit Add On)
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 on login if user has any failed payments. (Requires Paid Memberships Pro Failed Payment Limit Add On) | |
* Adjust the code on the line the line "site_url( ' payment-failed')" to redirect to page of your prefereance. | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_login_redirect_url( $url, $request, $user ) { | |
// Set failed payment redirect URL here. | |
$failed_payment_redirect_url = site_url( 'payment-failed' ); | |
if ( empty( $user->ID ) ) { | |
return; | |
} | |
$failed_payments = get_user_meta( $user->ID, 'pmpro_failed_payment_count', true ); | |
if ( $failed_payments ) { | |
$url = site_url( 'payment-failed' ); | |
} | |
return $url; | |
} | |
add_filter( 'pmpro_login_redirect_url', 'my_pmpro_login_redirect_url', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Redirect Members Who Have A Failed Payment To A Page Of Your Choice." at Paid Memberships Pro here: https://www.paidmembershipspro.com/redirect-members-who-have-a-failed-payment-to-a-page-of-your-choice/