settings = $settings; } /** * Log. * * @param string $message Plain-text message. * @return void */ public function log( $message ) { $log = $this->get_log(); $log[] = array( 'time' => time(), 'message' => sanitize_text_field( $message ), ); update_option( self::LOG_OPTION, array_slice( $log, -self::MAX_ENTRIES ), false ); } /** * Get log. * * @return array */ public function get_log() { $log = get_option( self::LOG_OPTION, array() ); return is_array( $log ) ? $log : array(); } /** * Clear log. * * @return void */ public function clear_log() { delete_option( self::LOG_OPTION ); } /** * Environment. * * @return array Safe environment summary. */ public function environment() { return array( 'QuicklyFly' => QUICKLYFLY_VERSION, 'WordPress' => get_bloginfo( 'version' ), 'PHP' => PHP_VERSION, 'Home URL' => home_url(), ); } /** * Checks for conditions that stop ajax navigation from working. * * @return array[] Each item: id, status (ok|warn|info), label, message. */ public function health_checks() { $checks = array(); $home = wp_parse_url( home_url() ); $site = wp_parse_url( site_url() ); $same_host = isset( $home['host'], $site['host'] ) && strtolower( $home['host'] ) === strtolower( $site['host'] ); $checks[] = array( 'id' => 'hosts', 'status' => $same_host ? 'ok' : 'warn', 'label' => __( 'Site address matches WordPress address', 'quicklyfly' ), 'message' => $same_host ? __( 'Links on your pages stay on the same host, so they can load instantly.', 'quicklyfly' ) : __( 'The Site Address and WordPress Address use different hosts. Links to the other host load normally.', 'quicklyfly' ), ); $home_is_https = isset( $home['scheme'] ) && 'https' === $home['scheme']; $mixed = ( is_ssl() && ! $home_is_https ); $checks[] = array( 'id' => 'https', 'status' => $mixed ? 'warn' : 'ok', 'label' => __( 'Consistent HTTPS', 'quicklyfly' ), 'message' => $mixed ? __( 'This request used HTTPS but the Site Address uses HTTP. Update the Site Address in Settings, General so links stay eligible.', 'quicklyfly' ) : __( 'The protocol of your site address matches how visitors reach it.', 'quicklyfly' ), ); $caches = $this->detected_cache_plugins(); $checks[] = array( 'id' => 'cache', 'status' => 'info', 'label' => __( 'Page caching', 'quicklyfly' ), 'message' => $caches ? sprintf( /* translators: %s: comma separated plugin names. */ __( 'Detected: %s. QuicklyFly works with page caches. Clear the cache after changing settings.', 'quicklyfly' ), implode( ', ', $caches ) ) : __( 'No page cache plugin detected.', 'quicklyfly' ), ); $php_ok = version_compare( PHP_VERSION, QUICKLYFLY_MIN_PHP, '>=' ); $checks[] = array( 'id' => 'php', 'status' => $php_ok ? 'ok' : 'warn', 'label' => __( 'PHP version', 'quicklyfly' ), 'message' => sprintf( /* translators: %s: PHP version. */ __( 'Running PHP %s.', 'quicklyfly' ), PHP_VERSION ), ); return $checks; } /** * Detected cache plugins. * * @return string[] Names of known caching plugins that are active. */ private function detected_cache_plugins() { $known = array( 'WP Rocket' => defined( 'WP_ROCKET_VERSION' ), 'LiteSpeed Cache' => defined( 'LSCWP_V' ), 'W3 Total Cache' => defined( 'W3TC' ), 'WP Super Cache' => defined( 'WPCACHEHOME' ), 'WP Fastest Cache' => defined( 'WPFC_MAIN_PATH' ), 'SG Optimizer' => defined( 'SiteGround_Optimizer\VERSION' ), ); return array_keys( array_filter( $known ) ); } }