> Argument schemas. */ public static function update_args(): array { return [ 'section' => [ 'type' => 'string', 'required' => false, 'default' => '', 'maxLength' => 64, 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ], 'data' => Controller::object_arg(), 'sections' => Controller::object_arg(), ]; } /** * Answers with every setting. * * @return array All settings. */ public function index(): array { return Options::all(); } /** * Saves one or more settings sections. * * @param WP_REST_Request $request The request. * @return array|WP_Error Keys `settings` and `flush_needed`, or a 400. */ public function update( WP_REST_Request $request ) { $sections = self::sections_from( $request ); if ( [] === $sections ) { return new WP_Error( 'acid_aeo_no_section', __( 'Send either a section and its data, or a sections object.', 'acid-aeo' ), [ 'status' => 400 ] ); } return Controller::save_sections( $sections ); } /** * The sections a save request is asking for, in either accepted form. * * @param WP_REST_Request $request The request. * @return array Section name => raw section data. */ private static function sections_from( WP_REST_Request $request ): array { $sections = $request->get_param( 'sections' ); $sections = is_array( $sections ) ? $sections : []; $section = (string) $request->get_param( 'section' ); if ( '' !== $section ) { $data = $request->get_param( 'data' ); $sections[ $section ] = is_array( $data ) ? $data : []; } return $sections; } }