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 kimcoleman/08ff6dc52e2894896a6d9800fe16bd03 to your computer and use it in GitHub Desktop.
Save kimcoleman/08ff6dc52e2894896a6d9800fe16bd03 to your computer and use it in GitHub Desktop.
Add Contact Form 7 to the Profile page's Memberlite Sidebar 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 my_memberlite_cf7_profile_page_before_sidebar_widgets( ) {
global $pmpro_pages;
//Get the profile user
if ( isset( $_REQUEST['pu'] ) ) {
if ( is_numeric($_REQUEST['pu'] ) ) {
$pu = get_user_by( 'id', $_REQUEST['pu'] );
} elseif( ! empty( $_REQUEST['pu'] ) ) {
$pu = get_user_by( 'slug', $_REQUEST['pu'] );
} else {
$pu = false;
}
}
if ( ! empty( $pu ) && shortcode_exists( 'contact-form-7' ) && is_page( $pmpro_pages['profile'] ) ) {
echo do_shortcode( '[contact-form-7 id="599" title="Contact form 1" send-to-email="' . $pu->user_email . '"]' );
}
}
add_action( 'memberlite_before_sidebar_widgets', 'my_memberlite_cf7_profile_page_before_sidebar_widgets' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment