Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save champsupertramp/0e7175e46a5100cd948368b1c1cbfe1d to your computer and use it in GitHub Desktop.
Save champsupertramp/0e7175e46a5100cd948368b1c1cbfe1d to your computer and use it in GitHub Desktop.
Ultimate Member Profile Tabs with Contact Form 7
add_filter( 'wpcf7_mail_components', 'um_020821_change_email_to_profile_owner_email', 10, 3 );
function um_020821_change_email_to_profile_owner_email( $args, $contact_form, $class){
if ( class_exists( '\WPCF7_Submission' ) ) {
$submission = \WPCF7_Submission::get_instance();
$page = $submission->get_meta( 'container_post_id' );
if ( intval( UM()->options()->get( 'core_user' ) ) == intval( $page ) ) {
if ( ! empty( $_REQUEST['_wpcf7_um_profile_id'] ) ) {
$user = get_user_by( 'ID', absint( $_REQUEST['_wpcf7_um_profile_id'] ) );
if ( ! is_wp_error( $user ) && isset( $user->user_email ) && is_email( $user->user_email ) ) {
$args['recipient'] = $user->user_email;
}
}
}
}
return $args;
}
add_filter( 'wpcf7_form_hidden_fields', 'um_020821_add_profile_id_on_cf7' );
function um_020821_add_profile_id_on_cf7( $fields ){
if ( um_is_core_page( 'user' ) ) {
$fields['_wpcf7_um_profile_id'] = um_profile_id();
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment