Created
September 21, 2023 05:58
-
-
Save ipokkel/45992b04e1bccba2cfe412678241f347 to your computer and use it in GitHub Desktop.
Send a copy of PMPro Approval admin notification emails to users that have the pmpro_approvals capability. This should include users that has the pmpro_approver role or the pmpro_membership_manager role role.
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 | |
/** | |
* Bcc admin approval emails to users with pmpro_approvals capability. | |
* | |
* 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 pmpro_approvals_bcc_admin_notification_emails( $headers, $email ) { | |
$approval_admin_email_templates = array( | |
'admin_approved', | |
'admin_denied', | |
'admin_notification_approval', | |
); | |
// Is this email an approvals admin notification email? | |
if ( ! in_array( $email->template, $approval_admin_email_templates ) ) { | |
return $headers; | |
} | |
// Get all users with pmpro_approvals capability. | |
$users_with_capability_pmpro_approvals = get_users( | |
array( | |
'capability' => 'pmpro_approvals', | |
'fields' => 'user_email', | |
) | |
); | |
// Remove site admin email from array. | |
$users_with_capability_pmpro_approvals = array_diff( $users_with_capability_pmpro_approvals, array( get_bloginfo( 'admin_email' ) ) ); | |
// Add Bcc to headers. | |
if ( ! empty( $users_with_capability_pmpro_approvals ) ) { | |
$headers[] = 'Bcc:' . implode( ',', $users_with_capability_pmpro_approvals ); | |
} | |
return $headers; | |
} | |
add_filter( 'pmpro_email_headers', 'pmpro_approvals_bcc_admin_notification_emails', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment