Created
August 6, 2026 15:39
-
-
Save dwanjuki/64006d04436ea0bb38af3438a2de5607 to your computer and use it in GitHub Desktop.
Don't Send the Membership Expired Email When a Member Is Given a Grace Period
This file contains hidden or 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 | |
| /** | |
| * Don't Send the Membership Expired Email When a Member Is Given a Grace Period | |
| * | |
| * Pairs with the "Add a Grace Period to a Membership Level" recipe here: | |
| * https://www.paidmembershipspro.com/add-a-grace-period/ | |
| * | |
| * 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/ | |
| */ | |
| /** | |
| * Remember which membership level is currently being expired. | |
| */ | |
| function my_pmpro_record_expiring_level_id( $user_id, $level_id ) { | |
| global $my_pmpro_expiring_level_id; | |
| $my_pmpro_expiring_level_id = $level_id; | |
| } | |
| add_action( 'pmpro_membership_post_membership_expiry', 'my_pmpro_record_expiring_level_id', 5, 2 ); | |
| /** | |
| * Skip the membership expired email when that level is active again (a grace period). | |
| */ | |
| function my_pmpro_skip_expiration_email_during_grace( $send_email, $user_id ) { | |
| global $my_pmpro_expiring_level_id; | |
| // Nothing recorded, so this email isn't part of an expiration we tracked. | |
| if ( empty( $my_pmpro_expiring_level_id ) ) { | |
| return $send_email; | |
| } | |
| $level_id = $my_pmpro_expiring_level_id; | |
| // Reset now so a later expiration in the same request can't reuse this level ID. | |
| $my_pmpro_expiring_level_id = null; | |
| // The level that just expired is active again, so the member is in a grace period. | |
| if ( pmpro_getSpecificMembershipLevelForUser( $user_id, $level_id ) ) { | |
| return false; | |
| } | |
| return $send_email; | |
| } | |
| add_filter( 'pmpro_send_expiration_email', 'my_pmpro_skip_expiration_email_during_grace', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment