WP_REST_Server::READABLE, 'callback' => array( __CLASS__, 'get_item' ), 'permission_callback' => array( __CLASS__, 'permissions_check' ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( __CLASS__, 'update_item' ), 'permission_callback' => array( __CLASS__, 'permissions_check' ), ), ) ); } /** * Only administrators can read or change the site's schema settings. * * @return bool */ public static function permissions_check() { return current_user_can( 'manage_options' ); } /** * GET: the editing payload (stored overrides plus placeholder defaults). * * @return \WP_REST_Response */ public static function get_item() { return rest_ensure_response( Schema_Settings::get_editable() ); } /** * POST/PUT: sanitize and persist the submission, then return the new payload. * Unknown keys are ignored and omitted schema sections retain their stored values. * * @param WP_REST_Request $request The REST request. * @return \WP_REST_Response */ public static function update_item( WP_REST_Request $request ) { $params = $request->get_json_params(); if ( ! is_array( $params ) ) { $params = $request->get_params(); } return rest_ensure_response( Schema_Settings::update( $params ) ); } }