registry = $registry; $this->cache = $cache; } public function register() { add_action( 'rest_api_init', array( $this, 'routes' ) ); } public function routes() { register_rest_route( 'artbees-quick-view/v1', '/status', array( 'methods' => 'GET', 'callback' => array( $this, 'status' ), 'permission_callback' => array( $this, 'permission' ) ) ); register_rest_route( 'artbees-quick-view/v1', '/cache', array( 'methods' => 'DELETE', 'callback' => array( $this, 'clear_cache' ), 'permission_callback' => array( $this, 'permission' ) ) ); } public function permission( $request ) { $nonce = $request->get_header( 'X-WP-Nonce' ); return current_user_can( 'manage_woocommerce' ) && is_string( $nonce ) && wp_verify_nonce( $nonce, 'wp_rest' ); } public function status() { return rest_ensure_response( $this->registry->diagnostics() ); } public function clear_cache() { $this->cache->invalidate(); return rest_ensure_response( array( 'cleared' => true ) ); } }