开发者

How are these PHP function applied to a specific page in WordPress?

开发者 https://www.devze.com 2023-02-13 05:30 出处:网络
I\'m fairly new to PHP and trying to understand it practical ways. I\'m getting most of what\'s going on in the following code, with the help of htt开发者_运维技巧p://www.php.net and http://codex.wo

I'm fairly new to PHP and trying to understand it practical ways.

I'm getting most of what's going on in the following code, with the help of htt开发者_运维技巧p://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');


It's the if statement in the show_popup function.

It either returns $content (ie. does nothing) or outputs a form.

If the current post has a meta field called location that's not 0 characters long, and there's not a cookie matching that location, it will output the form.


Ah, it was the "location" custom field, https://wordpress.stackexchange.com/questions/10457/how-are-these-php-functions-applied-to-a-specific-page-in-wordpress. Thanks to https://wordpress.stackexchange.com/users/2487/bainternet for the answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消