Skip to content

Instantly share code, notes, and snippets.

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 JarrydLong/36c1f5e1a6d9ed95e062aa6023399d50 to your computer and use it in GitHub Desktop.
Save JarrydLong/36c1f5e1a6d9ed95e062aa6023399d50 to your computer and use it in GitHub Desktop.
Add Contact Form 7 to the Profile page when using the Member Directory and Profiles Add On for Paid Memberships Pro.
<?php
/**
* Add Contact Form 7 to the Profile page when using the Member Directory and Profiles Add On for Paid Memberships Pro.
* Update line 36 with the correct CF7 shortcode for your desired form to display.
* Add a hidden field to your form: "[hidden send-to-email default:shortcode_attr]".
* Set the "To" field of the Contact Form to "[send-to-email]".
*
*/
// Allow custom shortcode attribute for "send-to-email".
function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
$my_attr = 'send-to-email';
if ( isset( $atts[$my_attr] ) ) {
$out[$my_attr] = $atts[$my_attr];
}
return $out;
}
add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );
// Add the contact form to the profile page using Contact Form 7.
function append_profile_page_with_cf7( $content ) {
global $pmpro_pages;
//Get the profile user
if( ! function_exists( 'pmpromd_get_user' ) ) {
return $content;
}
$pu = pmpromd_get_user();
if ( ! empty( $pu ) && shortcode_exists( 'contact-form-7' ) && is_page( $pmpro_pages['profile'] ) ) {
$content .= do_shortcode( '[contact-form-7 id="271" title="Contact form 1" send-to-email="' . $pu->user_email . '"]' );
}
return $content;
}
add_filter( 'the_content', 'append_profile_page_with_cf7' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment