-
-
Save dwanjuki/44afb59a796d2568806311bafdd6b708 to your computer and use it in GitHub Desktop.
This recipe adds user fields as email variables that may be used in PMPro Email Templates.
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 | |
/** | |
* This recipe adds a user field as an email variable !!your_field_name!! that may be used in PMPro Email Templates. | |
* | |
* 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_data( $data, $email ) { | |
if ( ! empty( $data['user_login'] ) ) { | |
$user = get_user_by( 'login', $data['user_login'] ); | |
if ( ! empty( $user ) && ! empty( $user->ID ) ) { | |
$data['your_field_name'] = get_user_meta( $user->ID, 'your_field_name', true ); | |
} | |
} | |
return $data; | |
} | |
add_filter( 'pmpro_email_data', 'my_pmpro_email_data', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment