Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Forked from ipokkel/my-pmpro-email-data.php
Last active February 9, 2023 07:32
Show Gist options
  • Save dwanjuki/44afb59a796d2568806311bafdd6b708 to your computer and use it in GitHub Desktop.
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.
<?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