• Hi,

    I’m using CF7 with MultiSite (3 websites). It works well however I have a form on all three websites called ‘Attachment’, all of which have their own form id number.

    Each form has the same function which hooks into the wpcf7_before_send_mail. See the code below.

    function send_pdf( $cf7 ) {
    	$id = $cf7->id();
    	if ($id==195){
    		$submission = WPCF7_Submission::get_instance();
    		$posted_data = $submission->get_posted_data();
    
    		$url = $submission->get_meta( 'url' );
    		$postid = url_to_postid( $url );
    		$tdsfileurl = get_field('house_plan_attachment' , $postid);
    		$title = get_the_title($postid);
    
    		$explode = explode("/", $tdsfileurl);
    		$end = '';
    		$begin = '';
    		if(count($explode) > 0){
    			$end = array_pop($explode);
    			if(count($explode) > 0){
    				$begin = implode('/', $explode);
    			}
    		}
    		$t=time();
    		$hostname = $_SERVER['HTTP_HOST'];
    		$newfile2 = explode($hostname, $begin);
    		$newfile = $_SERVER['DOCUMENT_ROOT'] . '' .$newfile2['1'].'/'.$title.'_House_Plan.pdf';
    		error_log('$tdsfileurl: ' . $tdsfileurl);
    		error_log('$newfile: ' . $newfile);
    		if ( copy($tdsfileurl, $newfile) ) {
    			error_log('File copied');
    			$submission->add_uploaded_file('pdf', $newfile);
    		}else{
    			error_log('Not able to attach file');
    		}
    	}
    }
    add_action('wpcf7_before_send_mail','send_pdf');

    The form works on all three websites however it only includes the attachment on the primary website and not the the 2 websites?

    I made sure the id is different on all three functions to match the form id.

    Cheers

    Tim

    https://wordpress.org/plugins/contact-form-7/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘CF7 with Multisite’ is closed to new replies.