Created
October 29, 2024 06:05
-
-
Save ipokkel/7ffed13963daf5ae574f404bbada5735 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Add a custom message to the confirmation message for specific email domains. | |
* | |
* 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/ | |
*/ | |
function add_email_note_to_pmpro_confirmation_message( $confirmation_message, $pmpro_invoice ) { | |
// Get the email address to check against | |
$from_email = get_option( 'admin_email' ); // Change this to the email address you want to check against | |
// Array of email domains to check | |
$email_domains = array( 'gmail', 'yahoo', 'hotmail' ); | |
// Get the user ID from the invoice object | |
$user_id = $pmpro_invoice->user_id; | |
// Get the user object | |
$user = get_userdata( $user_id ); | |
// Get the user email domain without the TLD. | |
$email_domain = substr( strrchr( $user->user_email, '@' ), 1 ); | |
$email_domain = explode( '.', $email_domain )[0]; | |
// Check if the user email domain matches any domain in the $email_domains array | |
if ( in_array( $email_domain, $email_domains, true ) ) { | |
// Add a custom message to the confirmation message | |
$confirmation_message .= '<p>Please whitelist <strong>' . $from_email . '</strong> in your email client and check your spam folder if the email did not appear in your inbox.</p>'; | |
} | |
return $confirmation_message; | |
} | |
add_filter( 'pmpro_confirmation_message', 'add_email_note_to_pmpro_confirmation_message', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment