'GET', 'callback' => array( __CLASS__, 'get_compare_notice' ), 'permission_callback' => array( __CLASS__, 'check_permissions_read' ), ), array( 'methods' => 'PUT', 'callback' => array( __CLASS__, 'set_compare_notice' ), 'permission_callback' => array( __CLASS__, 'check_permissions_manage' ), 'args' => array( 'generator' => array( 'sanitize_callback' => 'sanitize_key' ), 'state' => array( 'sanitize_callback' => 'sanitize_key' ), ), ), ) ); } /** * GET /content-structure/compare-notice * * @return WP_REST_Response */ public static function get_compare_notice(): WP_REST_Response { return self::success( array( 'states' => CompareNoticeRegistry::all() ) ); } /** * PUT /content-structure/compare-notice * * One generator per call, matching the execution-mode PUT's own * contract (`SettingsController::set_execution_mode()`): the request * body is never merged against a whole-settings save. Switching the * execution mode itself is a separate call the caller makes to the * existing execution-modes endpoint; this route only ever writes the * notice's own state. * * @param WP_REST_Request $request Request object. * @return WP_REST_Response|WP_Error */ public static function set_compare_notice( WP_REST_Request $request ) { $generator = (string) $request->get_param( 'generator' ); $state = (string) $request->get_param( 'state' ); if ( ! Generators::isValid( $generator ) ) { return self::error( 'aipt_blueprint_invalid_generator', __( 'Unknown content type.', 'ai-product-tools' ), 400 ); } if ( ! in_array( $state, CompareNoticeRegistry::WRITABLE_STATES, true ) ) { return self::error( 'aipt_blueprint_invalid_compare_notice_state', __( 'Unknown compare-notice state.', 'ai-product-tools' ), 400 ); } if ( ! CompareNoticeRegistry::set( $generator, $state ) ) { return self::error( 'aipt_blueprint_compare_notice_save_failed', __( 'The compare-notice state could not be saved.', 'ai-product-tools' ), 500 ); } return self::success( array( 'states' => CompareNoticeRegistry::all() ) ); } }