Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Created October 29, 2020 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronalfy/38fb653ca4447a8d981554042837c265 to your computer and use it in GitHub Desktop.
Save ronalfy/38fb653ca4447a8d981554042837c265 to your computer and use it in GitHub Desktop.
PMPro - Add RH to Approval Emails
<?php
/**
* Adds Register Helper Fields to the Approvals Email.
*
* 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_pmprorh_approval_email_filter( $email ) {
if ( ! function_exists( 'pmprorh_getProfileFields' ) ) {
return $email;
}
global $wpdb;
// only update admin confirmation emails
if ( ! empty( $email ) && strpos( $email->template, 'approval' ) !== false && strpos( $email->template, 'admin' ) !== false ) {
// get the user_id from the email
$user_id = $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_email = '" . $email->data['member_email'] . "' LIMIT 1" );
if ( ! empty( $user_id ) ) {
// get meta fields
$fields = pmprorh_getProfileFields( $user_id );
// add to bottom of email
if ( ! empty( $fields ) ) {
$email->body .= '<p>Extra Fields:<br />';
foreach ( $fields as $field ) {
if ( ! is_a( $field, 'PMProRH_Field' ) ) {
continue;
}
$email->body .= '- ' . $field->label . ': ';
$value = get_user_meta( $user_id, $field->meta_key, true );
if ( $field->type == 'file' && is_array( $value ) && ! empty( $value['fullurl'] ) ) {
$email->body .= $value['fullurl'];
} elseif ( is_array( $value ) ) {
$email->body .= implode( ', ', $value );
} else {
$email->body .= $value;
}
$email->body .= '<br />';
}
$email->body .= '</p>';
}
}
}
return $email;
}
add_filter( 'pmpro_email_filter', 'my_pmpro_pmprorh_approval_email_filter', 10, 2 );
@kimwhite
Copy link

This has been updated to work with the new User Fields from 2.9 - 2022-07-18
https://gist.github.com/kimwhite/1c277d1b80540cecc57f78401149f04e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment