We've got some custom endpoints set up that do various things, which we access via /wp/wp-admin/admin-ajax.php?action=some_action

However whenever there is an error as we're developing, such as syntax, logical, fatal etc, we simply get "500 Internal Server Error"

Every other page on the site when there's an error, it gives us the PHP error.

We have to then open our PHP Log file to see the error.

Is there something in wordpress that disables displaying of errors on these URLs? and if so, how can we prevent this to allow rendering of the errors on the browser?

  • If you look at the response in the network tab of the browser developer tools you’ll see the error. – Jacob Peattie Mar 26 '18 at 10:46
  • That's the whole problem - we just get a "500 internal server error" response - regardless of how we get there, even if you load the url directly in your browser – Owen Mar 26 '18 at 12:09
  • Please read this wordpress.stackexchange.com/questions/96554/… – bueltge Mar 26 '18 at 13:30
  • @bueltge Sorry I've read it, but do not understand what is relevant? I cannot see anywhere that they are discussing why error messages do not render? – Owen Mar 26 '18 at 14:21
  • Errors from ajax requests are never rendered in your browser directly. If error reporting is turned on you can see error messages in the network console. Bueltges link helps to debug that way. – Luckyfella Dec 14 '18 at 23:50

WordPress by default hide errors for ajax request call. This can be confirmed from the source file wp-includes/load.php#L352, here:

if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
    @ini_set( 'display_errors', 0 );

See the function wp_doing_ajax() is being used in the conditional statement thus the display_errors is being set.

To workaround this, you need to turn on error reporting manually at top of your ajax function call as suggested by @Friss.

| improve this answer | |
  • THANK YOU!!! I know obviously you never want to hack the core, but in a local environment only for troubleshooting purposes only, when the ajax is being called by a plugin you don't want to mess with or have to time to figure out - temporarily commenting out the line noted above in /wp-includes/load.php will allow the output of more specific error messages and let you track down where the problem is coming from. – squarecandy Sep 25 '19 at 19:58
  • 1
    There is a filter at the top of load.php that bypasses it: add_filter( 'enable_wp_debug_mode_checks', '__return_false' ); – Cragmonkey Apr 25 at 18:48
  • @Cragmonkey Please explain how one could use that hook on their ajax call. – Rahil Wazir May 10 at 1:58
  • @Rahil Wazir ... You would temporarily create that hook elsewhere in your plugin while debugging. – Cragmonkey May 11 at 22:36

You can try the WP_Ajax_Response

$response = array(
   'id'=>new WP_Error('oops','I had an accident.'),
   'data'=>'Whoops, there was a problem!'
$xmlResponse = new WP_Ajax_Response($response);

Read more https://codex.wordpress.org/Function_Reference/WP_Ajax_Response

| improve this answer | |
  • Sorry but this is not what we're asking for - our issue is that php errors are not displaying, when we need them to – Owen Mar 26 '18 at 12:10

You can try to add these two lines at the very top of tour script file

ini_set("display_errors", 1);

It tells php to report all kind of errors and overrides its default settings to display them.

| improve this answer | |
  • Hi, This does turn on error reporting - however, we're specifically trying to find out WHY it gets turned off for the admin-ajax.php as if we set it in the bottom of wp-config for example, it gets overwritten somewhere for the ajax calls – Owen Mar 27 '18 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.