WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
    
You should avoid using $PHP_SELF, in the above code you will get the same effect by not specifying an action at all, or by specifying an empty acction on your form element – Tom J Nowell May 6 at 15:00

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
    
@dooley don't forget you can mark this as the correct answer :) – Tom J Nowell May 6 at 15:01

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.