Skip to content

Developer Docs

Evan Herman edited this page May 13, 2015 · 59 revisions

In Progress...

Filters

  1. yikes-mailchimp-form-title-FORM_ID
  2. yikes-mailchimp-form-description-FORM_ID
  3. yikes-mailchimp-redirect-timer
  4. yikes-mailchimp-before-submission
  5. yikes-mailchimp-before-submission-FORM_ID
  6. yikes-mailchimp-user-role-access

Actions

  1. yikes-mailchimp-menu
  2. yikes-mailchimp-after-submission
  3. yikes-mailchimp-after-submission-FORM_ID
  4. yikes-mailchimp-before-checkbox
  5. yikes-mailchimp-after-checkbox

Filters

1. yikes-mailchimp-form-title-FORM_ID

Description

This filter is executed when the specified MailChimp form is rendered on the front end of your site and can be used to alter the title of a given form.

Usage

Applies to a specific form.

apply_filters( 'yikes-mailchimp-form-title-'.$form_id , apply_filters( 'the_title' , $form_name ) );

Parameters

  • $form_title

The form title of the specified form to alter.

Examples

This example will alter the form title on the front end of your site, for the MailChimp form with id 1 only.

function alter_mailchimp_form_title( $form_title ) {
	$form_title = 'New Form Title';
	return $form_title;
}
add_action( 'yikes-mailchimp-form-title-1' , 'alter_mailchimp_form_title' );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in process_form_shortcode.php.


2. yikes-mailchimp-form-description-FORM_ID

Description

This filter is executed when the specified MailChimp form is rendered on the front end of your site and can be used to alter the description of a given form.

Usage

Applies to a specific form.

apply_filters( 'yikes-mailchimp-form-description-'.$form_id ,  $form_description );

Parameters

  • $form_description

The form description of the specified form to alter.

Examples

This example will alter the form description on the front end of your site, for the MailChimp form with id 1 only.

function alter_mailchimp_form_description( $form_description ) {
	$form_description = 'Please enter your email address and name below to sign up for our mailing list.';
	return $form_description;
}
add_action( 'yikes-mailchimp-form-description-1' , 'alter_mailchimp_form_description' );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in process_form_shortcode.php.


3. yikes-mailchimp-redirect-timer

Description

This filter is executed after a successful form submission, and is only fired off if a redirection is set on the form.

Usage

Applies to all forms, both ajax and non-ajax.

apply_filters( 'yikes-mailchimp-redirect-timer' ,  $redirect_time );

Parameters

  • $redirect_time (in milliseconds)

The amount of time before redirecting a user to the specified page (in milliseconds).

Examples

This example will increase the amount of time before a user is redirected from 1500ms (default - 1.5 seconds) to 3000ms (3 seconds), for all forms.

function increase_redirect_time( $redirect_time ) {
	$redirect_time = 3000; // must pass in milliseconds, not seconds (1s = 1000ms)
	return $redirect_time;
}
add_action( 'yikes-mailchimp-redirect-timer' , 'increase_redirect_time' );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in process_form_shortcode.php.


4. yikes-mailchimp-before-submission

Description

This filter is executed after a successful form submission, and is fired off right before the data is sent over to MailChimp. This filter can be used to dynamically populate any of the fields, visible or not, with user data or any other data you see fit.

Usage

Applies to all forms, both ajax and non-ajax.

apply_filters( 'yikes-mailchimp-before-submission' , $merge_variables );

Parameters

  • $user_data

An array of all of the user provided data when the form was submit, including interest groups. eg:

Array ( 
   [EMAIL] => [email protected] 
   [FNAME] => User First Name 
   [optin_time] => 2015-05-07 21:21:25 
)

Examples

This example will populate the first name field with the current users first name, only if they are logged in.

function populate_user_firstname( $user_data ) {
	if( is_user_logged_in() ) {
		get_currentuserinfo();
		$user_data['FNAME'] = $current_user->user_firstname;
	}
	return $user_data;
}
add_filter( 'yikes-mailchimp-before-submission' , 'populate_user_firstname' );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in process_form_submission.php & process_form_submission_ajax.php.


5. yikes-mailchimp-before-submission-FORM_ID

Description

This filter is executed after a successful form submission, and is fired off right before the data is sent over to MailChimp. This filter can be used to dynamically populate any of the fields, visible or not, with user data or any other data you see fit.

Usage

Applies to a specified form, both ajax and non-ajax.

apply_filters( 'yikes-mailchimp-before-submission-'.$form , $merge_variables );

