WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I recently updated my Better WP Security plugin (and may have changed some of the settings, don't remember exactly) and now I'm having a problem where it's blocking the legitimate requests one of my custom plugins uses. I send a request to my website using the file_get_contents() method in order to determine whether a certain URL exists or not. When Better WP Security is enabled, this method is incorrect. When I disable the plugin however, the method works correctly. Any ideas what setting in Better WP Security plugin is blocking this so I don't have to disable the entire plugin?

share|improve this question
This is a legitimate question. It can be answered with a best WP practices answer. – Brian Fegter Jan 7 '13 at 22:24

You shouldn't use file_get_contents() for remote requests. WordPress does the heavy lifting for you when determining what is compatible on your host.

Instead of file_get_contents() use the following to check for 404s:

$request = wp_remote_get($url);
$status = $request['response']['code'];
if($status === 404){
    //do something

You can also use wp_remote_retrieve_body($request) to get the contents of the request.

share|improve this answer
Perfect. Thanks! – tsbadorrek Jan 8 '13 at 15:31
On second thought, this is still causing some issues. My previous code was: function url_exists($url) { if(@file_get_contents($url,0,NULL,0,1)){return 1;}else{ return 0;} } The replacement code doesn't work for all URLs entered: function url_exists($url) { $request = wp_remote_get($url); $status = $request['response']['code']; if($status === 404){return 0;}else{ return 1;} } – tsbadorrek Jan 8 '13 at 16:12
The new code is returning true for 404'd items. – tsbadorrek Jan 8 '13 at 16:23
@tsbadorrek Try if($status == 404) instead of the stringent === – Brian Fegter Jan 8 '13 at 16:28
@tsbadorrek Any luck? – Brian Fegter Jan 9 '13 at 7:24

Your Answer


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.