Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created July 23, 2020 14:13
Show Gist options
  • Save ipokkel/8351e27772728c28ab15e9aeb4732c57 to your computer and use it in GitHub Desktop.
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.
<?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