'GET', 'callback' => array( __CLASS__, 'get_execution_modes' ), 'permission_callback' => array( __CLASS__, 'check_permissions_read' ), ), array( 'methods' => 'PUT', 'callback' => array( __CLASS__, 'set_execution_mode' ), 'permission_callback' => array( __CLASS__, 'check_permissions_manage' ), 'args' => array( 'mode' => array( 'sanitize_callback' => 'sanitize_key' ), ), ), ) ); } /** * GET /content-structure/execution-modes * * `mode` is the plugin-wide content mode; `modes` repeats it per * generator so a reader that still looks one generator up keeps working. * * @return WP_REST_Response */ public static function get_execution_modes(): WP_REST_Response { return self::success( self::state() ); } /** * PUT /content-structure/execution-modes * * Sets the one content mode every generator follows. Saved on its own, * never merged into a whole-settings save, so an open Settings tab * cannot overwrite a mode change made elsewhere. * * @param WP_REST_Request $request Request object. * @return WP_REST_Response|WP_Error */ public static function set_execution_mode( WP_REST_Request $request ) { $mode = (string) $request->get_param( 'mode' ); if ( ! in_array( $mode, array( ExecutionModeRegistry::BLUEPRINT, ExecutionModeRegistry::ADVANCED ), true ) ) { return self::error( 'aipt_blueprint_invalid_execution_mode', __( 'Unknown execution mode.', 'ai-product-tools' ), 400 ); } if ( ! ExecutionModeRegistry::setGlobal( $mode ) ) { return self::error( 'aipt_blueprint_execution_mode_save_failed', __( 'The execution mode could not be saved.', 'ai-product-tools' ), 500 ); } return self::success( self::state() ); } /** * The response body both routes return. * * @return array{mode:string,modes:array} */ private static function state(): array { return array( 'mode' => ExecutionModeRegistry::globalMode(), 'modes' => ExecutionModeRegistry::all(), ); } }