Recipe_Post_Rest_Api::create( WP_REST_Request $request )
Create a recipe
Contents
Parameters Parameters
- $request
-
(Required)
Return Return
(WP_REST_Response)
Source Source
File: src/core/automator-post-types/uo-recipe/class-recipe-post-rest-api.php
public function create( WP_REST_Request $request ) { $return['success'] = false; $return['data'] = $request; $recipe_post = array( 'post_type' => 'uo-recipe', 'post_author' => get_current_user_id(), ); if ( $request->has_param( 'recipeTitle' ) ) { $recipe_post['title'] = wp_strip_all_tags( $request->get_param( 'recipeTitle' ) ); } $post_id = wp_insert_post( $recipe_post ); if ( is_wp_error( $post_id ) ) { $return['message'] = sprintf( '%s:%s', __( 'The action failed to create the post. The response was', 'uncanny-automator' ), $post_id ); return new WP_REST_Response( $return, 400 ); } $return = array(); $return['success'] = true; $return['post_ID'] = $post_id; $return['action'] = 'create'; $return['recipes_object'] = Automator()->get_recipes_data( true, $post_id ); return new WP_REST_Response( $return, 200 ); }
Expand full source code Collapse full source code View on Github