Parameters

  • $user_data

An array of all of the user provided data when the form was submit, including interest groups. eg:

Array ( 
   [EMAIL] => [email protected] 
   [FNAME] => User First Name 
   [optin_time] => 2015-05-07 21:21:25 
)

after the filter below is executed, the result would then be (assuming the current logged in users first name is John):

Array ( 
   [EMAIL] => [email protected] 
   [FNAME] => John 
   [optin_time] => 2015-05-07 21:21:25 
)

Examples

This example will populate the first name field with the current users first name, only if they are logged in. This will only effect the form with id 1.

function populate_user_firstname( $user_data ) {
	if( is_user_logged_in() ) {
		get_currentuserinfo();
		$user_data['FNAME'] = $current_user->user_firstname;
	}
	return $user_data;
}
add_filter( 'yikes-mailchimp-before-submission-1' , 'populate_user_firstname' );

after the filter below is executed, the result would then be (assuming the current logged in users first name is John):

Array ( 
   [EMAIL] => [email protected] 
   [FNAME] => John 
   [optin_time] => 2015-05-07 21:21:25 
)

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in process_form_submission.php & process_form_submission_ajax.php


8. yikes-mailchimp-user-role-access

Description

This filter is allows you to alter who can access Easy MailChimp by Yikes Inc., by capability.

Usage

Alters who can access Easy MailChimp in the dashboard.

apply_filters( 'yikes-mailchimp-user-role-access' , 'manage_options' ), 

Parameters

  • $capability

The minimum capability required to access the dashboard page, edit forms, alter account info etc.

Examples

