add_actions called from functions.php not returning good values

I am trying to add some security/acccess prevention to my site via the functions.php. However whenever I try to add through functions.php (instead of as a plugin, which I’ve done in the past) it fails (always returns false). For example:

add_action("parse_query", checkaccess());  // in functions.php

and

Read More
function checkaccess() {
    $allowAccess = false;

    if(is_admin()||is_front_page()||is_home()||current_user_can('administrator'))
        $allowAccess=true;

    if($allowAccess)
        echo 'whatup'; //do something here

}

even if i try something basic – eg global $wp_query; var_dump($wp_query); I can’t get the query var, its all NULL. Any advice? Is there some kind of walled sandbox the fuctions.php file operates from that it can’t get any of these?

Related posts

Leave a Reply

1 comment