Support » Plugin: Contact Form 7 » [Plugin: Contact Form 7] Controlling the send to option

Viewing 4 replies - 1 through 4 (of 4 total)
  • At most simplest, you can do the following –

    Create two contact form – 1) for Logged in user and 2) for other user. Make the necessary respective setting for the forms and use login conditional check to display the proper form to the visitors.

    If you can do moderate PHP coding, there is a way, but it includes changing a file of the plugin, so if you ever update the plugin, you have to include this change again.

    1. Set the “send to” of your form to b@mysite.com (default: not logged in)

    2. Make a backup copy of plugin file contact-form-7/includes/classes.php in case something goes wrong.

    3. In plugin file contact-form-7/includes/classes.php at around line 500 locate this:

    $recipient = $this->replace_mail_tags( $mail_template['recipient'] );

    4. Add a new line of code so it looks like this:

    $recipient = $this->replace_mail_tags( $mail_template['recipient'] );
    $recipient = apply_filters( 'ov3rfly_wpcf7_change_recipient', $recipient );

    5. Then in your themes function.php add this:

    function my_change_recipient( $recipient ) {
    	if ( is_user_logged_in() ) {
    		$recipient = 'a@mysite.com';
    	}
    	return $recipient;
    }
    add_filter( 'ov3rfly_wpcf7_change_recipient', 'my_change_recipient' );

    @ov3rfly I dont think changing the core plugin files is a good idea.

    @biswajeet Thanks for the hint. Would try that.

    If anyone has a better solution, pls share.

    Oh, actually there is a much easier way, I just did not see the filter-call in the plugin earlier, I only looked for apply_filters() and not for apply_filters_ref_array()

    No changes in plugin required, just use this:

    1. Set the “send to” of your form to b@mysite.com (default: not logged in)

    2. Then in your themes function.php add this:

    function my_wpcf7_mail_components( $arr, $this = '' ) {
    	if ( is_user_logged_in() ) {
    		$arr['recipient'] = 'a@mysite.com';
    	}
    	return $arr;
    }
    add_filter( 'wpcf7_mail_components', 'my_wpcf7_mail_components' );

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Contact Form 7] Controlling the send to option’ is closed to new replies.