'POST', 'callback' => 'addifect_save_post_data', 'permission_callback' => 'addifect_load_post_permission_check', 'args' => array( 'id' => array( 'required' => true, 'type' => 'integer', 'sanitize_callback' => 'absint', ), 'title' => array( 'required' => false, 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ), 'data' => array( 'required' => false, 'type' => 'object', 'sanitize_callback' => 'addifect_recursive_sanitize_array', ), ), ) ); } ); /** * Save post data and title via REST API. * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or error object on failure. */ function addifect_save_post_data( WP_REST_Request $request ) { $post_id = (int) $request->get_param( 'id' ); $title = $request->get_param( 'title' ); $data = $request->get_param( 'data' ); if ( $post_id <= 0 ) { return new WP_Error( 'missing_post_id', 'Invalid or missing post ID', // Internal message, no __() needed. array( 'status' => 400 ) ); } // 1. Update Title if provided if ( ! empty( $title ) ) { wp_update_post( array( 'ID' => $post_id, 'post_title' => sanitize_text_field( $title ), ) ); } // 2. Update Design Meta (JSON/Object) if ( isset( $data ) ) { update_post_meta( $post_id, '_addifect_post_data', wp_slash( $data ) ); } // 3. Flag the post as managed by Addifect update_post_meta( $post_id, '_addifect_edited', '1' ); return new WP_REST_Response( array( 'last_edited_time' => time(), ), 200 ); }