Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Created April 28, 2022 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfmeier/9e80a6e03ef76c81e00f1ef9b2b4fe6e to your computer and use it in GitHub Desktop.
Save rfmeier/9e80a6e03ef76c81e00f1ef9b2b4fe6e to your computer and use it in GitHub Desktop.
Example response helper function
<?php
/**
* Create a WP_REST_Response that uses ACM response data formatting.
*
* @param bool $success Whether the response was successful or not.
* @param array $data The data for the response.
* @param int $status Optional http status code. Default 200.
* @param array $headers Optional http headers. Default empty array.
*
* @return \WP_REST_Response A WP_REST_Response object.
*/
function create_rest_response( bool $success, array $data, int $status = 200, array $headers = [] ): \WP_REST_Response {
$data = format_response_data( $success, $data );
return new \WP_REST_Response( $data, $status, $headers );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment