@@ 466-490 (lines=25) @@ | ||
463 | * |
|
464 | * @return \WP_REST_Response |
|
465 | */ |
|
466 | public static function update_sync_settings( $request ) { |
|
467 | $args = $request->get_params(); |
|
468 | $sync_settings = Settings::get_settings(); |
|
469 | ||
470 | foreach ( $args as $key => $value ) { |
|
471 | if ( false !== $value ) { |
|
472 | if ( is_numeric( $value ) ) { |
|
473 | $value = (int) $value; |
|
474 | } |
|
475 | ||
476 | // special case for sending empty arrays - a string with value 'empty'. |
|
477 | if ( 'empty' === $value ) { |
|
478 | $value = array(); |
|
479 | } |
|
480 | ||
481 | $sync_settings[ $key ] = $value; |
|
482 | } |
|
483 | } |
|
484 | ||
485 | Settings::update_settings( $sync_settings ); |
|
486 | ||
487 | // re-fetch so we see what's really being stored. |
|
488 | return rest_ensure_response( Settings::get_settings() ); |
|
489 | } |
|
490 | ||
491 | /** |
|
492 | * Retrieve Sync Objects. |
|
493 | * |
@@ 158-182 (lines=25) @@ | ||
155 | ||
156 | // POST /sites/%s/sync/settings |
|
157 | class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
|
158 | protected function result() { |
|
159 | $args = $this->input(); |
|
160 | ||
161 | $sync_settings = Settings::get_settings(); |
|
162 | ||
163 | foreach ( $args as $key => $value ) { |
|
164 | if ( $value !== false ) { |
|
165 | if ( is_numeric( $value ) ) { |
|
166 | $value = (int) $value; |
|
167 | } |
|
168 | ||
169 | // special case for sending empty arrays - a string with value 'empty' |
|
170 | if ( $value === 'empty' ) { |
|
171 | $value = array(); |
|
172 | } |
|
173 | ||
174 | $sync_settings[ $key ] = $value; |
|
175 | } |
|
176 | } |
|
177 | ||
178 | Settings::update_settings( $sync_settings ); |
|
179 | ||
180 | // re-fetch so we see what's really being stored |
|
181 | return Settings::get_settings(); |
|
182 | } |
|
183 | } |
|
184 | ||
185 | // GET /sites/%s/sync/settings |