| @@ -3,15 +3,68 @@ | ||
| 3 | 3 | namespace FlyWP; |
| 4 | 4 | |
| 5 | 5 | class Opcache { |
| 6 | 6 | |
| 7 | - public static function is_enabled() { | |
| 8 | - // Check if OPcache is enabled | |
| 9 | - if ( ! function_exists( 'opcache_get_status' ) ) { | |
| 7 | + /** | |
| 8 | + * Opcache constructor. | |
| 9 | + */ | |
| 10 | + public function clear() { | |
| 11 | + return opcache_reset(); | |
| 12 | + } | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * Check if opcache is available. | |
| 16 | + * | |
| 17 | + * @return bool | |
| 18 | + */ | |
| 19 | + public function has_opcache() { | |
| 20 | + return function_exists( 'opcache_get_status' ); | |
| 21 | + } | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Get opcache status. | |
| 25 | + * | |
| 26 | + * @return array | |
| 27 | + */ | |
| 28 | + public function get_status() { | |
| 29 | + return opcache_get_status(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Get opcache config. | |
| 34 | + * | |
| 35 | + * @return array | |
| 36 | + */ | |
| 37 | + public function get_config() { | |
| 38 | + return opcache_get_configuration(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * Check if opcache is enabled. | |
| 43 | + * | |
| 44 | + * @return bool | |
| 45 | + */ | |
| 46 | + public function enabled() { | |
| 47 | + if ( ! $this->has_opcache() ) { | |
| 10 | 48 | return false; |
| 11 | 49 | } |
| 12 | 50 | |
| 13 | - $status = opcache_get_status(); | |
| 51 | + $status = $this->get_status(); | |
| 14 | 52 | |
| 15 | - return $status['opcache_enabled'] === true; | |
| 53 | + return isset( $status['opcache_enabled'] ) && $status['opcache_enabled'] === true; | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Get OPcache purge URL. | |
| 58 | + * | |
| 59 | + * @return string | |
| 60 | + */ | |
| 61 | + public function purge_cache_url() { | |
| 62 | + return wp_nonce_url( | |
| 63 | + add_query_arg( | |
| 64 | + [ 'flywp-action' => 'purge-opcache' ], | |
| 65 | + admin_url( 'index.php?page=flywp' ), | |
| 66 | + ), | |
| 67 | + 'fly-opcache-purge' | |
| 68 | + ); | |
| 16 | 69 | } |
| 17 | 70 | } |