Created
July 25, 2019 19:10
-
-
Save jalbertbowden/f15a3610109e40ed8347dffade21e0e1 to your computer and use it in GitHub Desktop.
frank
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
| 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