1

I'm running a WordPress install and was having issues with ajax-loads. Whenever I used the admin-ajax.php script, it wasn't returning anything so I decided to go to the source and see what the issue is.

It turns out that when I access the /wp-admin/admin-ajax.php file directly, it returns a 0 in the browser. I emptied the file, saved it and then tried to access it directly and it still returned a 0. I know I'm on the correct server in the correct directory as I created test files in the same DIR.

Does anyone know why this would be happening? A blank php file (with 644 permissions, and the correct owner/group) returning a 0 when navigating to it directly?

EDIT: I have highlighted a sentence above as people are skipping over that part. I have emptied the file, it still returns 0.

PavKR
  • 1,591
  • 2
  • 11
  • 26

1 Answers1

4

That file can't be accessed directly, it must be accessed through an Ajax call and you must pass in some action parameters, as in the line 28 there is a check:

// Require an action parameter
if ( empty( $_REQUEST['action'] ) )
    die( '0' );

Try upgrading your installation to the latest version and check that you file size is larger than 3.75K ... If you have no cache installed than you shouldn't get a 0 from a empty php file. Do you use caching like cloudflare ?

Regarding the returned 0, try the following code:

<?php
die('Hello');

it should return a simple Hello - on my side it works, at least :)

Codrut TG
  • 668
  • 7
  • 10
  • Thanks for your response however, as mentioned, I emptied the file and it was still returning a `0` – PavKR Mar 14 '17 at 23:36
  • I've updated the answer, but the idea is: you shouldn't get a 0 from an empty php file, rather than that you should have received an empty html document. Try clear the browser cache and cookies (related with your website) – Codrut TG Mar 14 '17 at 23:42
  • Yes I've done all that, hence the question - why would a blank PHP file return a `0`? Is this a server bug? – PavKR Mar 14 '17 at 23:43
  • Check your plugins and see if you're using any caching system - if so temporary disable them. there is certainly a cache of your file somewhere. To be sure is not a browser cache try opening the same page on a chrome "Incognito window" which will start a new session without using the cache and cookies. – Codrut TG Mar 14 '17 at 23:45
  • Put this content in your file and tell me what it returns: – Codrut TG Mar 14 '17 at 23:48
  • Ok, there are no caching plugins etc. I have cleared my browser cache, started incognito in chrome, added ` – PavKR Mar 14 '17 at 23:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/138067/discussion-between-codrut-tg-and-pavkr). – Codrut TG Mar 15 '17 at 00:01