<?php /** * Plugin Name: CS Modify REST Response * Description: Remove data from the REST response. * Author: Con Schneider * Author URI: https://conschneider.de/ * License: GPLv2 or later * Text Domain: voilamodify- * Version: 0.3 * Domain Path: /languages/ */ if ( ! defined( 'WPINC' ) ) { die; } function cs_rest_prepare_post( $data, $post, $request ) { $_data = $data->data; // get the data object of the REST response. Dump this to see which elements you can use for a control statement. $my_condition = $_data['category']; // We will remove posts from a certain category. if ( is_user_logged_in() ) { return $data; // Make sure only logged in users see JSON data. Optional. } if ( in_array( 'some_category', $my_condition) ) { $_data = []; // Remove all posts from the 'some_category' category. } $data->data = $_data; return $data; } add_filter( 'rest_prepare_post', 'cs_rest_prepare_post', 10, 3 );
WordPress Modify REST response
In