| @@ -1,35 +1,25 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: BerqWP |
| 4 | - * Plugin URI: https://berqwp.com | |
| 5 | - * Description: Automatically pass Core Web Vitals for WordPress and boost your speed score to 90+ for both mobile and desktop without any technical skills. | |
| 6 | - * Version: 1.9.5 | |
| 4 | + * Plugin URI: https://berqwp.com/ | |
| 5 | + * Description: Automatically boost your WordPress website speed. Includes full-page caching, image optimization, CSS/JS delivery, and Core Web Vitals improvements. | |
| 6 | + * Version: 4.1.16 | |
| 7 | 7 | * Requires at least: 5.3 |
| 8 | 8 | * Requires PHP: 7.4 |
| 9 | 9 | * Author: BerqWP |
| 10 | - * Author URI: https://berqwp.com | |
| 10 | + * Author URI: https://berqwp.com/ | |
| 11 | 11 | * Text Domain: searchpro |
| 12 | 12 | * Domain Path: /languages |
| 13 | + * Network: true | |
| 14 | + * License: GPL-2.0-or-later | |
| 15 | + * License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
| 13 | 16 | */ |
| 14 | 17 | |
| 15 | 18 | if (!defined('ABSPATH')) exit; |
| 16 | 19 | |
| 17 | -if (class_exists('berqWP')) { | |
| 18 | - include_once(ABSPATH . 'wp-admin/includes/plugin.php'); | |
| 19 | - $free_plugin_path = 'berqwp-lite/berqwp-lite.php'; | |
| 20 | - if (is_plugin_active($free_plugin_path)) { | |
| 21 | - deactivate_plugins($free_plugin_path); | |
| 22 | - } | |
| 23 | - $free_plugin_path = 'berqwp/berqwp.php'; | |
| 24 | - if (is_plugin_active($free_plugin_path)) { | |
| 25 | - deactivate_plugins($free_plugin_path); | |
| 26 | - } | |
| 27 | - return; | |
| 28 | -} | |
| 29 | - | |
| 30 | 20 | if (!defined('BERQWP_VERSION')) { |
| 31 | - define('BERQWP_VERSION', '1.9.5'); | |
| 21 | + define('BERQWP_VERSION', '4.1.16'); | |
| 32 | 22 | } |
| 33 | 23 | |
| 34 | 24 | if (!defined('optifer_PATH')) { |
| 35 | 25 | define('optifer_PATH', plugin_dir_path(__FILE__)); |
| @@ -50,100 +40,122 @@ | ||
| 50 | 40 | if (!defined('BERQ_SECRET')) { |
| 51 | 41 | define('BERQ_SECRET', '64bc22f838e982.66069471'); |
| 52 | 42 | } |
| 53 | 43 | |
| 44 | +// define('BERQWP_DISABLE_CACHE_WARMUP', true); | |
| 54 | 45 | |
| 55 | -if (!defined('BERQWP_MAX_WARMUP_REQUESTS')) { | |
| 56 | - define('BERQWP_MAX_WARMUP_REQUESTS', 2); // The maximum number of requests in our rate limit window. | |
| 57 | -} | |
| 58 | - | |
| 59 | -if (!defined('BERQWP_WARMUP_RATE_LIMIT_WINDOW')) { | |
| 60 | - define('BERQWP_WARMUP_RATE_LIMIT_WINDOW', 125); // Time window for rate limit in seconds, i.e., 5 minutes. | |
| 61 | -} | |
| 62 | - | |
| 63 | 46 | if (!file_exists(optifer_cache)) { |
| 64 | 47 | mkdir(optifer_cache, 0755, true); |
| 65 | 48 | } |
| 66 | 49 | |
| 50 | +if (isset($_GET['disable_berqwp'])) { | |
| 51 | + return; | |
| 52 | +} | |
| 67 | 53 | |
| 68 | -// if (isset($_GET['generating_critical_css']) | |
| 69 | -// || isset($_GET['nocache']) | |
| 70 | -// || isset($_GET['creating_cache'])) { | |
| 54 | +global $bwp_current_page; | |
| 55 | +$bwp_current_page = null; | |
| 71 | 56 | |
| 72 | -// add_filter( 'berqwp_bypass_cache', function () { return true; } ); | |
| 57 | +// Initialize BerqWP SDK | |
| 58 | +require_once optifer_PATH . '/BerqWP/vendor-prefixed/vendor/scoper-autoload.php'; | |
| 59 | +// require_once optifer_PATH . '/BerqWP/src/Vendor/SimpleHtmlDom/simple_html_dom.php'; | |
| 73 | 60 | |
| 74 | -// if (berqReverseProxyCache::is_reverse_proxy_cache_enabled()) { | |
| 75 | -// berqReverseProxyCache::bypass(); | |
| 76 | -// } | |
| 77 | - | |
| 78 | -// if (!class_exists('HMWP_Models_Compatibility_Abstract')) { | |
| 79 | -// return; | |
| 80 | -// } | |
| 81 | -// } | |
| 82 | - | |
| 83 | - | |
| 84 | -// if (get_option('berqwp_enable_sandbox') == 1 && !isset($_GET['berqwp']) && !is_admin() && !isset($_POST)) { | |
| 85 | -// return; | |
| 86 | -// } | |
| 87 | - | |
| 88 | 61 | require_once optifer_PATH . '/inc/crawler/berqDetectCrawler.php'; |
| 89 | -require_once optifer_PATH . '/inc/class-berqreverseproxy.php'; | |
| 90 | -require_once optifer_PATH . '/inc/class-ignoreparams.php'; | |
| 91 | -require_once optifer_PATH . '/inc/class-MemoryLeakDetector.php'; | |
| 92 | -require_once optifer_PATH . '/vendor/autoload.php'; | |
| 93 | -require_once optifer_PATH . '/vendor/woocommerce/action-scheduler/action-scheduler.php'; | |
| 62 | +require_once optifer_PATH . '/inc/class-berqconfigs.php'; | |
| 63 | +require_once optifer_PATH . '/inc/class-berqdatabase.php'; | |
| 64 | +// require_once optifer_PATH . '/vendor/autoload.php'; | |
| 65 | +// require_once optifer_PATH . '/vendor/woocommerce/action-scheduler/action-scheduler.php'; | |
| 94 | 66 | require_once optifer_PATH . '/inc/class-berqlogs.php'; |
| 95 | 67 | require_once optifer_PATH . '/inc/helper-functions.php'; |
| 96 | -require_once optifer_PATH . '/inc/classs-http.php'; | |
| 68 | +require_once optifer_PATH . '/inc/common-functions.php'; | |
| 69 | +require_once optifer_PATH . '/inc/dropin-functions.php'; | |
| 70 | +require_once optifer_PATH . '/inc/photon/class-berqUsedCSS.php'; | |
| 97 | 71 | require_once optifer_PATH . '/inc/photon/class-berqPageOptimizer.php'; |
| 98 | -require_once optifer_PATH . '/inc/photon/class-berqBufferOptimize.php'; | |
| 99 | -require_once optifer_PATH . '/inc/photon/class-styleOptimizer.php'; | |
| 100 | -require_once optifer_PATH . '/inc/photon/class-scriptOptimizer.php'; | |
| 101 | -require_once optifer_PATH . '/inc/photon/class-berqImages.php'; | |
| 102 | -require_once optifer_PATH . '/inc/photon/class-berqCDN.php'; | |
| 103 | -require_once optifer_PATH . '/inc/photon/class-berqCriticalCSS.php'; | |
| 104 | -require_once optifer_PATH . '/inc/photon/integration/index.php'; | |
| 105 | -require_once optifer_PATH . '/inc/class-berqcache.php'; | |
| 72 | +require_once optifer_PATH . '/inc/class-berqintegrations.php'; | |
| 106 | 73 | require_once optifer_PATH . '/inc/class-berqwp.php'; |
| 107 | -require_once optifer_PATH . '/inc/class-berqimages.php'; | |
| 108 | -require_once optifer_PATH . '/inc/class-berqintegrations.php'; | |
| 109 | 74 | require_once optifer_PATH . '/inc/class-berqnotifications.php'; |
| 110 | 75 | |
| 76 | +// cache | |
| 77 | +require_once optifer_PATH . '/inc/cache/class-berqcache.php'; | |
| 78 | +require_once optifer_PATH . '/inc/cache/class-berqwarmup.php'; | |
| 79 | +require_once optifer_PATH . '/inc/cache/class-berqCloudflareAPIHandler.php'; | |
| 80 | +require_once optifer_PATH . '/inc/cache/class-berqreverseproxy.php'; | |
| 81 | +require_once optifer_PATH . '/inc/cache/class-ignoreparams.php'; | |
| 111 | 82 | |
| 83 | +// queue | |
| 84 | +require_once optifer_PATH . '/inc/queue/class-berqUpload.php'; | |
| 85 | +require_once optifer_PATH . '/inc/queue/class-berqHeartbeat.php'; | |
| 86 | + | |
| 87 | +// admin | |
| 88 | +require_once optifer_PATH . '/admin/class-berqPageRules.php'; | |
| 89 | +require_once optifer_PATH . '/admin/admin-bar.php'; | |
| 90 | + | |
| 91 | +if (get_option('berqwp_enable_sandbox') == 0) { | |
| 92 | + bwp_serve_advanced_cache(); | |
| 93 | +} | |
| 94 | +// register_shutdown_function('bwp_cache_current_page'); | |
| 95 | + | |
| 112 | 96 | // Redirect to BerqWP admin page after activation |
| 113 | 97 | register_activation_hook(__FILE__, 'berqwp_activation'); |
| 114 | 98 | register_deactivation_hook(__FILE__, 'berqwp_deactivate_plugin'); |
| 115 | 99 | |
| 116 | -function berqwp_activation() | |
| 100 | +function berqwp_activation($network_wide = false) | |
| 117 | 101 | { |
| 118 | - // Specify the drop-in file path | |
| 119 | - $dropin_file = ABSPATH . 'wp-content/advanced-cache.php'; | |
| 102 | + if (function_exists('is_multisite') && is_multisite() && $network_wide) { | |
| 103 | + // Network-wide activation: activate for each site | |
| 104 | + $sites = get_sites(['fields' => 'ids', 'number' => 0]); | |
| 105 | + foreach ($sites as $site_id) { | |
| 106 | + switch_to_blog($site_id); | |
| 107 | + berqwp_activate_single_site(); | |
| 108 | + restore_current_blog(); | |
| 109 | + } | |
| 110 | + } else { | |
| 111 | + berqwp_activate_single_site(); | |
| 112 | + } | |
| 120 | 113 | |
| 121 | - // Dynamically create the drop-in file | |
| 122 | - $dropin_content = file_get_contents(optifer_PATH . 'advanced-cache.php'); | |
| 114 | + // Install the advanced-cache.php drop-in (shared across network) | |
| 115 | + berqwp_install_dropin(); | |
| 116 | +} | |
| 123 | 117 | |
| 124 | - // Write the drop-in content to the file, replacing any existing file | |
| 125 | - file_put_contents($dropin_file, $dropin_content); | |
| 118 | +function berqwp_install_dropin() | |
| 119 | +{ | |
| 120 | + if (defined('BERQWP_ADVANCED_CACHE_PATH')) { | |
| 121 | + $dropin_file = BERQWP_ADVANCED_CACHE_PATH; | |
| 122 | + } else { | |
| 123 | + $dropin_file = WP_CONTENT_DIR . '/advanced-cache.php'; | |
| 124 | + } | |
| 126 | 125 | |
| 127 | - // Enable object cache in wp-config.php | |
| 128 | - berqwp_enable_object_cache(true); | |
| 126 | + if (!file_exists($dropin_file) || (file_exists($dropin_file) && is_writable($dropin_file))) { | |
| 127 | + $dropin_content = file_get_contents(optifer_PATH . 'advanced-cache.php'); | |
| 128 | + file_put_contents($dropin_file, $dropin_content); | |
| 129 | + berqwp_enable_advanced_cache(true); | |
| 130 | + } | |
| 131 | +} | |
| 129 | 132 | |
| 130 | - if (function_exists('wp_cache_flush')) { | |
| 131 | - wp_cache_flush(); // Clear the entire object cache. | |
| 133 | +function berqwp_deactivate_plugin($network_wide = false) { | |
| 134 | + | |
| 135 | + // Remove the shared drop-in | |
| 136 | + if (defined('BERQWP_ADVANCED_CACHE_PATH')) { | |
| 137 | + $dropin_file = BERQWP_ADVANCED_CACHE_PATH; | |
| 138 | + } else { | |
| 139 | + $dropin_file = WP_CONTENT_DIR . '/advanced-cache.php'; | |
| 132 | 140 | } |
| 133 | 141 | |
| 134 | - set_transient( 'bqwp_hide_feedback_notice', true, 60*60 ); // Hide for one hour | |
| 135 | - set_transient('berqwp_redirect', true, 1); | |
| 136 | -} | |
| 142 | + if (file_exists($dropin_file)) { | |
| 143 | + unlink($dropin_file); | |
| 144 | + } | |
| 137 | 145 | |
| 138 | -function berqwp_deactivate_plugin() { | |
| 139 | - // Specify the drop-in file path | |
| 140 | - $dropin_file = ABSPATH . 'wp-content/advanced-cache.php'; | |
| 146 | + berqwp_enable_advanced_cache(false); | |
| 141 | 147 | |
| 142 | - // Check if the drop-in file exists and delete it | |
| 143 | - if (file_exists($dropin_file)) { | |
| 144 | - unlink($dropin_file); | |
| 145 | - } | |
| 148 | + if (function_exists('is_multisite') && is_multisite() && $network_wide) { | |
| 149 | + $sites = get_sites(['fields' => 'ids', 'number' => 0]); | |
| 150 | + foreach ($sites as $site_id) { | |
| 151 | + switch_to_blog($site_id); | |
| 152 | + do_action('berqwp_deactivate_plugin'); | |
| 153 | + restore_current_blog(); | |
| 154 | + } | |
| 155 | + } else { | |
| 156 | + do_action('berqwp_deactivate_plugin'); | |
| 157 | + } | |
| 158 | +} | |
| 146 | 159 | |
| 147 | - // Disable object cache in wp-config.php | |
| 148 | - berqwp_enable_object_cache(false); | |
| 149 | -} | |
| 160 | +bwp_lock_cache_directory(); | |
| 161 | +bwp_serve_advanced_cache(); | |