Support » Plugin: upPrev » Cookies?

  • Hi,

    This looks like a nice one of these gadgets.

    Would be even nicer if we could set cookies though.. πŸ™‚

    I am going to try doing so anyway I think, using this:

    https://github.com/carhartl/jquery-cookie

    What do you think? Something to add to the features list for a future release?

    One of the irritating things with these little pop-ins, is that unless they can be switched off by the user, they can end up having the opposite effect to the desired one.

    Something like the well known Foobar has a cookie option, but haven’t managed to find one like upprev out the box with this.

    Thanks for reading, and thanks for creating the plugin too πŸ™‚

    https://wordpress.org/plugins/upprev/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter gecko_guy

    (@gecko_guy)

    This might work:

    // Add script in footer for trigger close button click and call ajax function
    
    add_action('wp_footer', '__script_upprev_close_click', 100);
    
    function __script_upprev_close_click() {
    
    ?>
    
    <script type="text/javascript">
    
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
    
    </script>
    
    <?php
    
    	echo '<script type="text/javascript">
    
    jQuery( document ).ready(function() {
    
        jQuery("#upprev_close").click(function(){
    
    		jQuery.post(
    
    			ajaxurl, 
    
    			{
    
    				"action": "__callback_close_click",
    
    				"data":   "hideit"
    
    			}, 
    
    			function(response){
    
    				jQuery("#upprev_box").remove();
    			}
    		);
    	});
    });
    
    </script>';
    
    }
    
    // Reading ajax call, and set cookie
    
    add_action( 'wp_ajax___callback_close_click', '__upprev_set_cookie' );
    
    add_action( 'wp_ajax_nopriv___callback_close_click', '__upprev_set_cookie' );
    
    function __upprev_set_cookie() {
    
    	if($_POST['data'] && $_POST['data'] == 'hideit')
    
    	{
    
    		if (!isset($_COOKIE['hide_upprev'])) {
    
    			setcookie("hide_upprev", 'true', time()+3600, COOKIEPATH, COOKIE_DOMAIN);
    
    		}
    
    	}
    
    	die();
    
    }
    
    // Hide upPrev  Box if cookie is set
    
    add_action('init', '__hide_iworks_upprev_box',100);
    
    function __hide_iworks_upprev_box()
    
    {
    
    	if (!empty($_COOKIE['hide_upprev']) && $_COOKIE['hide_upprev'] == 'true') {
    
    		add_filter( 'iworks_upprev_box', '__callback__iworks_upprev_box' );
    
    	}
    
    }
    
    function __callback__iworks_upprev_box()
    
    {
    
       	return '';
    
    }

    Plugin Author Marcin Pietrzak

    (@iworks)

    Dear gecko_guy

    Good idea. I added this to ToDo list.

    Cheers,
    Marcin

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cookies?’ is closed to new replies.