Recipe_Post_Rest_Api::update_actions_order( WP_REST_Request $request )

Function to update the menu_order of the actions


Parameters Parameters

$request

(Required)


Top ↑

Return Return

(WP_REST_Response)


Source Source

File: src/core/automator-post-types/uo-recipe/class-recipe-post-rest-api.php

	public function update_actions_order( WP_REST_Request $request ) {

		// Make sure we have a recipe ID and the newOrder
		if ( $request->has_param( 'recipeID' ) && $request->has_param( 'newOrder' ) ) {

			$recipe_id = absint( $request->get_param( 'recipeID' ) );
			$new_order = $request->get_param( 'newOrder' );

			// Update the actions menu_order here
			foreach ( $new_order as $index => $action_id ) {
				Automator()->db->action->update_menu_order( $action_id, ( $index + 1 ) * 10 );
			}

			$return['message'] = 'Updated!';
			$return['success'] = true;
			$return['action']  = 'update_actions_order';

			Automator()->cache->clear_automator_recipe_part_cache( $recipe_id );

			$return['recipes_object'] = Automator()->get_recipes_data( true, $recipe_id );

			return new WP_REST_Response( $return, 200 );

		}

		$return['message'] = 'Failed to update';
		$return['success'] = false;
		$return['action']  = 'show_error';

		return new WP_REST_Response( $return, 200 );
	}