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.

I'm getting most of what's going on in the following code, with some help from http://www.php.net and http://codex.wordpress.org/Function_Reference/.

In its current situation, only one page on the site triggers the popup form if no cookie is set. Is that functionality specified within this code?

Here's the functions:

if (isset($_POST['confirm']) && isset($_POST['location'])) { 
    setcookie("Location", $_POST['location'], time()+3600);     
}
elseif (!isset($_COOKIE["Location"])) {
    setcookie("Location", "", 1);
}
elseif (isset($_POST['deny'])) {
    setcookie("Location", "", 1);
}

// Popup confirmation 
function show_popup($content) {
    global $post;
    $location = get_post_meta($post->ID, 'location', TRUE);
    if (strtolower($l) == strtolower($location) || strlen($location) == 0   
    || (isset($_COOKIE["Location"]) && strtolower($_COOKIE["Location"])  
    == strtolower($location))) {
        return $content;
    } else {
        ?>
        <div id="popup">
    <p>Foo.</p>
    <p>Yes/No?</p>
    <form action="<?php echo $PHP_SELF ?>" method="post">
    <input type="hidden" name="location" value="<?php echo $location; ?>" />
    <input type="submit" name="confirm" value="Yes" />
    <input type="submit" name="deny" value="No" />
    </form>
    </div>
        <?php
    }
}
add_filter('the_content', 'show_popup');

// Adds content to the <head> tag
function add_meta_content() {
if(isset($_POST['deny'])) {
?>
<meta http-equiv="refresh" content="0;url=<?php bloginfo ('wpurl') ?>">
<?php
}
if(isset($_POST['confirm'])) {
?>
<meta http-equiv="refresh" content="0;url=<?php echo $PHP_SELF; ?>">
<?php
}

}
add_action('wp_head', 'add_meta_content');
share|improve this question

1 Answer 1

make sure that the post as a customfield named 'location' and the page you are viewing is using the_content() or if you want this to work on categories and archives then add:

add_filter('the_excerpt', 'show_popup');

hope this helps

share|improve this answer
    
That's exactly it! Thanks, Bainternet. –  dooley Feb 25 '11 at 22:33
    
glad i could help –  Bainternet Feb 25 '11 at 22:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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