Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created October 12, 2022 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/89d4ab2d9944b8b86aec4b3008598dc3 to your computer and use it in GitHub Desktop.
Save ideadude/89d4ab2d9944b8b86aec4b3008598dc3 to your computer and use it in GitHub Desktop.
Add user_id as a data variable for email templates in PMPro
<?php
/* This code will add user_id as a data variable for email templates in PMPro.
*
* 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/
*/
// begin copying code below here
function my_pmpro_email_custom_data($data, $email) {
if( ! empty( $data['user_login'] ) ) {
$user = get_user_by( "login", $data['user_login'] );
$data['user_id'] = $user->ID;
}
return $data;
}
add_filter( "pmpro_email_data", "my_pmpro_email_custom_data", 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment