Skip to content

Instantly share code, notes, and snippets.

@gausam
Created October 12, 2020 06:52
Show Gist options
  • Save gausam/ff547ced22b769200bd6efc074f067b0 to your computer and use it in GitHub Desktop.
Save gausam/ff547ced22b769200bd6efc074f067b0 to your computer and use it in GitHub Desktop.
Copy an additional email address when admin approval is required for a specific membership level.
<?php
/**
* This recipe copies an additional email address when admin approval is
* required for a specific membership level.
*
* It is intended for use with the Approval Process for Membership Add On:
* https://www.paidmembershipspro.com/add-ons/approval-process-membership/
*
* 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 my_pmpro_email_filter($email) {
$membership_level_id = 1; // use target membership level
$email_to_copy = "test@example.com"; // use correct email address
if (
$email->template === 'admin_notification_approval' &&
$email->data['membership_id'] === $membership_level_id
) {
// Make sure we have a headers array
if ( empty( $email->headers ) ) {
$email->headers = array();
} elseif ( ! is_array( $email->headers ) ) {
$email->headers = array( $email->headers );
}
$email->headers[] = "Cc:" . $email_to_copy;
}
return $email;
}
add_filter( 'pmpro_email_filter', 'my_pmpro_email_filter' , 10, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment