I'm facing a weird issue with a Wordpress installation and I'm not sure how to proceed further. I've developed a simple api only available for logged in user, it just prints a custom post type associated with the user. Example:
function get_return_request_detail() {
$returnRequestId = ( isset( $_POST['return_request_id'] ) ) ? $_POST['return_request_id'] : '';
if( empty( $returnRequestId ) ) {
echo json_encode("missing parameter");
exit;
}
$results = get_post_meta($returnRequestId);
$meta = unserialize($results["_meta"][0]);
if($results["_field_user_id"][0] == get_current_user_id()) {
... logic ...
echo json_encode($data);
} else {
echo json_encode("unauthorized");
}
exit;
}
add_action('wp_ajax_get_return_request_detail', 'get_return_request_detail');
The api works fine and I retrieve the data correctly. The problem is that as soon as I switch to another page I start receiving a 500 error:
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
I've tried enabling both debug and debug_log but I still receive the same message with nothing being written in the log. To enable it I've just added in the wp-config.php
:
define('WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
The weird behaviour is that, in order to make the page work again, I just need to visit an Admin page and the error disappears. My questions are:
- Is there any way to have a more detailed error log for this issue?
- Do you have any idea on what could be possibly causing it? Something related to admin-ajax?
What I've tried so far, with no results:
- Check Wordpress core file permission;
- Replace core files with a fresh installation;
- Followed this answer in order to enable error logging for admin-ajax.php (no results);
- Disable caching / security plugins;
- Disable Server Side caching (Dynamic Cache & Memcached);
- Check error logs on Server (the error produces no log);
Thanks