From bc3f5ac62813c0e03861945d9b0f70203f74b372 Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Thu, 19 Oct 2023 01:52:37 +1100 Subject: [PATCH] On update settings from schema. --- includes/classes/REST/Features.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/includes/classes/REST/Features.php b/includes/classes/REST/Features.php index 3495207d6e..9f4a4d7d1f 100644 --- a/includes/classes/REST/Features.php +++ b/includes/classes/REST/Features.php @@ -105,7 +105,29 @@ public function check_permission() { * @return void */ public function update_settings( \WP_REST_Request $request ) { - $settings = $request->get_params(); + $settings = []; + + $features = \ElasticPress\Features::factory()->registered_features; + + foreach ( $features as $slug => $feature ) { + $param = $request->get_param( $slug ); + + if ( ! $param ) { + continue; + } + + $settings[ $slug ] = []; + + $schema = $feature->get_settings_schema(); + + foreach ( $schema as $schema ) { + $key = $schema['key']; + + if ( isset( $param[ $key ] ) ) { + $settings[ $slug ][ $key ] = $param[ $key ]; + } + } + } Utils\update_option( 'ep_feature_settings', $settings );