← All changes
|
includes/api/classes/class-api-handler-admin-options.php
+16
-5
2.10.1
→
3.2.1
View file →
| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | use JordanLeven\Plugins\ForceRefresh\Api\Api_Handler_Admin; |
| 11 | 11 | use JordanLeven\Plugins\ForceRefresh\Api\Interfaces\Api_Handler_Admin_Interface; |
| 12 | 12 | use JordanLeven\Plugins\ForceRefresh\Services\Options_Storage_Service; |
| 13 | +use JordanLeven\Plugins\ForceRefresh\Services\Versions_Storage_Service; | |
| 13 | 14 | |
| 14 | 15 | /** |
| 15 | 16 | * Main class controller. |
| 16 | 17 | */ |
| @@ -41,9 +42,9 @@ | ||
| 41 | 42 | self::ENDPOINT_VERSION, |
| 42 | 43 | array( |
| 43 | 44 | 'methods' => \WP_REST_Server::EDITABLE, |
| 44 | 45 | 'callback' => array( $this, 'save_options' ), |
| 45 | - 'permission_callback' => array( $this, 'user_is_able_to_admin_force_refresh' ), | |
| 46 | + 'permission_callback' => $this->get_admin_permission_callback(), | |
| 46 | 47 | ), |
| 47 | 48 | ); |
| 48 | 49 | } |
| 49 | 50 | |
| @@ -51,13 +52,14 @@ | ||
| 51 | 52 | * Method for saving options |
| 52 | 53 | * |
| 53 | 54 | * @param \WP_REST_Request $request The WP ReST request. |
| 54 | 55 | * |
| 55 | - * @return void | |
| 56 | + * @return \WP_REST_Response | |
| 56 | 57 | */ |
| 57 | - public function save_options( \WP_REST_Request $request ): void { | |
| 58 | + public function save_options( \WP_REST_Request $request ): \WP_REST_Response { | |
| 58 | 59 | $show_refresh_in_admin_bar = $request->get_param( 'show_refresh_in_admin_bar' ) ?? null; |
| 59 | 60 | $refresh_interval = $request->get_param( 'refresh_interval' ) ?? null; |
| 61 | + $use_static_file_polling = $request->get_param( 'use_static_file_polling' ) ?? null; | |
| 60 | 62 | |
| 61 | 63 | if ( null !== $show_refresh_in_admin_bar ) { |
| 62 | 64 | Options_Storage_Service::set_option_show_in_admin_bar( $show_refresh_in_admin_bar ); |
| 63 | 65 | } |
| @@ -65,10 +67,19 @@ | ||
| 65 | 67 | if ( null !== $refresh_interval ) { |
| 66 | 68 | Options_Storage_Service::set_option_refresh_interval( $refresh_interval ); |
| 67 | 69 | } |
| 68 | 70 | |
| 69 | - $this->return_api_response( | |
| 70 | - 201, | |
| 71 | + if ( null !== $use_static_file_polling ) { | |
| 72 | + $enabled = (bool) $use_static_file_polling; | |
| 73 | + Options_Storage_Service::set_use_static_file_polling( $enabled ); | |
| 74 | + | |
| 75 | + if ( $enabled ) { | |
| 76 | + Versions_Storage_Service::sync_version_file(); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + return $this->return_api_response( | |
| 81 | + \WP_Http::CREATED, | |
| 71 | 82 | 'You\'ve successfully updated options.', |
| 72 | 83 | ); |
| 73 | 84 | } |
| 74 | 85 | |