Quantcast
Channel: WordPress.org Forums » [Contact Form 7] Support
Viewing all articles
Browse latest Browse all 49500

permaculturetreegeek on "[Plugin: Contact Form 7] Contact form 7 subscribe to wysiga newsletter on submit"

$
0
0

In case anyone else has this question. I found most of this solution online... and modified it a bit.

Add the following code to the functions.php file of contact form 7 plugin. It is commented to help with configuration.

/*
*********************************************
		contact 7 subscribe to wysiga email list
*********************************************
	*/

function wpcf7_array_flatten( $input ) {
	if ( ! is_array( $input ) )
		return array( $input );

	$output = array();

	foreach ( $input as $value )
		$output = array_merge( $output, wpcf7_array_flatten( $value ) );

	return $output;
}

function wpcf7_support_html5() {
	return (bool) apply_filters( 'wpcf7_support_html5', true );
}

function wpcf7_format_atts( $atts ) {
	$html = '';

	$prioritized_atts = array( 'type', 'name', 'value' );

	foreach ( $prioritized_atts as $att ) {
		if ( isset( $atts[$att] ) ) {
			$value = trim( $atts[$att] );
			$html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) );
			unset( $atts[$att] );
		}
	}

	foreach ( $atts as $key => $value ) {
		$value = trim( $value );

		if ( '' !== $value )
			$html .= sprintf( ' %s="%s"', $key, esc_attr( $value ) );
	}

	$html = trim( $html );

	return $html;
}

function wysija_contactform7_subscribe($cfdata) {

	$formdata = $cfdata->posted_data;

	/*
'your-name' and 'your-email' are from the default template change them to match the ones you use in your form.
	*/

	$user_name = $formdata['your-name'];

	$user_email = $formdata['your-email'];

	/*

Insert the list id # you want the user to be subscribed to. The default list id is 1. This can be an array if you have more than one list. Example: $listID = array( '1,2' );
	*/

	$listID = array( '1' );	

	$userData=array(

		'email'		=>	$user_email,

		'firstname'	=>	$user_name

	);

	$data=array(

		'user'		=>	$userData,

		'user_list'	=>	array( 'list_ids'=> $listID )

	);

	$userHelper=&WYSIJA::get('user','helper');

	$userHelper->addSubscriber($data);

}
/*
Nothing will happen unless you give the user a chance to opt in. Create a radio select on your CF7 form with the options 'yes', 'no'. Name it 'opt-in', or change the variable below to match your form.

	*/
if(isset($_POST['opt-in']) &&
$_POST['opt-in'] == 'yes')
{
add_action('wpcf7_mail_sent', 'wysija_contactform7_subscribe', 1);
}

http://wordpress.org/extend/plugins/contact-form-7/


Viewing all articles
Browse latest Browse all 49500

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>