This example will allow editors and admins to access the Easy MailChimp menu item in the dashboard. (Because both user roles have the cabaility 'delete_others_pages'.

function alter_yikes_easy_mailchimp_access( $capability ) {
	$capability = 'delete_others_pages'; // allow editors & admins to access Easy MailChimp
	return $capability;
}
add_action( 'yikes-mailchimp-user-role-access' , 'alter_yikes_easy_mailchimp_access' );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in class-yikes-inc-easy-mailchimp-extender-admin.php & process_form_shortcode.php.


Actions

1. yikes-mailchimp-menu

Description

This filter enables you to nest new menu items inside of the parent 'Easy MailChimp' menu item in the dashboard.

Usage

Hook to generate a custom, user defined, menu item.

do_action( 'yikes-mailchimp-menu' ); 

Parameters

  • none

Examples

This example will generate a new menu item below 'Upgrade to Pro', nested inside of 'Easy MailChimp'. You'll need to setup pa callback to render some content in the new page, this is how to add the menu item.

function add_new_subpage_to_easy_mailchimp() {
		// Add a new menu just above 'Upgrade to Pro' (or to the end of the menu items if using pro)
		add_submenu_page(
			'yikes-inc-easy-mailchimp', // required, parent menu item slug
			__( 'New Page' , 'yikes-inc-easy-mailchimp-extender' ),
			__( 'New Page' , 'yikes-inc-easy-mailchimp-extender' ), 
			apply_filters( 'yikes-mailchimp-user-role-access' , 'manage_options' ),  // allows you to change who can access this page, should remain in place
			'yikes-inc-easy-mailchimp-new-page', // new page slug
			'generate_new_page' // callback to render our new page
		);		
}
add_action( 'yikes-mailchimp-menu' , 'add_new_subpage_to_easy_mailchimp' , 11 );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in class-yikes-inc-easy-mailchimp-extender-admin.php.


2. yikes-mailchimp-after-submission

Description

This filter is executed after a successful form submission, and is fired off directly after the data is successfully sent over to MailChimp. This filter can be used to store submitted user data in the database, used to create new users who any other appropriate functionality.

Usage

Applies to all forms.

do_action( 'yikes-mailchimp-after-submission' , $merge_variables );

Parameters

  • $user_data

An array of all of the user provided data when the form was submit, including interest groups. eg:

Array ( 
   [EMAIL] => [email protected] 
   [FNAME] => User First Name 
   [optin_time] => 2015-05-07 21:21:25 
)

Examples

This example will create a new subscriber user each time the form is filled out, as long as the username isn't already taken. The following function should be tightened up for production use, this is an example.

function create_user_on_mailchimp_submission( $user_data ) {
    $username = $user_data['FNAME'];
    $password = generateUserPassword();
    $email = $user_data['EMAIL'];

	if (username_exists( $username ) == null && email_exists( $email ) == false) {
            $user_id = wp_create_user( $username, $password, $email );
            $user = get_user_by( 'id', $user_id );
            $user->add_role( 'subscriber' );
	        // trigger registration email
	        wp_new_user_notification( $user_id, $password );
        }
}	
add_action( 'yikes-mailchimp-after-submission' , 'create_user_on_mailchimp_submission' );

and for anyone who would like to use the above function, you'll need the generateUserPassword(); function used above.

function generateUserPassword($length = 12) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in process_form_submission.php & process_form_submission_ajax.php


3. yikes-mailchimp-after-submission-FORM_ID

Description

This filter is executed after a successful form submission, and is fired off directly after the data is successfully sent over to MailChimp. This filter can be used to store submitted user data in the database, used to create new users who any other appropriate functionality.

Usage

Applies to a specified form.

do_action( 'yikes-mailchimp-after-submission-'.$form , $merge_variables );

Parameters

  • $user_data

An array of all of the user provided data when the form was submit, including interest groups. eg:

Array ( 
   [EMAIL] => [email protected] 
   [FNAME] => User First Name 
   [optin_time] => 2015-05-07 21:21:25 
)

Examples

This example will create a new subscriber user each time the form is filled out, as long as the username isn't already taken. The following function should be tightened up for production use, this is an example.

function create_user_on_mailchimp_submission( $user_data ) {
    $username = $user_data['FNAME'];
    $password = generateUserPassword();
    $email = $user_data['EMAIL'];

	if (username_exists( $username ) == null && email_exists( $email ) == false) {
            $user_id = wp_create_user( $username, $password, $email );
            $user = get_user_by( 'id', $user_id );
            $user->add_role( 'subscriber' );
	        // trigger registration email
	        wp_new_user_notification( $user_id, $password );
        }
}	
add_action( 'yikes-mailchimp-after-submission-1' , 'create_user_on_mailchimp_submission' );

and for anyone who would like to use the above function, you'll need the generateUserPassword(); function used above.

function generateUserPassword($length = 12) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in process_form_submission.php & process_form_submission_ajax.php.


4. yikes-mailchimp-before-checkbox

Description

This action is executed before the checkbox integration (comment form, registraion form, easy digital downloads, woocommerce etc.) is rendered on the page. This is useful to place any type of content before the checkbox.

Usage

Applies to all checkbox integrations.

do_action( 'yikes-mailchimp-before-checkbox' , $this->type )

Parameters

  • $this->type

The type of integration being rendered( ie. comment_form, registration_form, easy_digital_downloads etc)

Examples

This example will render out a small disclaimer before the checkbox is rendered on the page.

function content_for_checkboxes( $integration_type ) {
		echo '<p style="display:block;margin:.75em 0;">
					<em>
						<small>We will never sell or trade your personal info, this is for internal use only.</small>
					</em>
				</p>';	
}
// after the checkbox
add_filter( 'yikes-mailchimp-before-checkbox' , 'content_for_checkboxes' );

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in all of the checkbox integration class extensions found in, 'public/classes/checkbox-integrations/`.


5. yikes-mailchimp-after-checkbox

Description

This action is executed after the checkbox integration (comment form, registraion form, easy digital downloads, woocommerce etc.) is rendered on the page. This is useful to place any type of content after the checkbox.

Usage

Applies to all checkbox integrations.

do_action( 'yikes-mailchimp-before-checkbox' , $this->type )

Parameters

  • $this->type

The type of integration being rendered( ie. comment_form, registration_form, easy_digital_downloads etc)

Examples

This example will render out a small disclaimer before the checkbox is rendered on the page.

function content_for_checkboxes( $integration_type ) {
		echo '<p style="display:block;margin:.75em 0;">
					<em>
						<small>We will never sell or trade your personal info, this is for internal use only.</small>
					</em>
				</p>';	
}
// after the checkbox
add_filter( 'yikes-mailchimp-after-checkbox' , 'content_for_checkboxes' );

You can also target specific checkbox integrations. Say you only wanted to display the disclaimer to users who are going to be subscribed after leaving a comment, aka 'comment_form' integration, you could do something like the following:

function content_for_checkboxes( $integration_type ) {
	// comment form
	if( $integration_type == 'comment_form' ) {
		echo '<p>
					<em>We will never sell or trade your personal info, this is for internal use only.</em>
				</p>';
	}
}
// after the checkbox
add_filter( 'yikes-mailchimp-after-checkbox' , 'content_for_checkboxes' )

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in all of the checkbox integration class extensions found in, 'public/classes/checkbox-integrations/`.