Created
April 28, 2022 17:46
-
-
Save rfmeier/9e80a6e03ef76c81e00f1ef9b2b4fe6e to your computer and use it in GitHub Desktop.
Example response helper function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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