Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
if (is_user_logged_in()){
    if(!isset($_COOKIE['alertuser'])){
        // set cookie
        $timer = time()+86400;
        setcookie('alertuser', '1' $timer);

        // show alert
        function load_alert(){
            wp_register_script('alert', get_template_directory_uri() . '/js/alert.js', array( 'jquery' ));
            wp_enqueue_script( 'alert');
        }
        add_action('admin_enqueue_scripts', 'load_alert');

    }
} else {
        $timer = time()-86400;
        setcookie('alertuser', '', $timer); // <-problem here
}

I'm trying to attach a js file only when a customer first logs in. Upon signing out the cookie should get deleted, but isn't. Why?

(Maybe this is more of a php question that WP specific, if so, sorry for posting it here.)

share|improve this question
    
Since you've solved this and verified that it wasn't WP specific, I'm going to close as off-topic. Nothing personal, but had this been open longer it would have been closed/migrated anyway. –  EAMann Apr 10 '12 at 18:37
add comment

closed as off topic by EAMann Apr 10 '12 at 18:37

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

looks like I needed add a path to my cookie. This fixed it:

$timer = time()+86400;
setcookie('alertuser', '1', $timer, '/');

and

$timer = time()-86400;
setcookie('alertuser', '', $timer, '/');
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.