I am working on a website using Wordpress but all responses from admin-ajax.php have a php opening tag which throws errors.
Here is an example of a response when i try to search for a plugin in the "Add plugins" page of wordpress :
<?php{"success":true,"data":{"count":4399,"items":"<input type=\"hidden\" name= ... }}
It seems everytime ajax is used in the website, this problem shows up.
Edit:
I looked into my problem a bit more and here is what I found.
In the example I gave earlier, the file that makes the request is 'load-scripts.php'. But the problem happens with any ajax request made by wordpress. For example, when I try to add a new user with a form (using User Registration plugin), the file that makes the request is 'user-registration.min.js' and the response still have the php tag inside :
<?php{"success":false,"data":{"message":["Username already exists.","Email already exists."]}}
Edit 2:
I found a way to fix my problem. It is kind of a dirty fix but it works. As all my ajax responses had the php starting tag, I decided to filter all ajax responses and remove this tag.
I just added a small javascript code to do this.
// Fix php tag in ajax responses
(function($){
$.ajaxSetup({
dataFilter: function (response, type) {
response = response.replace('<?php', '');
return response;
}
});
})(jQuery);
As I said, kinda dirty but it works.