The admin-ajax.php file in Wordpress is sending back php code instead of the expected json format

How do I configure WordPress to return JSON on Nginx?

When making Ajax calls in my WordPress site, instead of receiving plain JSON, I see <?php JSON. Everything works fine on the site, except for admin-ajax calls.

Example of a regular call: https://i.stack.imgur.com/Xyz2m.png

Example of a file upload call: https://i.stack.imgur.com/DpJIl.png

Technical Information:

Wordpress 4.5
PHP 5.6.11-1ubuntu3.1 (fpm-fcgi)
Nginx version: nginx/1.9.3 (Ubuntu)

Header information:

Request URL:http://SERVER/wp-admin/admin-ajax.php
Request Method:POST <br/>
Status Code:200 OK <br/>
Remote Address:IP:80 <br/>
Response Headers <br/>
Access-Control-Allow-Credentials:true <br/>
Access-Control-Allow-Origin:http://SERVER <br/>
Cache-Control:no-cache, must-revalidate, max-age=0 <br/>
Connection:keep-alive <br/>
Content-Type:application/json; charset=UTF-8 <br/>
Date:Tue, 26 Apr 2016 06:44:17 GMT <br/>
Expires:Wed, 11 Jan 1984 05:00:00 GMT <br/>
Pragma:no-cache <br/>
Server:nginx/1.9.3 (Ubuntu) <br/>
Transfer-Encoding:chunked <br/>
X-Content-Type-Options:nosniff <br/>
X-Frame-Options:SAMEORIGIN <br/>
X-Robots-Tag:noindex <br/>
Request Headers <br/>
Accept:application/json, text/javascript, */*; q=0.01 <br/>
Accept-Encoding:gzip, deflate <br/>
Accept-Language:en-US,en;q=0.8,pl;q=0.6 <br/>
Connection:keep-alive <br/>
Content-Length:107 <br/>
Content-Type:application/x-www-form-urlencoded; charset=UTF-8 <br/>
Cookie:REDACTED ;) <br/>
Host:SERVER <br/>
Origin:http://SERVER <br/>
Referer:http://SERWER/wp-admin/media-new.php <br/>
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36 <br/>
X-Requested-With:XMLHttpRequest <br/>
Form Data <br/>
data[wp-auth-check]:true <br/>
interval:60 <br/>
_nonce:32b36eaa97 <br/>
action:heartbeat <br/>
screen_id:media <br/>
has_focus:false <br/>

Nginx Configuration:

location / {
    index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
}

Answer №1

To wrap up this discussion. The issue stemmed from the absence of COMMENTS in the functions.php file Once I included the following code snippet in functions.php, the problem was resolved.

<?php
/**
 * Twenty Fifteen functions and definitions
 *
 * Set up the theme and provides some helper functions, which are used in the
 * theme as custom template tags. Others are attached to action and filter
 * hooks in WordPress to change core functionality.
 *
 * When using a child theme you can override certain functions (those wrapped
 * in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before
 * the parent theme's file, so the child theme functions would be used.
 *
 * @link https://codex.wordpress.org/Theme_Development
 * @link https://codex.wordpress.org/Child_Themes
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are
 * instead attached to a filter or action hook.
 *
 * For more information on hooks, actions, and filters,
 * {@link https://codex.wordpress.org/Plugin_API}
 *
 * @package WordPress
 * @subpackage Twenty_Fifteen
 * @since Twenty Fifteen 1.0
 */

Answer №2

To ensure the security of your website, it is crucial to verify if your WordPress files have not been compromised. There may be unauthorized modifications made to the core WordPress files that are causing issues.

Consider performing a clean installation of the WordPress files and conduct a thorough check to see if the problem persists. Any alterations to WordPress should only be made within the theme folder or through plugins.

If the issue continues to persist, try disabling all plugins and then enable them one by one. It is possible that a particular plugin is causing conflicts and disrupting the functionality of your website.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on loading a JSON file in Play framework utilizing Scala

In my project, I am looking to retrieve a list of cities from a JSON file within one of my controllers. The intention is to then pass this information to a view for display. The location where I have stored the file is: app/assets/jsons/countriesToCities. ...

Discovering subtype relationships in JSON with TypeScript

Consider the scenario where there are parent and child typescript objects: class Parent { private parentField: string; } class Child extends Parent { private childField: string; } Suppose you receive a list of JSON objects for both types via a R ...

Encountering an [ERROR] IndexError when attempting to retrieve the InstanceId from the RunInstance cloudtrail json log within a lambda function

Encountering the [ERROR] IndexError: list index out of range in lambda when attempting to retrieve InstanceId from RunInstance cloudtrail json log: [ERROR] IndexError: list index out of range Traceback (most recent call last): Is there a solution for fetc ...

Mastering the Art of Defining JSON Information

I'm curious about how to obtain a single stream of data. Specifically, I want to retrieve the value for ModbusSerial.Port_1.COM.Power from the script. However, I'm unsure of how to write the code for that. I believe it is something similar to: js ...

Display Custom Form Fields Based on Radio Button Selection

Being a new user of Yii, I've been immersed in it for less than 2 months. Currently, my focus is on creating a registration form that initially displays only 2 radio buttons - one representing a Person and the other an Organization. Upon selecting eit ...

Application errors occur when unable to execute AsyncTask

I am facing an issue with my app related to the AsyncTask. The AsyncTask is implemented in the SplashScreenActivity.java file and is responsible for downloading data using JSON for the MainActivity while displaying the splash screen. However, if the intern ...

What could be causing UserAuthExtensions.PopulateFromMap(session, jwtPayload) to fail in properly deserializing escaped JSON values within ServiceStack.Auth?

Our goal is to extract the UserName from the ServiceStack session, but we're encountering an issue with the deserialization of backslashes in the UserName. The UserName follows this format 'domainname\username', and when serialized in a ...

Update JSON data in ng-blur event using AngularJS

Could you offer some guidance on how to push the content from a text box into JSON when I click outside of the box? Below is the code for my text box: <input type="text" name="treatmentCost" class="form-control" ng-model="addTemplate" /> And here i ...

Syntax error encountered: unexpected character '*'

Here is the code snippet I am currently working on: <?php function calculateCompoundInterest($principle, $rate, $time) { $ci = ($principle * (( (1 + $rate / 100) ** $time) - 1)); echo $ci; } ?> <?php echo calculateCompoundInterest ...

Electrify Transformation - cycle through nested lists to create a consolidated list

When it comes to iterating lists within a list and forming a single list with multiple objects, I am encountering some difficulties. While I can successfully iterate through the lists, I am facing issues regarding applying tags before iterating through eac ...

Enabling Moodle to Allow External Site Logins

Integrating Moodle into our site is a top priority. The new setup involves different servers with different sub-domains, but the same main domain. These servers are configured to communicate seamlessly with one another. Our goal is for users to experience ...

Challenges with asynchronous partial postback and data grid functionality

I'm struggling to enable partial postbacks (asynchronous) on an aspx datagrid control. Despite adding a script manager, an update panel, and a content template wrapper, the page continues to refresh when I select a data item and click add. <asp:Sc ...

What is the most efficient way to send multiple arrays by selecting checkboxes?

Currently, I am faced with a challenge where I have a selection of items from a list that need to be submitted in the form of three different arrays with distinct values to PHP. These arrays include: Device id, Client comment, and Manufacturer comment. < ...

Instructions for including a script and stylesheet exclusively on a single page of a website

I need to incorporate these two lines onto a single page of my website: <script src="//cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.js"></script> As well as <link href="//cdnjs.cloudflare.com/ajax/libs/OwlCa ...

Swift was unable to interpret the data

I am a beginner in using Swift and I am attempting to retrieve data from an API. The data is in JSON format, and here is a snippet of the data: { "photos": [ { "id": 424926, " ...

Utilizing Docker-Compose with PHP (using MySQLi) for seamless connection to MySQL database

Alright, here's the situation: I am utilizing Docker-Compose to set up 3 services - one for the platform, another for a MySQL database, and the third for PHPMyAdmin. I'm currently attempting to use mysqli to establish a connection to the databas ...

Transferring session data through AJAX in PHP

I'm currently developing an app using PhoneGap. However, PhoneGap only supports HTML, CSS, and JS, not PHP. This led me to the workaround of placing the PHP file on a remote server and using AJAX to call it via the server's URL. My issue now is ...

Obtain the data from the hyperlink destination

Having some trouble extracting a value from an href link to use in my database operations. Unfortunately, I couldn't retrieve the desired value. Displayed below is the code for a button: <a class="btn btn-info" href="scheduleSetTime.php?id=&apo ...

Exploring Laravel's recursive relationships feature and understanding the concept of returning $this

I am working on a navigation bar that contains industries with potentially unknown levels, including child industries. My goal is to create a recursive relationship to retrieve the top industry and display it as the main Category. The code snippet I attemp ...

Real-time web interface for automatically updating Python script

I have a straightforward Python script that continuously polls a serial device (specifically an Xbee module). The script runs in an endless while loop, and with each iteration through the loop, I want a web page to be updated. While many examples demonstra ...