false, 'message' => 'OPcache extension not available' ); } $st = @opcache_get_status( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors if ( ! is_array( $st ) ) { return array( 'enabled' => false, 'message' => 'OPcache disabled or restricted' ); } return array( 'enabled' => ! empty( $st['opcache_enabled'] ), 'memory_usage' => isset( $st['memory_usage'] ) ? $st['memory_usage'] : array(), 'statistics' => isset( $st['opcache_statistics'] ) ? $st['opcache_statistics'] : array(), ); } /** * @return bool */ public static function reset() { if ( function_exists( 'opcache_reset' ) ) { return (bool) @opcache_reset(); // phpcs:ignore WordPress.PHP.NoSilencedErrors } return false; } public function flush() { check_admin_referer( 'qwsc_opcache_flush' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized', 'qw-optimize' ), '', array( 'response' => 403 ) ); } $ok = self::reset(); wp_safe_redirect( add_query_arg( array( 'page' => 'qw-speed-cache-tools', 'opcache_flush' => $ok ? '1' : '0', ), admin_url( 'admin.php' ) ) ); exit; } }