Plugin Directory

Changeset 3483242


Ignore:
Timestamp:
03/15/2026 06:10:09 PM (2 weeks ago)
Author:
solankisoftware
Message:

Fixed admin console errors

Location:
speedora-total-website-speed-optimization
Files:
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • speedora-total-website-speed-optimization/tags/1.0.0/assets/js/admin.js

    r3483024 r3483242  
    33 */
    44
    5 jQuery(document).ready(function($) {
    6     // Tab switching
    7     $('.SPEEDORA-nav-item').on('click', function(e) {
     5jQuery( document ).ready( function( $ ) {
     6    try {
     7        // Tab switching (only on our settings page).
     8        $( '.SPEEDORA-nav-item' ).on( 'click', function( e ) {
    89        e.preventDefault();
    910
    10         // Remove active class from all tabs and nav items
    11         $('.SPEEDORA-tab').removeClass('active');
    12         $('.SPEEDORA-nav-item').removeClass('active');
     11            // Remove active class from all tabs and nav items.
     12            $( '.SPEEDORA-tab' ).removeClass( 'active' );
     13            $( '.SPEEDORA-nav-item' ).removeClass( 'active' );
    1314
    14         // Add active class to clicked nav item
    15         $(this).addClass('active');
     15            // Add active class to clicked nav item.
     16            $( this ).addClass( 'active' );
    1617
    17         // Get the tab ID and show it
    18         const tabId = $(this).data('tab');
    19         $('#' + tabId).addClass('active');
     18            // Get the tab ID and show it.
     19            var tabId = $( this ).data( 'tab' );
     20            if ( tabId ) {
     21                $( '#' + tabId ).addClass( 'active' );
     22            }
    2023
    21         // Scroll to tab
    22         $('.SPEEDORA-main').scrollTop(0);
    23     });
     24            // Scroll to tab.
     25            $( '.SPEEDORA-main' ).scrollTop( 0 );
     26        } );
    2427
    25     // Handle form submissions for tools
    26     $('form').on('submit', function() {
    27         const action = $(this).find('button[type="submit"]:focus').val();
    28        
    29         if (action === 'optimize_database') {
    30             if (typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmOptimize) {
    31                 if (!confirm(SPEEDORAData.confirmOptimize)) {
     28        // Handle form submissions for our plugin tools/settings only.
     29        $( '#SPEEDORA-settings-form, .SPEEDORA-tools form' ).on( 'submit', function() {
     30            var $form  = $( this );
     31            var $btn   = $form.find( 'button[type="submit"]:focus' );
     32            var action = $btn.length ? $btn.val() : $form.find( 'input[name="action"]' ).val();
     33
     34            if ( ! action ) {
     35                return true;
     36            }
     37
     38            if ( action === 'optimize_database' ) {
     39                var msg = 'This may take a while. Continue?';
     40                if ( typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmOptimize ) {
     41                    msg = SPEEDORAData.confirmOptimize;
     42                }
     43                if ( ! window.confirm( msg ) ) {
    3244                    return false;
    3345                }
    34             } else if (!confirm('This may take a while. Continue?')) {
    35                 return false;
    3646            }
    37         }
    3847
    39         if (action === 'clear_cache') {
    40             if (typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmClear) {
    41                 if (!confirm(SPEEDORAData.confirmClear)) {
     48            if ( action === 'clear_cache' ) {
     49                var clearMsg = 'Are you sure you want to clear all cache?';
     50                if ( typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmClear ) {
     51                    clearMsg = SPEEDORAData.confirmClear;
     52                }
     53                if ( ! window.confirm( clearMsg ) ) {
    4254                    return false;
    4355                }
    44             } else if (!confirm('Are you sure you want to clear all cache?')) {
    45                 return false;
    4656            }
     57
     58            return true;
     59        } );
     60
     61        // Placeholder: SPEEDORAData may carry extra info for future AJAX ops.
     62        if ( typeof SPEEDORAData !== 'undefined' ) {
     63            // No-op for now.
    4764        }
    48     });
    49 
    50     // AJAX handlers for async operations
    51     if (typeof SPEEDORAData !== 'undefined') {
    52         // You can add AJAX handlers here for async operations
     65    } catch ( e ) {
     66        // Swallow any unexpected errors to avoid breaking the admin console.
     67        if ( window && window.console && console.error ) {
     68            console.error( 'Speedora admin script error:', e );
     69        }
    5370    }
    54 
    55     // Show success/error messages
    56     if (typeof wp !== 'undefined' && wp.notices) {
    57         // Notices are handled by WordPress
    58     }
    59 });
     71} );
    6072
    6173
  • speedora-total-website-speed-optimization/tags/1.0.0/includes/class-minify.php

    r3483024 r3483242  
    1919     */
    2020    public static function SPEEDORA_setup_minification() {
     21        // Never touch admin area scripts/styles – avoid breaking block editor and core JS.
     22        if ( is_admin() ) {
     23            return;
     24        }
     25
    2126        if ( SPEEDORA_Settings::SPEEDORA_is_optimization_enabled( 'minify_html' ) ) {
    2227            add_filter( 'the_content', array( self::class, 'SPEEDORA_minify_html' ) );
     
    162167     */
    163168    public static function SPEEDORA_modify_script_tags( $tag, $handle ) {
     169        // Do not modify script tags in admin; many core scripts rely on exact loading order.
     170        if ( is_admin() ) {
     171            return $tag;
     172        }
    164173        // Get excluded scripts that should not be deferred/async
    165174        $excluded = array( 'jquery-core', 'jquery' );
  • speedora-total-website-speed-optimization/trunk/assets/js/admin.js

    r3483024 r3483242  
    33 */
    44
    5 jQuery(document).ready(function($) {
    6     // Tab switching
    7     $('.SPEEDORA-nav-item').on('click', function(e) {
     5jQuery( document ).ready( function( $ ) {
     6    try {
     7        // Tab switching (only on our settings page).
     8        $( '.SPEEDORA-nav-item' ).on( 'click', function( e ) {
    89        e.preventDefault();
    910
    10         // Remove active class from all tabs and nav items
    11         $('.SPEEDORA-tab').removeClass('active');
    12         $('.SPEEDORA-nav-item').removeClass('active');
     11            // Remove active class from all tabs and nav items.
     12            $( '.SPEEDORA-tab' ).removeClass( 'active' );
     13            $( '.SPEEDORA-nav-item' ).removeClass( 'active' );
    1314
    14         // Add active class to clicked nav item
    15         $(this).addClass('active');
     15            // Add active class to clicked nav item.
     16            $( this ).addClass( 'active' );
    1617
    17         // Get the tab ID and show it
    18         const tabId = $(this).data('tab');
    19         $('#' + tabId).addClass('active');
     18            // Get the tab ID and show it.
     19            var tabId = $( this ).data( 'tab' );
     20            if ( tabId ) {
     21                $( '#' + tabId ).addClass( 'active' );
     22            }
    2023
    21         // Scroll to tab
    22         $('.SPEEDORA-main').scrollTop(0);
    23     });
     24            // Scroll to tab.
     25            $( '.SPEEDORA-main' ).scrollTop( 0 );
     26        } );
    2427
    25     // Handle form submissions for tools
    26     $('form').on('submit', function() {
    27         const action = $(this).find('button[type="submit"]:focus').val();
    28        
    29         if (action === 'optimize_database') {
    30             if (typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmOptimize) {
    31                 if (!confirm(SPEEDORAData.confirmOptimize)) {
     28        // Handle form submissions for our plugin tools/settings only.
     29        $( '#SPEEDORA-settings-form, .SPEEDORA-tools form' ).on( 'submit', function() {
     30            var $form  = $( this );
     31            var $btn   = $form.find( 'button[type="submit"]:focus' );
     32            var action = $btn.length ? $btn.val() : $form.find( 'input[name="action"]' ).val();
     33
     34            if ( ! action ) {
     35                return true;
     36            }
     37
     38            if ( action === 'optimize_database' ) {
     39                var msg = 'This may take a while. Continue?';
     40                if ( typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmOptimize ) {
     41                    msg = SPEEDORAData.confirmOptimize;
     42                }
     43                if ( ! window.confirm( msg ) ) {
    3244                    return false;
    3345                }
    34             } else if (!confirm('This may take a while. Continue?')) {
    35                 return false;
    3646            }
    37         }
    3847
    39         if (action === 'clear_cache') {
    40             if (typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmClear) {
    41                 if (!confirm(SPEEDORAData.confirmClear)) {
     48            if ( action === 'clear_cache' ) {
     49                var clearMsg = 'Are you sure you want to clear all cache?';
     50                if ( typeof SPEEDORAData !== 'undefined' && SPEEDORAData.confirmClear ) {
     51                    clearMsg = SPEEDORAData.confirmClear;
     52                }
     53                if ( ! window.confirm( clearMsg ) ) {
    4254                    return false;
    4355                }
    44             } else if (!confirm('Are you sure you want to clear all cache?')) {
    45                 return false;
    4656            }
     57
     58            return true;
     59        } );
     60
     61        // Placeholder: SPEEDORAData may carry extra info for future AJAX ops.
     62        if ( typeof SPEEDORAData !== 'undefined' ) {
     63            // No-op for now.
    4764        }
    48     });
    49 
    50     // AJAX handlers for async operations
    51     if (typeof SPEEDORAData !== 'undefined') {
    52         // You can add AJAX handlers here for async operations
     65    } catch ( e ) {
     66        // Swallow any unexpected errors to avoid breaking the admin console.
     67        if ( window && window.console && console.error ) {
     68            console.error( 'Speedora admin script error:', e );
     69        }
    5370    }
    54 
    55     // Show success/error messages
    56     if (typeof wp !== 'undefined' && wp.notices) {
    57         // Notices are handled by WordPress
    58     }
    59 });
     71} );
    6072
    6173
  • speedora-total-website-speed-optimization/trunk/includes/class-minify.php

    r3483024 r3483242  
    1919     */
    2020    public static function SPEEDORA_setup_minification() {
     21        // Never touch admin area scripts/styles – avoid breaking block editor and core JS.
     22        if ( is_admin() ) {
     23            return;
     24        }
     25
    2126        if ( SPEEDORA_Settings::SPEEDORA_is_optimization_enabled( 'minify_html' ) ) {
    2227            add_filter( 'the_content', array( self::class, 'SPEEDORA_minify_html' ) );
     
    162167     */
    163168    public static function SPEEDORA_modify_script_tags( $tag, $handle ) {
     169        // Do not modify script tags in admin; many core scripts rely on exact loading order.
     170        if ( is_admin() ) {
     171            return $tag;
     172        }
    164173        // Get excluded scripts that should not be deferred/async
    165174        $excluded = array( 'jquery-core', 'jquery' );
Note: See TracChangeset for help on using the changeset viewer.