Support » Plugin: Contact Form 7 - Campaign Monitor Addon » WordPress 4.0 compatibility issues

Viewing 3 replies - 1 through 3 (of 3 total)
  • This is not WP issue. this is due to contact form 7 changes.

    In file cf7-campaignmonitor.php on line approx:161 replace whole function function wpcf7_cm_subscribe($obj) with this code

    function wpcf7_cm_subscribe($obj)
    {
    	$cf7_cm = get_option( 'cf7_cm_'.$obj->id() );
    	$submission = WPCF7_Submission::get_instance();
    
    	if( $cf7_cm )
    	{
    		$subscribe = false;
    
    		$regex = '/\[\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\s*\]/';
    		$callback = array( &$obj, 'cf7_cm_callback' );
    
    		$email = cf7_cm_tag_replace( $regex, $cf7_cm['email'], $submission->get_posted_data() );
    		$name = cf7_cm_tag_replace( $regex, $cf7_cm['name'], $submission->get_posted_data() );
    
    		$lists = cf7_cm_tag_replace( $regex, $cf7_cm['list'], $submission->get_posted_data() );
    		$listarr = explode(',',$lists);
    
    		if( isset($cf7_cm['accept']) && strlen($cf7_cm['accept']) != 0 )
    		{
    			$accept = cf7_cm_tag_replace( $regex, $cf7_cm['accept'], $submission->get_posted_data() );
    			if($accept != $cf7_cm['accept'])
    			{
    				if(strlen($accept) > 0)
    					$subscribe = true;
    			}
    		}
    		else
    		{
    			$subscribe = true;
    		}
    
    		for($i=1;$i<=20;$i++){
    
    			if( isset($cf7_cm['CustomKey'.$i]) && isset($cf7_cm['CustomValue'.$i]) && strlen(trim($cf7_cm['CustomValue'.$i])) != 0 )
    			{
    				$CustomFields[] = array('Key'=>trim($cf7_cm['CustomKey'.$i]), 'Value'=>cf7_cm_tag_replace( $regex, trim($cf7_cm['CustomValue'.$i]), $submission->get_posted_data() ) );
    			}
    
    		}
    
    		if( isset($cf7_cm['resubscribeoption']) && strlen($cf7_cm['resubscribeoption']) != 0 )
    		{
    			$ResubscribeOption = true;
    		}
    			else
    		{
    			$ResubscribeOption = false;
    		}
    
    		if($subscribe && $email != $cf7_cm['email'])
    		{
    
    			require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'csrest_subscribers.php');
    
    			$wrap = new CF7CM_CS_REST_Subscribers( trim($listarr[0]), $cf7_cm['api'] );
    			foreach($listarr as $listid)
    			{
    				$wrap->set_list_id(trim($listid));
    				$wrap->add(array(
    					'EmailAddress' => $email,
    					'Name' => $name,
    					'CustomFields' => $CustomFields,
    					'Resubscribe' => $ResubscribeOption
    				));
    			}
    
    		}
    
    	}
    }

    basically these are the changes you need to take care if you are using any custom code related to contact form 7

    /* Don't do this, since id property is no longer accessible. */
    $id = $contact_form->id; // Wrong.
    
    /* Use id() method instead. */
    $id = $contact_form->id();
    
    /* Properties form, mail, mail_2, messages, additional_settings are inaccessible as well. */
    $form = $contact_form->form; // Wrong.
    
    /* So, use prop() method to access them. */
    $form = $contact_form->prop( 'form' );
    
    /* To set the properties, use set_properties() method, like this: */
    $mail = $contact_form->prop( 'mail' );
    $mail['subject'] = "Well, hello, Dolly";
    $contact_form->set_properties( array( 'mail' => $mail ) );
    
    /* WPCF7_ContactForm object no longer has a posted_data property. */
    $posted_data = $contact_form->posted_data; // Wrong.
    
    /* Use WPCF7_Submission object's get_posted_data() method to get it. */
    $submission = WPCF7_Submission::get_instance();
    
    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }

    Hi,

    If you need to get this working in WP 4.0.1 with CF7 v4.0.2, you need to change the function mentioned above, but you also need to change:

    add_action( ‘wpcf7_admin_before_subsubsub’, ‘add_cm_meta’ );

    to:

    add_action( ‘wpcf7_admin_notices’, ‘add_cm_meta’ );

    around line 40 of cf7-campaignmonitor.php 🙂

    As soon as I found this little gem hidden away on Google, the campaign monitor settings all popped up again and were still set to the previous settings.

    P.S. Thanks fmzac for the function change 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress 4.0 compatibility issues’ is closed to new replies.