Forked from ipokkel/pmpro-approvals-custom-message-data.php
Last active
September 20, 2021 20:50
-
-
Save kimwhite/9fa9d8aa24bfc1bf542e9299a0f0cec8 to your computer and use it in GitHub Desktop.
Create a custom message email variable for PMPro Approvals Add On.
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 | |
/** | |
* This recipe adds a custom message per membership level to PMPro_Approvals email data. | |
*. ADDED - Custom Shortcode to add to Subject Line !!custom_subject!! | |
* This recipe assumes that the !!custom_approved_message!! variable was added to the | |
* Approvals - Approved Email template, and | |
* the !!custom_denied_message!! variable was added to the | |
* Approvals - Denied Email template. | |
* | |
* 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/ | |
*/ | |
// # APPROVED # | |
// Data for the !!custom_approved_message!! email variable in the Approvals - Approved Email template. | |
function my_pmpro_approvals_member_approved_email_data( $data, $member ) { | |
$level_id = $data['membership_id']; | |
$membership_level_name = $data['membership_level_name']; | |
// Let's match the approval level ID and create a custom message for that level. | |
switch ( $level_id ) { | |
case '1': | |
$custom_approved_message = '<p>' . esc_html( 'You are now a member of the ' . $membership_level_name . ' level.' ) . '</p>'; | |
$custom_subject = esc_html( 'Subject Variable ' ); | |
break; | |
case '2': | |
$custom_approved_message = '<p>' . esc_html( 'Custom approved message for the ' . $membership_level_name . ' level.' ) . '</p>'; | |
$custom_subject = esc_html( 'Subject Variable Two' ); | |
break; | |
default: | |
$custom_approved_message = '<p>' . esc_html( 'Default message here for other approval levels not specified above' ) . '</p>'; | |
$custom_subject = esc_html( 'Subject Default ' ); | |
break; | |
} | |
$data['custom_approved_message'] = $custom_approved_message; | |
$data['custom_subject'] = $custom_subject; | |
return $data; | |
} | |
add_filter( 'pmpro_approvals_member_approved_email_data', 'my_pmpro_approvals_member_approved_email_data', 10, 2 ); | |
// # DENIED # | |
// Data for the !!custom_denied_message!! email variable in the Approvals - Denied Email template. | |
function my_pmpro_approvals_member_denied_email_data( $data, $member ) { | |
$level_id = $data['membership_id']; | |
$membership_level_name = $data['membership_level_name']; | |
// Let's match the approval level ID and create a custom message for that level. | |
switch ( $level_id ) { | |
case '1': | |
$custom_denied_message = '<p>' . esc_html( 'Custom message for the ' . $membership_level_name . ' level.' ) . '</p>'; | |
break; | |
case '2': | |
$custom_denied_message = '<p>' . esc_html( 'Custom message for the ' . $membership_level_name . ' level.' ) . '</p>'; | |
break; | |
default: | |
$custom_denied_message = '<p>' . esc_html( 'Default message here for other approval levels not specified above' ) . '</p>'; | |
break; | |
} | |
$data['custom_denied_message'] = $custom_denied_message; | |
return $data; | |
} | |
add_filter( 'pmpro_approvals_member_denied_email_data', 'my_pmpro_approvals_member_denied_email_data', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment