Changeset 3462798
- Timestamp:
- 02/16/2026 05:55:36 PM (6 weeks ago)
- Location:
- disable-css-js-cache/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (3 diffs)
-
disable-css-js-cache.php (modified) (2 diffs)
-
includes/class-disable-css-js-cache.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
disable-css-js-cache/trunk/README.txt
r3363418 r3462798 5 5 Requires at least: 7.4 6 6 Requires php: 7.2 7 Tested up to: 6. 8.28 Stable tag: 1.0. 07 Tested up to: 6.9.1 8 Stable tag: 1.0.9 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 22 22 == Core plugin Features == 23 23 * **Instantly Disable CSS and JS Cache:** The plugin provides a simple toggle switch to disable caching for CSS and JS files with just a single click. No coding or complex configurations required. This feature allows you to quickly bypass caching for these critical files and ensure seamless updates and changes reflect immediately. 24 25 * **Smart Cache Busting (New):** Choose between Force Refresh (timestamp) or Smart Refresh (file modification time). Smart Refresh only updates the version when the file is actually modified, which is better for performance. 26 27 * **Exclude Specific Paths (New):** You can now exclude specific files or paths from cache busting. Simply enter them in the settings page. 24 28 25 29 * **Prevent Display Issues:** When making changes to your website's CSS or JS files, caching can often cause display issues where the changes don't reflect in the user's browser. "Disable CSS JS Cache" eliminates this problem, allowing you to make real-time updates and maintain a consistently smooth user experience. … … 46 50 47 51 == Changelog == 52 53 = 1.0.9 = 54 * Feature: Added Smart Refresh (File Modification Time) option for better performance. 55 * Feature: Added option to exclude specific paths from cache busting. 56 * Improvement: Updated settings page UI. 57 * Added support for wordpress 6.9.1 48 58 49 59 = 1.0.8 = -
disable-css-js-cache/trunk/disable-css-js-cache.php
r3363418 r3462798 17 17 * Plugin URI: https://phptutorialpoints.in 18 18 * Description: This plugin helps prevent browser caching of CSS and JS files from theme in WordPress. 19 * Version: 1.0. 819 * Version: 1.0.9 20 20 * Author: Umang Prajapati 21 21 * License: GPL-2.0+ … … 36 36 * Rename this for your plugin and update it as you release new versions. 37 37 */ 38 define( 'DISABLE_CSS_JS_CACHE_VERSION', '1.0. 8' );38 define( 'DISABLE_CSS_JS_CACHE_VERSION', '1.0.9' ); 39 39 40 40 /** -
disable-css-js-cache/trunk/includes/class-disable-css-js-cache.php
r3363418 r3462798 197 197 } 198 198 199 // Don't modify admin scripts or external scripts 199 // Don't modify admin scripts or external scripts if source is empty 200 200 if ( is_admin() || empty( $src ) || strpos( $src, home_url() ) === false ) { 201 201 return $src; 202 202 } 203 204 // Add timestamp to prevent caching 205 $timestamp = current_time( 'timestamp' ); 206 $src = add_query_arg( 'ver', $timestamp, $src ); 203 204 // Check for excluded paths 205 $exclude_paths = get_option( 'disable_css_js_exclude_paths', '' ); 206 if ( ! empty( $exclude_paths ) ) { 207 $paths_array = array_map( 'trim', explode( "\n", $exclude_paths ) ); 208 foreach ( $paths_array as $path ) { 209 if ( ! empty( $path ) && strpos( $src, $path ) !== false ) { 210 return $src; 211 } 212 } 213 } 214 215 $cache_method = get_option( 'disable_css_js_cache_method', 'time' ); 216 $version = ''; 217 218 if ( 'filemtime' === $cache_method ) { 219 // Convert URL to local path 220 $local_path = disable_css_js_get_local_path( $src ); 221 if ( $local_path && file_exists( $local_path ) ) { 222 $version = filemtime( $local_path ); 223 } 224 } 225 226 // Fallback to timestamp if file not found or method is 'time' 227 if ( empty( $version ) ) { 228 $version = current_time( 'timestamp' ); 229 } 230 231 $src = add_query_arg( 'ver', $version, $src ); 207 232 208 233 return $src; 234 } 235 236 /** 237 * Helper function to convert URL to local path 238 */ 239 function disable_css_js_get_local_path( $url ) { 240 $base_url = home_url(); 241 $parsed_url = parse_url( $url ); 242 $parsed_base = parse_url( $base_url ); 243 244 // Clean up URL parameters 245 $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; 246 247 // If URL host matches site host 248 if ( ! isset( $parsed_url['host'] ) || $parsed_url['host'] === $parsed_base['host'] ) { 249 // Remove the base path from the URL path if it exists (for sub-directory installs) 250 $base_path = isset( $parsed_base['path'] ) ? rtrim($parsed_base['path'], '/') : ''; 251 252 if ( ! empty( $base_path ) && strpos( $path, $base_path ) === 0 ) { 253 $path = substr( $path, strlen( $base_path ) ); 254 } 255 256 // ABSPATH already includes the trailing slash 257 $local_path = ABSPATH . ltrim( $path, '/' ); 258 return $local_path; 259 } 260 261 return false; 209 262 } 210 263 … … 221 274 222 275 $disable_css_js_cache_radio = get_option('disable_css_js_cache_radio', ''); 276 $cache_method = get_option('disable_css_js_cache_method', 'time'); 277 $exclude_paths = get_option('disable_css_js_exclude_paths', ''); 278 223 279 $browser_caching_enabled = get_option('browser_caching_enabled', ''); 224 280 $browser_cache_duration = get_option('browser_cache_duration', 604800); // 7 days by default … … 236 292 <table class="form-table" role="presentation"> 237 293 <tbody> 294 <!-- General Settings --> 238 295 <tr> 239 296 <th scope="row"><?php _e( 'Disable CSS JS Cache', 'disable-css-js-cache' ); ?></th> … … 245 302 <label for="disable_css_js_cache_radio"> 246 303 <input name="disable_css_js_cache_radio" type="checkbox" id="disable_css_js_cache_radio" value="1" <?php checked( $disable_css_js_cache_radio, '1' ); ?>> 247 <?php _e( ' Disable CSS JS Cache', 'disable-css-js-cache' ); ?>304 <?php _e( 'Enable Cache Busting', 'disable-css-js-cache' ); ?> 248 305 </label> 249 <p class="description"><?php _e( 'This will add a timestamp to CSS and JS files to prevent browser caching.', 'disable-css-js-cache' ); ?></p>306 <p class="description"><?php _e( 'This will add a version parameter to CSS and JS files.', 'disable-css-js-cache' ); ?></p> 250 307 </fieldset> 251 308 </td> … … 253 310 254 311 <tr> 255 <th scope="row"><?php _e( 'Browser Caching Header for Static Assets', 'disable-css-js-cache' ); ?></th> 312 <th scope="row"><?php _e( 'Cache Busting Method', 'disable-css-js-cache' ); ?></th> 313 <td> 314 <fieldset> 315 <legend class="screen-reader-text"> 316 <span><?php _e( 'Cache Busting Method', 'disable-css-js-cache' ); ?></span> 317 </legend> 318 <label> 319 <input type="radio" name="disable_css_js_cache_method" value="time" <?php checked( $cache_method, 'time' ); ?>> 320 <?php _e( 'Force Refresh (Timestamp)', 'disable-css-js-cache' ); ?> 321 </label><br> 322 <label> 323 <input type="radio" name="disable_css_js_cache_method" value="filemtime" <?php checked( $cache_method, 'filemtime' ); ?>> 324 <?php _e( 'Smart Refresh (File Modification Time)', 'disable-css-js-cache' ); ?> 325 </label> 326 <p class="description"><?php _e( 'Force Refresh updates the version on every page load (good for development). Smart Refresh only updates when the file is actually modified (good for production).', 'disable-css-js-cache' ); ?></p> 327 </fieldset> 328 </td> 329 </tr> 330 331 <tr> 332 <th scope="row"><?php _e( 'Exclude Paths', 'disable-css-js-cache' ); ?></th> 333 <td> 334 <fieldset> 335 <legend class="screen-reader-text"> 336 <span><?php _e( 'Exclude Paths', 'disable-css-js-cache' ); ?></span> 337 </legend> 338 <textarea name="disable_css_js_exclude_paths" id="disable_css_js_exclude_paths" rows="5" cols="50" class="large-text code"><?php echo esc_textarea( $exclude_paths ); ?></textarea> 339 <p class="description"><?php _e( 'Enter one path or filename per line to exclude from cache busting (e.g. jquery.js, /wp-includes/).', 'disable-css-js-cache' ); ?></p> 340 </fieldset> 341 </td> 342 </tr> 343 344 <!-- Separator --> 345 <tr><td colspan="2"><hr></td></tr> 346 347 <!-- Static Assets Settings --> 348 <tr> 349 <th scope="row"><?php _e( 'Browser Caching Header', 'disable-css-js-cache' ); ?></th> 256 350 <td> 257 351 <fieldset> … … 261 355 <label for="browser_caching_enabled"> 262 356 <input name="browser_caching_enabled" type="checkbox" id="browser_caching_enabled" value="1" <?php checked( $browser_caching_enabled, '1' ); ?>> 263 <?php _e( 'Enable browser caching for static assets ', 'disable-css-js-cache' ); ?>357 <?php _e( 'Enable browser caching for static assets (.htaccess)', 'disable-css-js-cache' ); ?> 264 358 </label> 265 <p class="description"><?php _e( 'This will add caching headers to your .htaccess file for images, CSS, and JS files.', 'disable-css-js-cache' ); ?></p>359 <p class="description"><?php _e( 'This will add proper Cache-Control headers to your .htaccess file for better performance.', 'disable-css-js-cache' ); ?></p> 266 360 </fieldset> 267 361 </td> … … 269 363 270 364 <tr> 271 <th scope="row"><?php _e( 'Caching Duration for Static Assets', 'disable-css-js-cache' ); ?></th>365 <th scope="row"><?php _e( 'Caching Duration', 'disable-css-js-cache' ); ?></th> 272 366 <td> 273 367 <fieldset> 274 368 <legend class="screen-reader-text"> 275 <span><?php _e( ' Static Assets', 'disable-css-js-cache' ); ?></span>369 <span><?php _e( 'Caching Duration', 'disable-css-js-cache' ); ?></span> 276 370 </legend> 277 371 <label for="browser_cache_duration"> 278 372 <input name="browser_cache_duration" type="number" id="browser_cache_duration" min="60" max="31536000" value="<?php echo esc_attr( $browser_cache_duration ); ?>"> 279 <?php _e( ' (Enter Value in Seconds. Default: 604800 = 1 Week)', 'disable-css-js-cache' ); ?>373 <?php _e( 'Seconds', 'disable-css-js-cache' ); ?> 280 374 </label> 281 <p class="description"><?php _e( ' Minimum: 60 seconds, Maximum: 31536000 seconds (1 year)', 'disable-css-js-cache' ); ?></p>375 <p class="description"><?php _e( 'Default: 604800 (1 Week). Max: 31536000 (1 Year).', 'disable-css-js-cache' ); ?></p> 282 376 </fieldset> 283 377 </td> … … 307 401 add_option( 'disable_css_js_cache_radio', ''); 308 402 register_setting( 'dcjc_options_group', 'disable_css_js_cache_radio', 'disable_css_js_sanitize_checkbox' ); 403 404 add_option( 'disable_css_js_cache_method', 'time'); 405 register_setting( 'dcjc_options_group', 'disable_css_js_cache_method', 'sanitize_text_field' ); 406 407 add_option( 'disable_css_js_exclude_paths', ''); 408 register_setting( 'dcjc_options_group', 'disable_css_js_exclude_paths', 'disable_css_js_sanitize_textarea' ); 409 309 410 add_option( 'browser_caching_enabled', ''); 310 411 register_setting( 'dcjc_options_group', 'browser_caching_enabled', 'disable_css_js_sanitize_checkbox' ); 412 311 413 add_option( 'browser_cache_duration', ''); 312 414 register_setting( 'dcjc_options_group', 'browser_cache_duration', 'disable_css_js_sanitize_duration' ); 415 313 416 add_option( 'browser_caching_settings_changed', ''); 314 417 register_setting( 'dcjc_options_group', 'browser_caching_settings_changed', 'disable_css_js_sanitize_checkbox' ); … … 318 421 function disable_css_js_sanitize_checkbox( $input ) { 319 422 return ( $input == '1' ) ? '1' : ''; 423 } 424 425 function disable_css_js_sanitize_textarea( $input ) { 426 return sanitize_textarea_field( $input ); 320 427 } 321 428 … … 427 534 add_action('update_option_browser_caching_enabled', 'disable_css_js_add_browser_caching_to_htaccess'); 428 535 add_action('update_option_browser_cache_duration', 'disable_css_js_add_browser_caching_to_htaccess'); 429
Note: See TracChangeset
for help on using the changeset viewer.