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?

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • If you look at the response in the network tab of the browser developer tools you’ll see the error. – Jacob Peattie Mar 26 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 at 12:09
  • Please read this wordpress.stackexchange.com/questions/96554/… – bueltge Mar 26 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 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 2 days ago

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

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

  • 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 at 8:47

WordPress by default hide errors for ajax request call. This can be confirmed from the source file wp-includes/load.php#L353, 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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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