Plugin Directory

Changeset 3462798


Ignore:
Timestamp:
02/16/2026 05:55:36 PM (6 weeks ago)
Author:
umangapps48
Message:

wordress 6.9.1 support, new features

Location:
disable-css-js-cache/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • disable-css-js-cache/trunk/README.txt

    r3363418 r3462798  
    55Requires at least: 7.4
    66Requires php: 7.2
    7 Tested up to: 6.8.2
    8 Stable tag: 1.0.0
     7Tested up to: 6.9.1
     8Stable tag: 1.0.9
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2222== Core plugin Features ==
    2323* **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.
    2428
    2529* **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.
     
    4650
    4751== 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
    4858
    4959= 1.0.8 =
  • disable-css-js-cache/trunk/disable-css-js-cache.php

    r3363418 r3462798  
    1717 * Plugin URI:        https://phptutorialpoints.in
    1818 * Description:       This plugin helps prevent browser caching of CSS and JS files from theme in WordPress.
    19  * Version:           1.0.8
     19 * Version:           1.0.9
    2020 * Author:            Umang Prajapati
    2121 * License:           GPL-2.0+
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define( 'DISABLE_CSS_JS_CACHE_VERSION', '1.0.8' );
     38define( 'DISABLE_CSS_JS_CACHE_VERSION', '1.0.9' );
    3939
    4040/**
  • disable-css-js-cache/trunk/includes/class-disable-css-js-cache.php

    r3363418 r3462798  
    197197    }
    198198   
    199     // Don't modify admin scripts or external scripts
     199    // Don't modify admin scripts or external scripts if source is empty
    200200    if ( is_admin() || empty( $src ) || strpos( $src, home_url() ) === false ) {
    201201        return $src;
    202202    }
    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 );
    207232   
    208233    return $src;
     234}
     235
     236/**
     237 * Helper function to convert URL to local path
     238 */
     239function 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;
    209262}
    210263
     
    221274
    222275    $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
    223279    $browser_caching_enabled = get_option('browser_caching_enabled', '');
    224280    $browser_cache_duration = get_option('browser_cache_duration', 604800); // 7 days by default
     
    236292            <table class="form-table" role="presentation">
    237293                <tbody>
     294                    <!-- General Settings -->
    238295                    <tr>
    239296                        <th scope="row"><?php _e( 'Disable CSS JS Cache', 'disable-css-js-cache' ); ?></th>
     
    245302                                <label for="disable_css_js_cache_radio">
    246303                                    <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' ); ?>
    248305                                </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>
    250307                            </fieldset>
    251308                        </td>
     
    253310
    254311                    <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>
    256350                        <td>
    257351                            <fieldset>
     
    261355                                <label for="browser_caching_enabled">
    262356                                    <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' ); ?>
    264358                                </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>
    266360                            </fieldset>
    267361                        </td>
     
    269363                   
    270364                    <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>
    272366                        <td>
    273367                            <fieldset>
    274368                                <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>
    276370                                </legend>
    277371                                <label for="browser_cache_duration">
    278372                                    <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' ); ?>
    280374                                </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>
    282376                            </fieldset>
    283377                        </td>
     
    307401    add_option( 'disable_css_js_cache_radio', '');
    308402    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
    309410    add_option( 'browser_caching_enabled', '');
    310411    register_setting( 'dcjc_options_group', 'browser_caching_enabled', 'disable_css_js_sanitize_checkbox' );
     412   
    311413    add_option( 'browser_cache_duration', '');
    312414    register_setting( 'dcjc_options_group', 'browser_cache_duration', 'disable_css_js_sanitize_duration' );
     415   
    313416    add_option( 'browser_caching_settings_changed', '');
    314417    register_setting( 'dcjc_options_group', 'browser_caching_settings_changed', 'disable_css_js_sanitize_checkbox' );
     
    318421function disable_css_js_sanitize_checkbox( $input ) {
    319422    return ( $input == '1' ) ? '1' : '';
     423}
     424
     425function disable_css_js_sanitize_textarea( $input ) {
     426    return sanitize_textarea_field( $input );
    320427}
    321428
     
    427534add_action('update_option_browser_caching_enabled', 'disable_css_js_add_browser_caching_to_htaccess');
    428535add_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.