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 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

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Your add_action should be:

add_action( "parse_query", "checkaccess" );
share|improve this answer
    
ah! in quotes rather than calling a function directly, right? –  dama_do_bling Apr 30 '12 at 17:11
1  
@dama_do_bling correct, callbacks should be string-formatted. –  Milo Apr 30 '12 at 17:13
add comment

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.