| @@ -14,13 +14,17 @@ | ||
| 14 | 14 | * @var Settings |
| 15 | 15 | */ |
| 16 | 16 | private SettingsRoutes $settings_routes; |
| 17 | 17 | |
| 18 | + private CacheRoutes $cache_routes; | |
| 19 | + | |
| 18 | 20 | /** |
| 19 | 21 | * @param SettingsRoutes $settings_routes Settings route class. |
| 22 | + * @param CacheRoutes $cache_routes Cache route class. | |
| 20 | 23 | */ |
| 21 | - public function __construct( SettingsRoutes $settings_routes ) { | |
| 24 | + public function __construct( SettingsRoutes $settings_routes, CacheRoutes $cache_routes ) { | |
| 22 | 25 | $this->settings_routes = $settings_routes; |
| 26 | + $this->cache_routes = $cache_routes; | |
| 23 | 27 | } |
| 24 | 28 | |
| 25 | 29 | /** |
| 26 | 30 | * Init rest routes |
| @@ -36,8 +40,21 @@ | ||
| 36 | 40 | */ |
| 37 | 41 | public function register_routes() { |
| 38 | 42 | // Register Settings Rest API Routes. |
| 39 | 43 | $this->register_settings_routes(); |
| 44 | + $this->register_cache_routes(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + private function register_cache_routes(): void { | |
| 48 | + register_rest_route( | |
| 49 | + HOSTINGER_PLUGIN_REST_API_BASE, | |
| 50 | + 'clear-cache', | |
| 51 | + array( | |
| 52 | + 'methods' => \WP_REST_Server::DELETABLE, | |
| 53 | + 'callback' => array( $this->cache_routes, 'clear_cache' ), | |
| 54 | + 'permission_callback' => array( $this, 'permission_check' ), | |
| 55 | + ) | |
| 56 | + ); | |
| 40 | 57 | } |
| 41 | 58 | |
| 42 | 59 | /** |
| 43 | 60 | * |