isInstalled()) { $a2Plugin->install(); } else { // Perform any version-upgrade activities prior to activation (e.g. database changes) $a2Plugin->upgrade(); } // Add callbacks to hooks $a2Plugin->addActionsAndFilters(); // Register the Plugin Activation Hook register_activation_hook(__FILE__, [&$a2Plugin, 'activate']); // Register the Plugin Deactivation Hook register_deactivation_hook(__FILE__, [&$a2Plugin, 'deactivate']); } public function A2_Optimized_noticePhpVersionWrong() { echo '
' . __('Error: plugin "A2 Optimized" requires a newer version of PHP to be running.', 'a2-optimized') . '
' . __('Minimal version of PHP required: ', 'a2-optimized') . '' . A2OPT_MIN_PHP . '' . '
' . __('Your site is running PHP version: ', 'a2-optimized') . '' . phpversion() . '' . '
' . __(' To learn how to change the version of php running on your site') . ' ' . __('read this Knowledge Base Article') . '.' . '
'; } // add plugin upgrade notification public static function showUpgradeNotification($currentPluginMetadata) { // Notice Transient $upgrade_notices = get_transient('a2_opt_ug_notes'); if (!$upgrade_notices) { $response = wp_remote_get('https://wp-plugins.a2hosting.com/wp-json/wp/v2/update_notice?notice_plugin=2'); if (is_array($response)) { $upgrade_notices = []; $body = json_decode($response['body']); // use the content foreach ($body as $item) { $upgrade_notices[$item->title->rendered] = 'Version ' . $item->title->rendered . ': ' . strip_tags($item->content->rendered); } set_transient('a2_opt_ug_notes', $upgrade_notices, 3600 * 12); } else { return; } } foreach ($upgrade_notices as $ver => $notice) { if (version_compare($currentPluginMetadata['Version'], $ver) < 0) { echo '

Important Upgrade Notice:
'; echo esc_html($notice), '

'; break; } } } // Remove WooCommerce AJAX calls from homepage if user has selected public static function dequeue_woocommerce_cart_fragments() { if (is_front_page() && get_option('a2_wc_cart_fragments')) { wp_dequeue_script('wc-cart-fragments'); } } } if (get_option('a2_cache_enabled') == 1) { if (is_plugin_active('litespeed-cache/litespeed-cache.php')) { A2_Optimized_Cache_Disk::clean(); update_option('a2_cache_enabled', 0); } else { add_action('plugins_loaded', [ 'A2_Optimized_Cache', 'init' ]); } } register_deactivation_hook(__FILE__, [ 'A2_Optimized_Cache', 'on_deactivation' ]); register_uninstall_hook(__FILE__, [ 'A2_Optimized_Cache', 'on_uninstall' ]); $a2opt_class = new A2_Optimized(); add_action('in_plugin_update_message-a2-optimized-wp/a2-optimized.php', [ 'A2_Optimized','showUpgradeNotification'], 10, 2); add_action('wp_enqueue_scripts', ['A2_Optimized', 'dequeue_woocommerce_cart_fragments'], 11, 2); // load WP-CLI command if (defined('WP_CLI') && WP_CLI && class_exists('WP_CLI')) { require_once A2OPT_DIR . '/A2_Optimized_CLI.php'; }