Created
April 13, 2022 09:52
-
-
Save aliss1105/a4f82b5d0fcf1a3cd65cdb5d0b92ceb9 to your computer and use it in GitHub Desktop.
Contact form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 ( 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'] ) ) { | |
$content .= do_shortcode( '[contact-form-7 id="834" title="Formulaire de contact 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