Reply To: buddypress function in themes functions.php
Maybe I should explan more in detail what I’m trying to achieve.
After the members loop I have added a custom template (my-contact-form.php). This template just calls the Plugin Contact Form 7:
echo do_shortcode( '[contact-form-7 id="1235" title="Contact form 1"]' );
So a contact form is displayed after a members profile.
Now I would like to make it possible to write an email to the member in the contact form. The advantage is that the visitor doesn’t need to be logged in.
So in bp-custom.php I have now the following:
function mycf7_before_send_mail($WPCF7_ContactForm) {
$new_recipient = xprofile_get_field_data('Email for contact', bp_displayed_user_id(), $multi_format = 'comma');
$mail = $WPCF7_ContactForm->prop('mail');
$mail['recipient'] = $new_recipient;
$WPCF7_ContactForm->set_properties( array( 'mail' => $mail ) );
}
add_action( "wpcf7_before_send_mail", "mycf7_before_send_mail" );
It does not work. But when I change the xprofile_get… to a concrete email it does work. For instance:
// Custom Recipient
function mycf7_before_send_mail($WPCF7_ContactForm) {
$new_recipient = "recipient@email.de";
$mail = $WPCF7_ContactForm->prop('mail');
$mail['recipient'] = $new_recipient;
$WPCF7_ContactForm->set_properties( array( 'mail' => $mail ) );
}
add_action( "wpcf7_before_send_mail", "mycf7_before_send_mail" );
At the same time the email of the member is displayed if I echo it with echo xprofile_get_field_data('Email for contact', bp_displayed_user_id(), $multi_format = 'comma'); in the my-contact-form.php.
So the problem is that the function xprofile_get… is just working in themy-contact-form.php. Any suggestions?