| 
          <?php | 
        
        
           | 
          /*  | 
        
        
           | 
          Plugin Name:  Delete Cookies | 
        
        
           | 
          Plugin URI: https://rayflores.com/plugins/wp-delete-cookies/ | 
        
        
           | 
          Description: Delete those unwanted cookies from sticking to the computer of the users for so long! | 
        
        
           | 
          Version: 1.0 | 
        
        
           | 
          Author: Ray Flores | 
        
        
           | 
          Author URI: https://www.rayflores.com/ | 
        
        
           | 
          */ | 
        
        
           | 
          
 | 
        
        
           | 
          // Turn 10 days cookie to time = 10 seconds from login | 
        
        
           | 
          add_filter( 'post_password_expires', 'wp_turn_time_ten_seconds' ); | 
        
        
           | 
          function wp_turn_time_ten_seconds( $time ){ | 
        
        
           | 
          	return time() + 180; | 
        
        
           | 
          } | 
        
        
           | 
          
 | 
        
        
           | 
          add_action('wp','remove_ba_goal_cookie'); | 
        
        
           | 
          function remove_ba_goal_cookie(){ | 
        
        
           | 
          	// clear session | 
        
        
           | 
          		foreach ($_SESSION as $key => $value) | 
        
        
           | 
          		{ | 
        
        
           | 
          			// test if $key starts with 'goal_' | 
        
        
           | 
          			if (strpos($key, 'goal_') === 0) { | 
        
        
           | 
          				// it does! so delete it | 
        
        
           | 
          				unset($_SESSION[$key]); | 
        
        
           | 
          			} | 
        
        
           | 
          		} | 
        
        
           | 
          
 | 
        
        
           | 
          		// clear cookies | 
        
        
           | 
          		foreach ($_COOKIE as $key => $value) | 
        
        
           | 
          		{			 | 
        
        
           | 
          			// delete cookie if it starts with 'b_a_a_g_' | 
        
        
           | 
          			if (strpos($key, 'b_a_a_g_') === 0) { | 
        
        
           | 
          				unset($_COOKIE[$key]); | 
        
        
           | 
          				// set a new cookie with its expiration in the past  | 
        
        
           | 
          				// so it will be deleted on next page load | 
        
        
           | 
          				setcookie($key, '', time() + 10, '/'); | 
        
        
           | 
          			} | 
        
        
           | 
          		} | 
        
        
           | 
          } | 
        
        
           | 
          add_action('wp_footer','delete_user_meta_goal'); | 
        
        
           | 
          function delete_user_meta_goal(){ | 
        
        
           | 
          ?> | 
        
        
           | 
          	<style> | 
        
        
           | 
          	#gform_2 .gform_title { | 
        
        
           | 
          		display:none; | 
        
        
           | 
          	} | 
        
        
           | 
          	</style> | 
        
        
           | 
          <?php	 | 
        
        
           | 
          	 | 
        
        
           | 
          		// delete all goal completion post meta values for the current user | 
        
        
           | 
          		$browser_hash = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); | 
        
        
           | 
          		$meta_key = 'b_a_goal_complete_' . $browser_hash; | 
        
        
           | 
          		$args = array( | 
        
        
           | 
          			'post_type' => 'b_a_goal', | 
        
        
           | 
          			'posts_per_page' => -1, | 
        
        
           | 
          			'post_status' => 'any', | 
        
        
           | 
          			'meta_key' => $meta_key | 
        
        
           | 
          		); | 
        
        
           | 
          		$goals_completed = get_posts($args); | 
        
        
           | 
          		if ( !empty($goals_completed) && is_array($goals_completed) ) { | 
        
        
           | 
          			foreach($goals_completed as $goal) { | 
        
        
           | 
          				$goal_meta = get_post_meta($goal->ID,$meta_key, true); | 
        
        
           | 
          				if ( $goal_meta['ip'] === $_SERVER['REMOTE_ADDR'] ) { | 
        
        
           | 
          					//print_r($goal_meta['ip']); | 
        
        
           | 
          					delete_post_meta($goal->ID, $meta_key); | 
        
        
           | 
          				} | 
        
        
           | 
          			}			 | 
        
        
           | 
          		} | 
        
        
           | 
          		 | 
        
        
           | 
          }	 |