Block Tracking and Detect WordPress Login


I made an update the other day to the detection script I use to block my tracking scripts.

I got tired of forcing ?preview=true onto URL's when I was searching my own site and I hated the idea of my personal hits from any machine being tracked. It's real easy for me to login to the WordPress admin and then know my hits aren't being tracked.

So I modified my is_preview_mode() function from the Block Content and Detect Wordpress Preview post and added in one of WordPress's built-in functions is_user_logged_in().

Here's the updated function. You just need to replace the old is_preview_mode() function and you'll be all set!

PHP

<?php
if(!function_exists('is_preview_mode')){
    function is_preview_mode(){
        if(is_user_logged_in()){
            $result = true;
        } else {
            $query = $_SERVER['QUERY_STRING'];
            $pattern = '/(((p=([0-9]*)&)?preview=true)|(p=([0-9]*)))/';
            $result = preg_match($pattern, $query);
        }
        return $result;
    }
}
?>

Popularity: 45% [?]


Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!