Created
July 23, 2020 14:13
-
-
Save ipokkel/8351e27772728c28ab15e9aeb4732c57 to your computer and use it in GitHub Desktop.
This recipe add user meta as email variables that may be used for the PMPro Email Template Editor Add On.
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 add user meta as email variables that may be used for | |
* the PMPro Email Template Editor Add On. | |
* | |
* 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['first_name'] = get_user_meta( $user->ID, 'first_name', true ); | |
} | |
if ( ! empty( $user ) && ! empty( $user->ID ) ) { | |
$data['prefix'] = get_user_meta( $user->ID, 'prefix', 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