Skip to content

Instantly share code, notes, and snippets.

@jalbertbowden
Created July 25, 2019 19:10
Show Gist options
  • Select an option

  • Save jalbertbowden/f15a3610109e40ed8347dffade21e0e1 to your computer and use it in GitHub Desktop.

Select an option

Save jalbertbowden/f15a3610109e40ed8347dffade21e0e1 to your computer and use it in GitHub Desktop.
frank
function get_publisher( WP_REST_Request $request ) {
$publisher_id = null;
$params = $request->get_params();
if (isset($params['id'])) { // get the id parameter
$publisher_id = $params['id'];
};
// imagine code that gets the record from the database; assuming the code from the database returns $publisher
if ( empty( $publisher ) ) { // return a 404 response
return new WP_Error( 'page_does_not_exist', __('The page you are looking for does not exist'), array( 'status' => 404 ) );
};
return new WP_REST_Response( $publisher ); // return a normal response with the $publisher
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment