Plugin Directory

Changeset 3402049


Ignore:
Timestamp:
11/24/2025 06:36:43 PM (4 months ago)
Author:
sethta
Message:

Update to version 1.4.4

Location:
easy-critical-css
Files:
297 added
13 edited

Legend:

Unmodified
Added
Removed
  • easy-critical-css/trunk/assets/admin.js

    r3401089 r3402049  
    155155  const toggleButton = document.getElementById('ecc-toggle-advanced')
    156156  const advancedSettings = document.getElementById('ecc-advanced-settings')
    157  
     157
    158158  if (toggleButton && advancedSettings) {
    159159    toggleButton.addEventListener('click', function(e) {
    160160      e.preventDefault()
    161      
     161
    162162      const isVisible = advancedSettings.style.display !== 'none'
    163      
     163
    164164      if (isVisible) {
    165165        advancedSettings.style.display = 'none'
     
    180180      const statusContainer = this.closest('.ecc-auto-mode-status')
    181181      if (!statusContainer) return
    182      
     182
    183183      const details = statusContainer.querySelector('.ecc-status-details')
    184184      if (!details) return
    185      
     185
    186186      const isVisible = details.style.display !== 'none'
    187187      details.style.display = isVisible ? 'none' : 'block'
     
    194194    btn.addEventListener('click', function(e) {
    195195      e.preventDefault()
    196      
     196
    197197      btn.disabled = true
    198198      btn.textContent = 'Refreshing...'
    199      
     199
    200200      fetch(`${easyCriticalCss.restUrl}refresh-auto-mode-status`, {
    201201        method: 'POST',
     
    215215        const statusContainer = btn.closest('.ecc-auto-mode-status')
    216216        if (!statusContainer) return
    217        
     217
    218218        const allOk = data.all_ok
     219        const activeKeyOk = data.active_key
    219220        const localOk = data.local_ok
    220221        const restApiOk = data.rest_api_ok
    221        
     222
    222223        // Update main status
    223224        const icon = statusContainer.querySelector('.ecc-status-icon')
    224225        const text = statusContainer.querySelector('.ecc-status-text')
    225226        const statusClass = allOk ? 'ecc-status-ready' : 'ecc-status-blocked'
    226        
     227
    227228        icon.style.color = allOk ? '#1e7e34' : '#b12331'
    228229        icon.textContent = allOk ? '✓' : '✕'
    229230        text.textContent = allOk ? 'Auto mode ready' : 'Auto mode cannot run'
    230        
     231
    231232        statusContainer.className = 'ecc-auto-mode-status ' + statusClass
    232        
     233
    233234        // Update details
    234235        const checks = statusContainer.querySelectorAll('.ecc-check')
    235236        const detailItems = statusContainer.querySelectorAll('.ecc-status-details li')
    236        
     237
     238        // Map checks/detailItems to the correct data: 0=Active API Key, 1=Local Install, 2=REST API Reachable
    237239        if (checks[0]) {
    238           checks[0].className = 'ecc-check ' + (localOk ? 'ecc-check-ok' : 'ecc-check-fail')
    239           checks[0].textContent = localOk ? '✓' : '✕'
    240         }
    241        
     240          checks[0].className = 'ecc-check ' + (activeKeyOk ? 'ecc-check-ok' : 'ecc-check-fail')
     241          checks[0].textContent = activeKeyOk ? '✓' : '✕'
     242        }
     243
    242244        if (checks[1]) {
    243           checks[1].className = 'ecc-check ' + (restApiOk ? 'ecc-check-ok' : 'ecc-check-fail')
    244           checks[1].textContent = restApiOk ? '✓' : '✕'
    245         }
    246        
    247         // Update error messages in detail items
    248         if (detailItems[0]) {
    249           const localErrorEl = detailItems[0].querySelector('em') || detailItems[0].lastChild
    250           if (localErrorEl && !localOk) {
    251             if (!detailItems[0].querySelector('em')) {
    252               const em = document.createElement('em')
    253               em.textContent = 'Site is local'
    254               detailItems[0].appendChild(em)
    255             }
    256           } else if (localErrorEl && localOk && localErrorEl.tagName === 'EM') {
    257             localErrorEl.remove()
     245          checks[1].className = 'ecc-check ' + (localOk ? 'ecc-check-ok' : 'ecc-check-fail')
     246          checks[1].textContent = localOk ? '✓' : '✕'
     247        }
     248
     249        if (checks[2]) {
     250          checks[2].className = 'ecc-check ' + (restApiOk ? 'ecc-check-ok' : 'ecc-check-fail')
     251          checks[2].textContent = restApiOk ? '✓' : '✕'
     252        }
     253
     254        // Helper: replace any plain text error nodes with an <em>, or remove them when OK
     255        function setDetailMessage(li, ok, message) {
     256          if (!li) return
     257          const em = li.querySelector('em')
     258          // Remove any plain text nodes (text nodes that are not the <strong> or <span>)
     259          const textNodes = Array.from(li.childNodes).filter(function(n) {
     260            return n.nodeType === Node.TEXT_NODE && n.textContent.trim().length > 0
     261          })
     262
     263          if (!ok) {
     264            if (em) return // already present
     265            // remove existing plain text nodes so we don't duplicate messages
     266            textNodes.forEach(function(n) { n.remove() })
     267            const newEm = document.createElement('em')
     268            newEm.textContent = message
     269            li.appendChild(newEm)
     270          } else {
     271            if (em) em.remove()
     272            // also remove any lingering plain text error nodes
     273            textNodes.forEach(function(n) { n.remove() })
    258274          }
    259275        }
    260        
    261         if (detailItems[1]) {
    262           const apiErrorEl = detailItems[1].querySelector('em') || detailItems[1].lastChild
    263           if (apiErrorEl && !restApiOk) {
    264             if (!detailItems[1].querySelector('em')) {
    265               const em = document.createElement('em')
    266               em.textContent = 'Generator cannot reach the site'
    267               detailItems[1].appendChild(em)
    268             }
    269           } else if (apiErrorEl && restApiOk && apiErrorEl.tagName === 'EM') {
    270             apiErrorEl.remove()
    271           }
    272         }
     276
     277        // Active API Key (detailItems[0])
     278        setDetailMessage(detailItems[0], activeKeyOk, 'No active API key')
     279        // Local Install (detailItems[1])
     280        setDetailMessage(detailItems[1], localOk, 'Site is local')
     281        // REST API Reachable (detailItems[2])
     282        setDetailMessage(detailItems[2], restApiOk, 'Generator cannot reach the site')
    273283       
    274284        btn.disabled = false
  • easy-critical-css/trunk/easy-critical-css.php

    r3401089 r3402049  
    33 * Plugin Name:       Easy Critical CSS
    44 * Description:       Easily inject Critical CSS and Secondary CSS (with unused styles removed) to improve site speed and performance.
    5  * Version:           1.4.3
     5 * Version:           1.4.4
    66 * Requires at least: 6.2
    7  * Tested up to:      6.8.3
     7 * Tested up to:      6.8
    88 * Requires PHP:      7.4
    99 * Author:            CriticalCSS.net
  • easy-critical-css/trunk/inc/class-admin-settings.php

    r3401089 r3402049  
    252252
    253253                            <li>
    254                                 <strong><?php esc_html_e( 'Local Install:', 'easy-critical-css' ); ?></strong>
     254                                <strong><?php esc_html_e( 'Site is Public:', 'easy-critical-css' ); ?></strong>
    255255                                <span class="ecc-check <?php echo $status['local_ok'] ? 'ecc-check-ok' : 'ecc-check-fail'; ?>">
    256256                                    <?php echo $status['local_ok'] ? '✓' : '✕'; ?>
     
    805805
    806806            // Clear cached transients related to site environment checks.
    807             delete_transient( 'easy_cc_is_local_site' );
    808             delete_transient( 'easy_cc_is_rest_api_reachable' );
     807            TimedOption::delete_all();
    809808        }
    810809    }
  • easy-critical-css/trunk/inc/class-api-service.php

    r3401089 r3402049  
    1717    public static function test_receive_endpoint() {
    1818        // Check transient for cached result.
    19         $cached = get_transient( 'easy_cc_is_rest_api_reachable' );
     19        $cached = TimedOption::get( 'is_rest_api_reachable' );
    2020        if ( $cached !== false ) {
    2121            return (bool) $cached;
     
    2626
    2727        // Store the nonce in a transient for verification (5 minute expiry for the test).
    28         set_transient( 'easy_cc_test_nonce_' . substr( $nonce, 0, 8 ), $nonce, 5 * MINUTE_IN_SECONDS );
     28        TimedOption::set( 'receive_test_nonce', $nonce, 5 * MINUTE_IN_SECONDS );
    2929
    3030        $api_url = self::get_api_url();
     
    4444
    4545        if ( is_wp_error( $response ) ) {
    46             set_transient( 'easy_cc_is_rest_api_reachable', '0', 6 * HOUR_IN_SECONDS );
     46            TimedOption::set( 'is_rest_api_reachable', '0', 6 * HOUR_IN_SECONDS );
     47
    4748            return false;
    4849        }
     
    5455
    5556        // Cache the result for 6 hours.
    56         set_transient( 'easy_cc_is_rest_api_reachable', $success ? '1' : '0', 6 * HOUR_IN_SECONDS );
     57        TimedOption::set( 'is_rest_api_reachable', $success ? '1' : '0', 6 * HOUR_IN_SECONDS );
    5758
    5859        return $success;
  • easy-critical-css/trunk/inc/class-helpers.php

    r3401089 r3402049  
    186186    public static function is_local_site( $host, $debug = false ) {
    187187        // Check transient.
    188         $cached = get_transient( 'easy_cc_is_local_site' );
     188        $cached = TimedOption::get( 'is_local_site' );
    189189        if ( ! $debug && $cached !== false ) {
    190190            return (bool) $cached;
     
    237237        // We need to store both true and false values as a transient, but only if no debug.
    238238        if ( ! $debug ) {
    239             set_transient( 'easy_cc_is_local_site', $is_local ? '1' : '0', 6 * HOUR_IN_SECONDS );
     239            TimedOption::set( 'is_local_site', $is_local ? '1' : '0', 6 * HOUR_IN_SECONDS );
    240240        } else {
    241241            // Give more info if debug.
     
    248248    }
    249249
     250    public static function get_auto_mode_status( $force_refresh = false ) {
     251        // Check transient.
     252        $cached = TimedOption::get( 'auto_mode_status' );
     253        if ( ! $force_refresh && $cached !== false ) {
     254            return $cached;
     255        }
     256
     257        $status = [
     258            'active_key'  => false,
     259            'local_ok'    => ! self::is_local_site( wp_parse_url( site_url(), PHP_URL_HOST ) ),
     260            'rest_api_ok' => false,
     261            'all_ok'      => false,
     262        ];
     263
     264        // Only run full status check if there's an active API key.
     265        if ( empty( easy_cc_fs()->has_active_valid_license() ) ) {
     266            TimedOption::set( 'auto_mode_status', $status, 6 * HOUR_IN_SECONDS );
     267
     268            return $status;
     269        }
     270
     271        $status['active_key'] = true;
     272        $status['rest_api_ok'] = API_Service::test_receive_endpoint();
     273
     274        // Overall ready state requires an active key, non-local install, and REST API reachability.
     275        $status['all_ok'] = $status['active_key'] && $status['local_ok'] && $status['rest_api_ok'];
     276
     277        TimedOption::set( 'auto_mode_status', $status, 6 * HOUR_IN_SECONDS );
     278
     279        return $status;
     280    }
     281
    250282    public static function is_rest_api_reachable( $debug = false ) {
    251283        // Check transient.
    252         $cached = get_transient( 'easy_cc_is_rest_api_reachable' );
     284        $cached = TimedOption::get( 'is_rest_api_reachable' );
    253285        if ( ! $debug && $cached !== false ) {
    254286            return (bool) $cached;
    255287        }
    256288
    257         $is_reachable = API_Service::test_receive_endpoint();
     289        $auto_mode_status = self::get_auto_mode_status();
     290        $is_reachable     = $auto_mode_status['rest_api_ok'];
    258291
    259292        // We need to store both true and false values as a transient, but only if no debug.
    260293        if ( ! $debug ) {
    261             set_transient( 'easy_cc_is_rest_api_reachable', $is_reachable ? '1' : '0', 6 * HOUR_IN_SECONDS );
     294            TimedOption::set( 'is_rest_api_reachable', $is_reachable ? '1' : '0', 6 * HOUR_IN_SECONDS );
    262295        } else {
    263296            // Give more info if debug.
     
    329362        return apply_filters( 'easy_cc_excluded_url_params', $excluded_url_params );
    330363    }
    331 
    332     public static function get_auto_mode_status() {
    333         // Only show status if there's an active API key.
    334         if ( empty( easy_cc_fs()->has_active_valid_license() ) ) {
    335             return [
    336                 'active_key'  => false,
    337                 'local_ok'    => false,
    338                 'rest_api_ok' => false,
    339                 'all_ok'      => false,
    340             ];
    341         }
    342 
    343         $status = [
    344             'active_key'  => true,
    345             'local_ok'    => ! self::is_local_site( wp_parse_url( site_url(), PHP_URL_HOST ) ),
    346             'rest_api_ok' => API_Service::test_receive_endpoint(),
    347         ];
    348 
    349         // Overall ready state requires an active key, non-local install, and REST API reachability.
    350         $status['all_ok'] = $status['active_key'] && $status['local_ok'] && $status['rest_api_ok'];
    351 
    352         return $status;
    353     }
    354364}
  • easy-critical-css/trunk/inc/class-plugin.php

    r3401089 r3402049  
    1010    private static $instance = null;
    1111
    12     private static $plugin_version = '1.4.3';
     12    private static $plugin_version = '1.4.4';
    1313
    1414    private static $db_version = '2';
  • easy-critical-css/trunk/inc/class-reset-handler.php

    r3395875 r3402049  
    5555
    5656        // Remove transients.
     57        TimedOption::delete_all();
     58
     59        // Remove old transients.
    5760        delete_transient( 'easy_cc_is_local_site' );
    5861        delete_transient( 'easy_cc_is_rest_api_reachable' );
  • easy-critical-css/trunk/inc/class-rest-api.php

    r3401089 r3402049  
    562562        // Mark REST API reachability as successful so we don't trigger repeated
    563563        // remote tests immediately after receiving CSS. Cache for 6 hours.
    564         set_transient( 'easy_cc_is_rest_api_reachable', '1', 6 * HOUR_IN_SECONDS );
     564        TimedOption::set( 'is_rest_api_reachable', '1', 6 * HOUR_IN_SECONDS );
    565565
    566566        /**
     
    801801
    802802    public static function handle_receive_test( WP_REST_Request $request ) {
    803         global $wpdb;
    804 
    805803        $nonce = sanitize_text_field( $request->get_param( 'nonce' ) );
    806804
     
    813811        }
    814812
    815         $test_nonce = get_transient( 'easy_cc_test_nonce_' . substr( $nonce, 0, 8 ) );
    816         if ( ! $test_nonce || $test_nonce !== $nonce ) {
     813        $stored_nonce = TimedOption::get( 'receive_test_nonce' );
     814        if ( ! $stored_nonce || $stored_nonce !== $nonce ) {
    817815            return new WP_Error(
    818816                'invalid_nonce',
     
    822820        }
    823821
     822        // Success, clean it up.
     823        TimedOption::delete( 'receive_test_nonce' );
     824
    824825        return rest_ensure_response( [ 'success' => true ] );
    825826    }
     
    845846        // Clear the REST API reachability cache and get fresh status.
    846847        delete_transient( 'easy_cc_is_rest_api_reachable' );
    847         $status = Helpers::get_auto_mode_status();
     848        $status = Helpers::get_auto_mode_status( true );
    848849
    849850        return rest_ensure_response( $status );
  • easy-critical-css/trunk/inc/load-freemius.php

    r3307644 r3402049  
    5757easy_cc_fs()->add_filter( 'show_deactivation_feedback_form', '__return_false' );
    5858
     59// Clear auto_mode_status cache when license changes.
     60easy_cc_fs()->add_action( 'after_license_change', [ __NAMESPACE__ . '\TimedOption', 'delete_all' ] );
     61easy_cc_fs()->add_action( 'after_license_activation', [ __NAMESPACE__ . '\TimedOption', 'delete_all' ] );
     62easy_cc_fs()->add_action( 'after_license_deactivation', [ __NAMESPACE__ . '\TimedOption', 'delete_all' ] );
     63
    5964// Signal that SDK was initiated.
    6065do_action( 'easy_cc_fs_loaded' );
  • easy-critical-css/trunk/readme.txt

    r3401089 r3402049  
    44Tags: critical css, unused css, performance, optimization, lighthouse
    55Requires at least: 6.2
    6 Tested up to:      6.8.3
     6Tested up to:      6.8
    77Requires PHP:      7.4
    8 Stable tag:        trunk
     8Stable tag:        1.4.4
    99License:           GPLv2 or later
    1010License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    102102== Changelog ==
    103103
     104= 1.4.4 =
     105- FIX: Addresses an issue where transients clear too quickly on some server configurations.
     106- FIX: Prevents status checks from sending when no API key is present.
     107
    104108= 1.4.3 =
    105109- OPTIMIZATION: Adds better REST API check with more details on Settings page
     
    182186== Upgrade Notice ==
    183187
     188= 1.4.4 =
     189* This update provides bug fixes.
     190
     191= 1.4.3 =
     192* This update provides compatibility improvements and bug fixes.
     193
    184194= 1.4.2 =
    185195* This update provides compatibility improvements and bug fixes.
  • easy-critical-css/trunk/vendor/composer/autoload_classmap.php

    r3395875 r3402049  
    3333    'EasyCriticalCSS\\Reset_Handler' => $baseDir . '/inc/class-reset-handler.php',
    3434    'EasyCriticalCSS\\Settings' => $baseDir . '/inc/class-settings.php',
     35    'EasyCriticalCSS\\TimedOption' => $baseDir . '/inc/class-timed_option.php',
    3536    'EasyCriticalCSS\\Uninstall_Handler' => $baseDir . '/inc/class-uninstall-handler.php',
    3637);
  • easy-critical-css/trunk/vendor/composer/autoload_static.php

    r3395875 r3402049  
    3838        'EasyCriticalCSS\\Reset_Handler' => __DIR__ . '/../..' . '/inc/class-reset-handler.php',
    3939        'EasyCriticalCSS\\Settings' => __DIR__ . '/../..' . '/inc/class-settings.php',
     40        'EasyCriticalCSS\\TimedOption' => __DIR__ . '/../..' . '/inc/class-timed_option.php',
    4041        'EasyCriticalCSS\\Uninstall_Handler' => __DIR__ . '/../..' . '/inc/class-uninstall-handler.php',
    4142    );
  • easy-critical-css/trunk/vendor/composer/installed.php

    r3401089 r3402049  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '7cba3efe0d456a72032002b0be1b75841af0dbdc',
     6        'reference' => 'ea2ebe9b5d6c7882882c5dcd835bd2d76e8d97c2',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    2323            'pretty_version' => 'dev-main',
    2424            'version' => 'dev-main',
    25             'reference' => '7cba3efe0d456a72032002b0be1b75841af0dbdc',
     25            'reference' => 'ea2ebe9b5d6c7882882c5dcd835bd2d76e8d97c2',
    2626            'type' => 'wordpress-plugin',
    2727            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.