Trim off outside whitespace from the comma delimited list.
$requested_fields = array_map( 'trim', $requested_fields );
// Always persist 'id', because it can be needed for add_additional_fields_to_object().
if ( in_array( 'id', $fields, true ) ) {
$requested_fields[] = 'id';
}
// Return the list of all requested fields which appear in the schema.
return array_reduce(
$requested_fields,
static function( $response_fields, $field ) use ( $fields ) {
if ( in_array( $field, $fields, true ) ) {
$response_fields[] = $field;
return $response_fields;
}
// Check for nested fields if $field is not a direct match.
$nested_fields = explode( '.', $field );
// A nested field is included so long as its top-level property
// is present in the schema.
if ( in_array( $nested_fields[0], $fields, true ) ) {
$response_fields[] = $field;
}
return $response_fields;
},
array()
);
}
/**
* Retrieves an array of endpoint arguments from the item schema for the controller.
*
* @since 4.7.0
*
* @param string $method Optional. HTTP method of the request. The arguments for `CREATABLE` requests are
* checked for required values and may fall-back to a given default, this is not done
* on `EDITABLE` requests. Default WP_REST_Server::CREATABLE.
* @return array Endpoint arguments.
*/
public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
return rest_get_endpoint_args_for_schema( $this->get_item_schema(), $method );
}
/**
* Sanitizes the slug value.
*
* @since 4.7.0
*
* @internal We can't use sanitize_title() directly, as the second
* parameter is the fallback title, which would end up being set to the
* request object.
*
* @see https://github.com/WP-API/WP-API/issues/1585
*
* @todo Remove this in favour of https://core.trac.wordpress.org/ticket/34659
*
* @param string $slug Slug value passed in request.
* @return string Sanitized value for the slug.
*/
public function sanitize_slug( $slug ) {
return sanitize_title( $slug );
}
}
Fatal error: Uncaught Error: Class 'WP_REST_Controller' not found in /home/mrfilame/public_html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:17
Stack trace:
#0 /home/mrfilame/public_html/wp-settings.php(256): require()
#1 /home/mrfilame/public_html/wp-config.php(96): require_once('/home/mrfilame/...')
#2 /home/mrfilame/public_html/wp-load.php(50): require_once('/home/mrfilame/...')
#3 /home/mrfilame/public_html/wp-blog-header.php(13): require_once('/home/mrfilame/...')
#4 /home/mrfilame/public_html/index.php(17): require('/home/mrfilame/...')
#5 {main}
thrown in /home/mrfilame/public_html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 17