| 1 |
<?php |
| 2 |
|
| 3 |
namespace FlyWP\Api; |
| 4 |
|
| 5 |
use FlyWP\LiteSpeed; |
| 6 |
|
| 7 |
class Cache { |
| 8 |
|
| 9 |
/** |
| 10 |
* API constructor. |
| 11 |
*/ |
| 12 |
public function __construct() { |
| 13 |
flywp()->router->post( 'fastcgi-cache', [ $this, 'fastcgi_setting' ] ); |
| 14 |
flywp()->router->post( 'ls-cache', [ $this, 'lscache_setting' ] ); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Handle request. |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
public function handle_cache_setting( $args ) { |
| 23 |
if ( ! isset( $args['status'] ) ) { |
| 24 |
wp_send_json_error( |
| 25 |
[ |
| 26 |
'message' => 'Missing status.', |
| 27 |
] |
| 28 |
); |
| 29 |
} |
| 30 |
|
| 31 |
$enabled = isset( $args['status'] ) && $args['status'] === 'enabled' ? true : false; |
| 32 |
|
| 33 |
$settings = flywp()->fastcgi->settings(); |
| 34 |
$settings['enabled'] = $enabled; |
| 35 |
|
| 36 |
update_option( flywp()->fastcgi::SETTINGS_KEY, $settings ); |
| 37 |
|
| 38 |
wp_send_json_success( |
| 39 |
[ |
| 40 |
'message' => 'Updated successfully.', |
| 41 |
] |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Handle request. |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function lscache_setting( $args ) { |
| 51 |
if ( ! isset( $args['status'] ) ) { |
| 52 |
wp_send_json_error( |
| 53 |
[ |
| 54 |
'message' => 'Missing status.', |
| 55 |
] |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
$status = isset( $args['status'] ) && $args['status'] === 'enabled' ? '1' : '0'; |
| 60 |
|
| 61 |
update_option( LiteSpeed::OPTION_KEY, $status ); |
| 62 |
|
| 63 |
wp_send_json_success( |
| 64 |
[ |
| 65 |
'message' => 'Updated successfully.', |
| 66 |
] |
| 67 |
); |
| 68 |
} |
| 69 |
} |
| 70 |
|