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.

so I've got a bunch of custom page templates that are scripts that are meant to be run by cron to update various things on my wordpress site, there are not meant to be viewed by regular site users.

Note: I'm using "regular" cron jobs, not "wp-cron" jobs.

Q: Is there a way to block average joe from visting these pages but allow cron to still be able to execute the scripts contained in the pages ok?

Thanks!

-- UPDATE #1 --

What do the crons job pages do?

The scripts on the pages that are triggered by cron use shortcodes to trigger a plugin that crawls various pages (the list of URLs to crawl is in an array thats fed to a for loop that triggers the shortcode) and do wordpress things like create post, categories, tags, etc.

I'm creating a very niche search engine that crawls pages I tell it to then creates wordpress pages from the results.

$urls = array('http://url1.com', 'http://url2.com', 'http://url3.com'); 
## etc.. for each page to be crawled.

## crawl each url in the array

foreach ($url as $crawling) {
    do_shortcode('[shortcode]'); 

}
share|improve this question
1  
May I ask why you abuse pages as cron-scripts? I am pretty sure that the general approach isn't a good idea. Can you explain the use case a bit more in detail? –  kraftner May 28 at 14:11
    
Because I honestly dont know how else to do it. The scripts are dependant on wordpress functions to run, thats why I have them as wordpress pages. Id be more than happy to do it "the right way" if I knew what that was. –  user12920 May 28 at 20:58
    
Please go back one step and explain what your crons should do. –  kraftner May 28 at 21:45
    
Ok, I've updated the original post with info about what the crons do and the scripts that they run. –  user12920 May 28 at 22:33

2 Answers 2

You could use php_sapi_name().

See this demo lifted from the developer docs

<?php
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
    echo "Your are probably a human";
} else {
    echo "You are probably not a human";
}
?>

You could just apply this kind of conditional at the start of your script.

share|improve this answer
    
....or put the script above the root directory. –  Edd Smith Jun 2 at 10:23

You could limit specific pages by user roles i.e. Admins get access to all pages but editors and below can't access certain pages. There's a plugin that handles this called Role Scoper: http://wordpress.org/plugins/role-scoper/ or, if you prefer, there's a plugin free route explained in another answer: Hide pages depending on role.

share|improve this answer

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.