Skip to content

Instantly share code, notes, and snippets.

@PaulGwamanda
Created February 13, 2017 08:46
Show Gist options
  • Save PaulGwamanda/a82c3c01b42a68b4e650fe6af896bd01 to your computer and use it in GitHub Desktop.
Save PaulGwamanda/a82c3c01b42a68b4e650fe6af896bd01 to your computer and use it in GitHub Desktop.
Remember Me Cookies for Ninja Forms + Mailchimp
<?php
/*
Plugin Name: Remember Me Cookies
Description: Remember Me Cookies for Ninja Forms + Mailchimp
Version: 1.0
*/
function ninja_forms_code()
{
//step 1
//Have cookie, have wp query on ID, populate form values
function get_cookies() {
global $wp_query;
$post_ID = $wp_query->post->ID;
if (!isset($_COOKIE['tradebase_lp'])) {
setcookie( "tradebase_lp", $post_ID, strtotime( '+10 days' ) ); /* expire in 10 days */
}
}
add_action( 'wp_head', 'ninja_forms_before_pre_process');
//step 2
// If remember me checked, save ID to cookie
if (form_value('remember_me') == 'yes') :
function remember_me_checked() {
global $wp_query;
$id = $post->ID;
setcookie('tradebase_lp' . $id); //set the cookie
}
add_action( 'ninja_forms_post_process', 'remember_me_checked' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment