Receiving JSON POST data in PHP is a common scenario I come across when building custom WordPress API’s. If you’re working with JSON API’s powered by PHP you may find that $_POST
is not working with JSON, and you may be seeing a broken response of Array
or NULL
.
Processing $_POST data with application/javascript
headers
To receive a request with a content-type of application/javascript
in PHP you’ll need to use the following:
$data = json_decode( file_get_contents( 'php://input' ), true );
This is really for my own reference/editor integration, but hopefully it’s helpful to you as well!