Changeset 3397254
- Timestamp:
- 11/17/2025 01:32:26 PM (3 months ago)
- Location:
- lws-optimize/trunk
- Files:
-
- 5 edited
-
Classes/Admin/LwsOptimizeManageAdmin.php (modified) (5 diffs)
-
Classes/FileCache/LwsOptimizeFileCache.php (modified) (1 diff)
-
Classes/LwsOptimize.php (modified) (14 diffs)
-
lws-optimize.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lws-optimize/trunk/Classes/Admin/LwsOptimizeManageAdmin.php
r3374142 r3397254 30 30 if (substr(get_current_screen()->id, 0, 29) == "toplevel_page_lws-op-config") { 31 31 remove_all_actions('admin_notices'); 32 if ( get_option('lws_optimize_deactivate_temporarily') && (is_plugin_active('wp-rocket/wp-rocket.php') || is_plugin_active('powered-cache/powered-cache.php') || is_plugin_active('wp-super-cache/wp-cache.php')32 if (!get_option('lws_optimize_deactivate_temporarily') && (is_plugin_active('wp-rocket/wp-rocket.php') || is_plugin_active('powered-cache/powered-cache.php') || is_plugin_active('wp-super-cache/wp-cache.php') 33 33 || is_plugin_active('wp-optimize/wp-optimize.php') || is_plugin_active('wp-fastest-cache/wpFastestCache.php') || is_plugin_active('w3-total-cache/w3-total-cache.php'))) { 34 34 $this->lws_optimize_warning_incompatibiliy(); … … 749 749 wp_unschedule_event(wp_next_scheduled("lws_optimize_start_filebased_preload"), "lws_optimize_start_filebased_preload"); 750 750 } 751 wp_schedule_event(time() , "lws_minute", "lws_optimize_start_filebased_preload");751 wp_schedule_event(time() + 60, "lws_minute", "lws_optimize_start_filebased_preload"); 752 752 } 753 753 } … … 755 755 756 756 // Clear cache when updating data 757 $this->lws_optimize_delete_directory(LWS_OP_UPLOADS, $this);758 $logger = fopen($this->log_file, 'a');759 fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . '] Removed cache after configuration change' . PHP_EOL);760 fclose($logger);761 762 $this->after_cache_purge_preload();757 // $this->lws_optimize_delete_directory(LWS_OP_UPLOADS, $this); 758 // $logger = fopen($this->log_file, 'a'); 759 // fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . '] Removed cache after configuration change' . PHP_EOL); 760 // fclose($logger); 761 762 // $this->after_cache_purge_preload(); 763 763 764 764 if (function_exists("opcache_reset")) { … … 1601 1601 $optimize_options['filebased_cache']['timer'] = $timer; 1602 1602 1603 $timer = $optimize_options['filebased_cache']['timer'] ?? "lws_yearly"; 1604 switch ($timer) { 1605 case 'lws_daily': 1606 $cdn_date = "86400"; 1607 break; 1608 case 'lws_weekly': 1609 $cdn_date = "604800"; 1610 break; 1611 case 'lws_monthly': 1612 $cdn_date = "2592000"; 1613 break; 1614 case 'lws_thrice_monthly': 1615 $cdn_date = "7776000"; 1616 break; 1617 case 'lws_biyearly': 1618 $cdn_date = "15552000"; 1619 break; 1620 case 'lws_yearly': 1621 $cdn_date = "31104000"; 1622 break; 1623 case 'lws_two_years': 1624 $cdn_date = "62208000"; 1625 break; 1626 case 'lws_never': 1627 $cdn_date = "93312000"; 1628 break; 1629 default: 1630 $cdn_date = "7776000"; 1631 break; 1632 } 1633 1634 1603 1635 // Update Cloudflare TTL to match filebased cache clear timer 1604 1636 $this->cloudflare_manager->lws_optimize_change_cloudflare_ttl($timer); … … 1613 1645 // Never start cron if timer is defined as zero (infinite) 1614 1646 if ($timer != 0) { 1615 wp_schedule_event(time() , $timer, 'lws_optimize_clear_filebased_cache_cron');1647 wp_schedule_event(time() + $cdn_date, $timer, 'lws_optimize_clear_filebased_cache_cron'); 1616 1648 } 1617 1649 -
lws-optimize/trunk/Classes/FileCache/LwsOptimizeFileCache.php
r3374948 r3397254 281 281 $modified = $data['html']; 282 282 283 var_dump($modified);284 285 283 $cached_elements['css']['file'] += $data['files']['file']; 286 284 $cached_elements['css']['size'] += $data['files']['size']; -
lws-optimize/trunk/Classes/LwsOptimize.php
r3374142 r3397254 295 295 } 296 296 297 $timer = $optimize_options['filebased_cache']['timer'] ?? "lws_yearly"; 298 switch ($timer) { 299 case 'lws_daily': 300 $cdn_date = "86400"; 301 break; 302 case 'lws_weekly': 303 $cdn_date = "604800"; 304 break; 305 case 'lws_monthly': 306 $cdn_date = "2592000"; 307 break; 308 case 'lws_thrice_monthly': 309 $cdn_date = "7776000"; 310 break; 311 case 'lws_biyearly': 312 $cdn_date = "15552000"; 313 break; 314 case 'lws_yearly': 315 $cdn_date = "31104000"; 316 break; 317 case 'lws_two_years': 318 $cdn_date = "62208000"; 319 break; 320 case 'lws_never': 321 $cdn_date = "93312000"; 322 break; 323 default: 324 $cdn_date = "7776000"; 325 break; 326 } 327 297 328 // Schedule the cache cleanout again if it has been deleted 298 329 // If the plugin is OFF or the filecached is deactivated, unregister the WPCron 299 330 if (isset($optimize_options['filebased_cache']['timer']) && !get_option('lws_optimize_deactivate_temporarily')) { 300 331 if (!wp_next_scheduled('lws_optimize_clear_filebased_cache_cron') && $optimize_options['filebased_cache']['timer'] != 0) { 301 wp_schedule_event(time() , $optimize_options['filebased_cache']['timer'], 'lws_optimize_clear_filebased_cache_cron');332 wp_schedule_event(time() + $cdn_date, $optimize_options['filebased_cache']['timer'], 'lws_optimize_clear_filebased_cache_cron'); 302 333 } 303 334 } elseif (get_option('lws_optimize_deactivate_temporarily') || $this->lwsop_check_option('filebased_cache')['state'] === "false") { … … 344 375 $this->lws_optimize_reset_header_htaccess(); 345 376 346 $this->lws_optimize_delete_directory(LWS_OP_UPLOADS, $this);347 $logger = fopen($this->log_file, 'a');348 fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . '] Removed cache after update' . PHP_EOL);349 fclose($logger);350 351 $this->after_cache_purge_preload();377 // $this->lws_optimize_delete_directory(LWS_OP_UPLOADS, $this); 378 // $logger = fopen($this->log_file, 'a'); 379 // fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . '] Removed cache after update' . PHP_EOL); 380 // fclose($logger); 381 382 // $this->after_cache_purge_preload(); 352 383 } 353 384 } … … 535 566 stream_context_set_default([ 536 567 'ssl' => [ 537 'verify_peer' => false,538 'verify_peer_name' => false,568 'verify_peer' => false, 569 'verify_peer_name' => false, 539 570 ], 540 571 ]); 541 572 542 // Check if sitemap exists 543 $headers = get_headers($sitemap); 544 if (substr($headers[0], 9, 3) == 404) { 573 // Check if sitemap exists and is valid XML 574 $headers = @get_headers($sitemap); 575 $is_valid = false; 576 577 if ($headers && is_array($headers) && isset($headers[0]) && intval(substr($headers[0], 9, 3)) === 200) { 578 // Check if it's actually XML by trying to load it 579 $sitemap_content = @file_get_contents($sitemap); 580 if ($sitemap_content !== false) { 581 libxml_use_internal_errors(true); 582 $xml = @simplexml_load_string($sitemap_content); 583 if ($xml !== false) { 584 $is_valid = true; 585 } 586 libxml_clear_errors(); 587 } 588 } 589 590 // Fall back to alternative sitemap if the first one is invalid 591 if (!$is_valid) { 545 592 $sitemap = home_url('/sitemap_index.xml'); 546 593 } … … 680 727 681 728 // If files exist and this is first run, count it as done 682 if (!empty($file_exists) && (!isset($userAgents['mobile']) || !empty($file_exists_mobile))) {729 if (!empty($file_exists) && !empty($file_exists_mobile)) { 683 730 if ($first_run) { 684 731 $done++; … … 688 735 689 736 // Fetch pages with appropriate user agents 690 foreach ($userAgents as $agent) { 691 // Ensure the nocache parameter is unique for each request 692 $unique_nocache = 'nocache=' . time() . '-' . mt_rand(1000, 9999); 693 $request_url = str_replace('nocache=' . time(), $unique_nocache, $url); 694 695 // Make the request with additional cache-busting headers 696 $response = wp_remote_get( 697 $request_url, 698 [ 699 'timeout' => 30, 700 'user-agent' => $agent, 701 'headers' => [ 702 'Cache-Control' => 'no-cache, no-store, must-revalidate', 703 'Pragma' => 'no-cache', 704 'Expires' => '0', 705 'X-LWS-Preload' => time(), // Additional unique header 706 'X-No-Cache' => '1' // Some servers recognize this 707 ], 708 'sslverify' => false, 709 'blocking' => true, 710 'cookies' => [], // Clean request with no cookies 711 'reject_unsafe_urls' => false, // Allow URLs with query strings 712 'redirection' => 3 // Don't follow too many redirects 713 ] 714 ); 737 foreach ($userAgents as $type => $agent) { 738 if ($type === 'mobile' && $file_exists_mobile) { 739 continue; // Skip if mobile cache already exists 740 } else if ($type === 'desktop' && $file_exists) { 741 continue; // Skip if desktop cache already exists 742 } 743 744 // Ensure the nocache parameter is unique for each request 745 $unique_nocache = 'nocache=' . time() . '-' . mt_rand(1000, 9999); 746 $request_url = str_replace('nocache=' . time(), $unique_nocache, $url); 747 748 // Make the request with additional cache-busting headers 749 $response = wp_remote_get( 750 $request_url, 751 [ 752 'timeout' => 30, 753 'user-agent' => $agent, 754 'headers' => [ 755 'Cache-Control' => 'no-cache, no-store, must-revalidate', 756 'Pragma' => 'no-cache', 757 'Expires' => '0', 758 'X-LWS-Preload' => time(), // Additional unique header 759 'X-No-Cache' => '1' // Some servers recognize this 760 ], 761 'sslverify' => false, 762 'blocking' => true, 763 'cookies' => [], // Clean request with no cookies 764 'reject_unsafe_urls' => false, // Allow URLs with query strings 765 'redirection' => 3 // Don't follow too many redirects 766 ] 767 ); 715 768 } 716 769 … … 1529 1582 $cache_dirs = array_merge([$cache_desktop => 'desktop specific'], $cache_dirs); 1530 1583 } else { 1531 fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . "] Directory $cache_desktop not found." . PHP_EOL);1584 fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . "] Directory for $directory not found. No cache to purge" . PHP_EOL); 1532 1585 } 1533 1586 … … 1536 1589 $cache_dirs = array_merge([$cache_mobile => 'mobile specific'], $cache_dirs); 1537 1590 } else { 1538 fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . "] Directory $cache_mobile not found." . PHP_EOL);1591 fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . "] Directory for $directory not found. No cache to purge" . PHP_EOL); 1539 1592 } 1540 1593 … … 1689 1742 public function after_cache_purge_preload() { 1690 1743 $logger = fopen($this->log_file, 'a'); 1744 fwrite($logger, '[' . gmdate('Y-m-d H:i:s') . "] Restarting preload process after cache purge..." . PHP_EOL); 1691 1745 1692 1746 // Handle preload configuration … … 2053 2107 2054 2108 wp_unschedule_event(wp_next_scheduled('lws_optimize_clear_filebased_cache_cron'), 'lws_optimize_clear_filebased_cache_cron'); 2055 wp_schedule_event(time() , 'lws_yearly', 'lws_optimize_clear_filebased_cache_cron');2109 wp_schedule_event(time() + YEAR_IN_SECONDS, 'lws_yearly', 'lws_optimize_clear_filebased_cache_cron'); 2056 2110 wp_unschedule_event(wp_next_scheduled('lws_optimize_maintenance_db_weekly'), 'lws_optimize_maintenance_db_weekly'); 2057 2111 … … 2064 2118 wp_unschedule_event(wp_next_scheduled('lws_optimize_start_filebased_preload'), 'lws_optimize_start_filebased_preload'); 2065 2119 } 2066 wp_schedule_event(time() , "lws_minute", "lws_optimize_start_filebased_preload");2120 wp_schedule_event(time() + 60, "lws_minute", "lws_optimize_start_filebased_preload"); 2067 2121 } 2068 2122 break; … … 2102 2156 2103 2157 wp_unschedule_event(wp_next_scheduled('lws_optimize_clear_filebased_cache_cron'), 'lws_optimize_clear_filebased_cache_cron'); 2104 wp_schedule_event(time() , 'lws_yearly', 'lws_optimize_clear_filebased_cache_cron');2158 wp_schedule_event(time() + YEAR_IN_SECONDS, 'lws_yearly', 'lws_optimize_clear_filebased_cache_cron'); 2105 2159 wp_unschedule_event(wp_next_scheduled('lws_optimize_maintenance_db_weekly'), 'lws_optimize_maintenance_db_weekly'); 2106 2160 … … 2109 2163 wp_unschedule_event(wp_next_scheduled('lws_optimize_start_filebased_preload'), 'lws_optimize_start_filebased_preload'); 2110 2164 } 2111 wp_schedule_event(time() , "lws_minute", "lws_optimize_start_filebased_preload");2165 wp_schedule_event(time() + 60, "lws_minute", "lws_optimize_start_filebased_preload"); 2112 2166 } 2113 2167 break; … … 2147 2201 2148 2202 wp_unschedule_event(wp_next_scheduled('lws_optimize_clear_filebased_cache'), 'lws_optimize_clear_filebased_cache'); 2149 wp_schedule_event(time() , 'lws_biyearly', 'lws_optimize_clear_filebased_cache');2203 wp_schedule_event(time() + (6 * MONTH_IN_SECONDS), 'lws_biyearly', 'lws_optimize_clear_filebased_cache_cron'); 2150 2204 wp_unschedule_event(wp_next_scheduled('lws_optimize_maintenance_db_weekly'), 'lws_optimize_maintenance_db_weekly'); 2151 2205 … … 2154 2208 wp_unschedule_event(wp_next_scheduled('lws_optimize_start_filebased_preload'), 'lws_optimize_start_filebased_preload'); 2155 2209 } 2156 wp_schedule_event(time() + 10, "lws_minute", "lws_optimize_start_filebased_preload");2210 wp_schedule_event(time() + 60, "lws_minute", "lws_optimize_start_filebased_preload"); 2157 2211 } 2158 2212 break; -
lws-optimize/trunk/lws-optimize.php
r3374948 r3397254 9 9 * Plugin URI: https://www.lws.fr/ 10 10 * Description: Reach better speed and performances with Optimize! Minification, Combination, Media convertion... Everything you need for a better website 11 * Version: 3.3.1 611 * Version: 3.3.17 12 12 * Author: LWS 13 13 * Author URI: https://www.lws.fr -
lws-optimize/trunk/readme.txt
r3374948 r3397254 4 4 Requires at least: 6.0 5 5 Tested up to: 6.8 6 Stable tag: 3.3.1 66 Stable tag: 3.3.17 7 7 Requires PHP: 7.4 8 8 Author: LWS … … 187 187 == Changelog == 188 188 189 = 3.3.17 = 190 * Only options in "Front-End" now clear cache when changed (instead of all options) 191 * Cache is emptied less often now (removed on update, on preload start and on temporary deactivation cleaning) 192 * Updated sitemap fetching to prevent issues when WordPress can't find the original sitemap (due to plugins) ; will now check sitemap_index.xml and wp-sitemap.xml more reliably 193 Fixed issue with the cache-cleaning cron that would be executed too soon and too often, preventing cache creation 194 189 195 = 3.3.16 = 190 196 * Fixed issues where directories/files could not be created during page caching, resulting in CSS/JS not being loaded and white page appearing
Note: See TracChangeset
for help on using the changeset viewer.