Skip to:
Content
Pages
Categories
Search
Top
Bottom

buddypress function in themes functions.php


  • barodscheff
    Participant

    @barodscheff

    Hi guys!

    Just a short question.
    I’ve created a custom funtion in my themes functions.php (not in buddypress-functions.php!).
    The interesting part looks like this:

    function mycf7_before_send_mail($WPCF7_ContactForm) {
    	
    	$new_recipient = bp_get_profile_field_data('field=Email for contact&user_id='.bp_displayed_user_id());
    	
    	$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" );		

    So I’m trying to call a buddypress function to get the email of the currently visited user. But the buddypress function is not working in functions.php. Any suggestions how to solve it? I can’t call it in buddypress-functions.php. It needs to be in the themes functions.php.

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)

  • shanebp
    Moderator

    @shanebp

    Try changing this:
    $new_recipient = bp_get_profile_field_data('field=Email for contact&user_id='.bp_displayed_user_id());

    to this:
    $new_recipient = xprofile_get_field_data('Email for contact', bp_displayed_user_id(), $multi_format = 'comma');


    barodscheff
    Participant

    @barodscheff

    No unfortunately not.
    If I echo the code directly in the page template it works. My code did it too. But both do not work in the funtions.php.


    shanebp
    Moderator

    @shanebp

    Try it in bp-custom.php


    barodscheff
    Participant

    @barodscheff

    Still the same problem 🙁


    barodscheff
    Participant

    @barodscheff

    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?


    barodscheff
    Participant

    @barodscheff

    No one?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘buddypress function in themes functions.php’ is closed to new replies.
Skip to toolbar