'GET', 'callback' => 'addifect_get_post_data', 'permission_callback' => 'addifect_load_post_permission_check', 'args' => array( 'id' => array( 'type' => 'integer', 'required' => true, ), ), ) ); } ); /** * Load post design data via REST API. * * @param WP_REST_Request $request The request object. * @return WP_REST_Response The response object. */ function addifect_get_post_data( WP_REST_Request $request ) { $post_id = (int) $request->get_param( 'id' ); $post = get_post( $post_id ); if ( ! $post ) { return new WP_Error( 'post_not_found', 'Post not found', array( 'status' => 404 ) ); } // Fetch the primary design JSON. $addifect_post_data = get_post_meta( $post_id, '_addifect_post_data', true ); $addifect_design_post_data = ''; if ( 'addifect_design' !== $post->post_type ) { $design_data = get_option( 'addifect_active_connection' ); if ( $design_data && $design_data['design_id'] ) { $addifect_design_post_data = get_post_meta( (int) $design_data['design_id'], '_addifect_post_data', true ); } } return new WP_REST_Response( array( 'id' => $post_id, 'title' => esc_html( $post->post_title ), 'post_type' => sanitize_key( $post->post_type ), 'document_data' => $addifect_post_data, 'design_data' => $addifect_design_post_data, ), 200 ); }