Plugin Directory

Changeset 1966596


Ignore:
Timestamp:
10/31/2018 04:27:09 PM (7 years ago)
Author:
seismicpixels
Message:

1.8.8 trunk commit

Location:
optimize-scripts-styles/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • optimize-scripts-styles/trunk/library/functions.php

    r1938888 r1966596  
    2727/* ACTIONS & FILTERS */
    2828if ( $remove_scripts ) {
    29     add_action( 'wp_print_scripts', 'spos_dequeue_scripts', 99 );
    30     add_action( 'wp_footer', 'spos_dequeue_scripts', 19 ); // some additional scripts may be added after wp_print_scripts
     29    add_action( 'wp_print_scripts', 'spos_dequeue_scripts', 98 );
     30    add_action( 'wp_footer', 'spos_dequeue_scripts', 18 ); // some additional scripts may be added after wp_print_scripts
    3131}
    3232
    3333if ( $remove_styles ) {
    34     add_action( 'wp_print_styles', 'spos_dequeue_styles', 99 );
     34    add_action( 'wp_print_styles', 'spos_dequeue_styles', 98 );
    3535}
    3636
     
    135135function spos_minify_head_scripts() {
    136136    global $spos_settings;
    137     if ( !is_admin() ) {
     137    if ( !is_admin() && !isset( $spos_settings['processed_header'] ) ) {
    138138        $start_time = microtime(true);
    139139        global $wp_scripts;
     
    163163            // this helps to eliminate problems with php files masquerading as javascript
    164164            if ( substr( $wp_scripts->registered[$script_name]->src, -3 ) !== '.js' ) continue;
    165            
     165
    166166            $footer = isset( $wp_scripts->registered[$script_name]->extra['group'] ) && $wp_scripts->registered[$script_name]->extra['group'] == 1 ? true : false;
    167167            if ( !$footer &&
     
    184184        $data = rtrim( $data, "\r\n" );
    185185        if ( !empty( $data ) ) {
    186             echo '<script type="text/javascript">' . "\r\n" . '/* <![CDATA[ */' . "\r\n" . $data . "\r\n" . '/* ]]> */' . "\r\n" . '</script>' . "\r\n";
     186            $stype = $remove_script_type ? '' : ' type="text/javascript"';
     187            echo '<script' . $stype . '>' . "\r\n" . '/* <![CDATA[ */' . "\r\n" . $data . "\r\n" . '/* ]]> */' . "\r\n" . '</script>' . "\r\n";
    187188        }           
    188189       
     
    197198            // remove existing scripts since they are included in the stored files
    198199            foreach ( $header_scripts as $script_name ) {
     200                $wp_scripts->done[] = $wp_scripts->registered[$script_name]->handle;
    199201                wp_dequeue_script( $wp_scripts->registered[$script_name]->handle );
    200                 $wp_scripts->done[] = $wp_scripts->registered[$script_name]->handle;
    201202            }
    202203           
     
    204205            $script_url = WP_CONTENT_URL . '/cache/scripts/' . $md5;
    205206            if ( file_exists( $script_path . '.header.js' ) ) {
    206                 wp_register_script( 'min-header', $script_url . '.header.js', '', filemtime( $script_path . '.header.js' ), false );               
    207                 wp_enqueue_script( 'min-header' );
     207                wp_register_script( 'min-' . $md5, $script_url . '.header.js', '', filemtime( $script_path . '.header.js' ), false );               
     208                wp_enqueue_script( 'min-' . $md5 );
    208209            }
    209210                   
     
    292293                fclose( $script_file );
    293294
    294                 wp_register_script( 'min-header', $script_url, '', filemtime( $script_path ), $footer );
    295                 wp_enqueue_script( 'min-header' );
     295                wp_register_script( 'min-' . $md5, $script_url, '', filemtime( $script_path ), $footer );
     296                wp_enqueue_script( 'min-' . $md5 );             
    296297           
    297298                // flag file
     
    299300                $execution_time = ( $end_time - $start_time );
    300301                $gmt_offset = get_option('gmt_offset');
    301                 $info = 'Cached ' . date('l jS \of F Y h:i:s A', time() + ( $gmt_offset * 60 * 60 ) ) . "\r\n" . 'Post Type: ' . get_post_type() . "\r\n" . 'Includes: ' . implode( ', ', $included_scripts ) . "\r\n" . 'Execution time: ' . $execution_time . ' seconds' ;
     302                $info = 'Cached ' . date('l jS \of F Y h:i:s A', time() + ( $gmt_offset * 60 * 60 ) ) . "\r\n";
     303                    $info .= 'Initial ' . ucfirst( get_post_type() ) . ': ' . get_the_title() . "\r\n";
     304                    $info .= 'Location: Header' . "\r\n";
     305                    $info .= 'Includes: ' . implode( ', ', $included_scripts ) . "\r\n";
     306                    $info .= 'Execution time: ' . $execution_time . ' seconds';
    302307
    303308                //$flag_path = WP_CONTENT_DIR . '/cache/scripts/' . $md5 . '.txt';
     
    305310                fwrite( $flag_file, $info );
    306311                fclose( $flag_file );
    307            
    308             }
    309         }
     312
     313                if ( $testing ) {
     314                    echo '<pre>' . $info . '</pre>';
     315                }
     316           
     317            }
     318        }
     319   
     320        // set processed_header = true so this only runs once
     321        $spos_settings['processed_header'] = true;
    310322    }
    311323}
     
    347359        $data = rtrim( $data, "\r\n" );
    348360        if ( !empty( $data ) ) {
    349             echo '<script>' . "\r\n" . '/* <![CDATA[ */' . "\r\n" . $data . "\r\n" . '/* ]]> */' . "\r\n" . '</script>' . "\r\n";
     361            $stype = $remove_script_type ? '' : ' type="text/javascript"';
     362            echo '<script' . $stype . '>' . "\r\n" . '/* <![CDATA[ */' . "\r\n" . $data . "\r\n" . '/* ]]> */' . "\r\n" . '</script>' . "\r\n";
    350363        }
    351364       
     
    385398            $script_url = WP_CONTENT_URL . '/cache/scripts/' . $md5;
    386399            if ( file_exists( $script_path . '.footer.js' ) ) {
    387                 wp_register_script( 'min-footer', $script_url . '.footer.js', '', filemtime( $script_path . '.footer.js' ), true );             
    388                 wp_enqueue_script( 'min-footer' );
     400                wp_register_script( 'min-', $script_url . '.footer.js', '', filemtime( $script_path . '.footer.js' ), true );               
     401                wp_enqueue_script( 'min-' );
    389402            }
    390403                   
     
    478491                fclose( $script_file );
    479492
    480                 wp_register_script( 'min-footer', $script_url, '', filemtime( $script_path ), $footer );
    481                 wp_enqueue_script( 'min-footer' );
     493                wp_register_script( 'min-', $script_url, '', filemtime( $script_path ), $footer );
     494                wp_enqueue_script( 'min-' );
    482495               
    483496                // flag file
     
    485498                $execution_time = ( $end_time - $start_time );
    486499                $gmt_offset = get_option('gmt_offset');
    487                 $info = 'Cached ' . date('l jS \of F Y h:i:s A', time() + ( $gmt_offset * 60 * 60 ) ) . "\r\n" . 'Post Type: ' . get_post_type() . "\r\n" . 'Includes: ' . implode( ', ', $included_scripts ) . "\r\n" . 'Execution time: ' . $execution_time . ' seconds' ;
     500                $info = 'Cached ' . date('l jS \of F Y h:i:s A', time() + ( $gmt_offset * 60 * 60 ) ) . "\r\n";
     501                    $info .= 'Initial ' . ucfirst( get_post_type() ) . ': ' . get_the_title() . "\r\n";
     502                    $info .= 'Location: Footer' . "\r\n";
     503                    $info .= 'Includes: ' . implode( ', ', $included_scripts ) . "\r\n";
     504                    $info .= 'Execution time: ' . $execution_time . ' seconds';
    488505
    489506                //$flag_path = WP_CONTENT_DIR . '/cache/scripts/' . $md5;
     
    491508                fwrite( $flag_file, $info );
    492509                fclose( $flag_file );
     510
     511                if ( $testing ) {
     512                    echo '<pre>' . $info . '</pre>';
     513                }
    493514            }
    494515           
     
    674695                $execution_time = ( $end_time - $start_time );
    675696                $gmt_offset = get_option('gmt_offset');
    676                 $info = 'Cached ' . date('l jS \of F Y h:i:s A', time() + ( $gmt_offset * 60 * 60 ) ). "\r\n" . 'Post Type: ' . get_post_type() . "\r\n" . 'Includes: ' . implode( ', ', $included_styles ) . "\r\n" . 'Execution time: ' . $execution_time . ' seconds';
     697                $info = 'Cached ' . date('l jS \of F Y h:i:s A', time() + ( $gmt_offset * 60 * 60 ) ). "\r\n";
     698                    $info .= 'Initial ' . ucfirst( get_post_type() ) . ': ' . get_the_title() . "\r\n";
     699                    $info .= 'Includes: ' . implode( ', ', $included_styles ) . "\r\n";
     700                    $info .= 'Execution time: ' . $execution_time . ' seconds';
     701
    677702                //$flag_path = WP_CONTENT_DIR . '/cache/styles/' . $md5;
    678703                $flag_file = fopen( $flag_path, 'w' );
  • optimize-scripts-styles/trunk/library/pages/spos-admin.php

    r1938888 r1966596  
    167167                        foreach ( $files as $filename ) {
    168168                            echo '<strong>Hash: ' . str_replace( array($dir,'.txt'), '', $filename ) . '</strong><br />';
    169                             $contents = file_get_contents( $filename );
    170                             echo '<pre>' . sanitize_textarea_field( $contents ) . '</pre><br /><br />';
     169                            $contents = sanitize_textarea_field( file_get_contents( $filename ) );
     170                            echo '<pre>' . $contents . '</pre><br /><br />';
    171171                        }
    172172                    } else {
     
    186186                        foreach ( $files as $filename ) {
    187187                            echo '<strong>Hash: ' . str_replace( array($dir,'.txt'), '', $filename ) . '</strong><br />';
    188                             $contents = file_get_contents( $filename );
    189                             echo '<pre>' . sanitize_textarea_field( $contents ) . '</pre><br /><br />';
     188                            $contents = sanitize_textarea_field( file_get_contents( $filename ) );
     189                            echo '<pre>' . $contents . '</pre><br /><br />';
    190190                        }               
    191191                    } else {
  • optimize-scripts-styles/trunk/readme.txt

    r1938888 r1966596  
    44Tags: scripts, styles, optimize, optimization, minify, compress, seo, performance, combine
    55Requires at least: 4.0
    6 Tested up to: 4.9.8
     6Tested up to: 4.9.7
    77Requires PHP: 5.6
    8 Stable tag: 1.8.7
     8Stable tag: 1.8.8
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    9191== Changelog ==
    9292
     93= 1.8.8 =
     94* Tweaked localized script output to only remove the type='text/javscript' if that option is set in the admin
     95* Added location (header or footer) to the cached files description
     96* The plugin no longer initializes on AJAX requests
     97* Added a hash to the script handles to allow them be unique
     98* The header scripts optimization now only runs once. This fixes issues with plugins like Gravity Forms loading their AJAX scripts using the same hooks. Their inline scripts now load as intended, but are not optimized. This is safer since they call inline code that relies on their scripts being loaded, and users won't need to add the handles to the Ignore Scripts section of this plugin.
     99
    93100= 1.8.7 =
    94101* [New Feature] Added an option to remove type='text/javscript' from script tags so that HTML5 sites can be W3C compliant (other optimizations may be needed)
     102* [New Feature] Added an option to remove type='text/css' from style tags so that HTML5 sites can be W3C compliant (other optimizations may be needed)
    95103* [New Feature] Added an option to REMOVE scripts and/or styles. Add script or style handles to the list and they will no longer load for the site
    96 * Modified the Clear Optimize Scripts action to better handle a variety of existing query string formats*
    97 * Removed the type='text/javscript' that SPOS scripts output
     104* Modified the Clear Optimize Scripts action to better handle a variety of existing query string formats
     105* Removed the type='text/javscript' that SPOS scripts output for localized data
    98106* Cosmetic udpates to the admin area
    99107* Added a Refresh button to the cached files area for easier testing
  • optimize-scripts-styles/trunk/sp-optimize-scripts.php

    r1938888 r1966596  
    33 * Plugin Name: Optimize Scripts & Styles
    44 * Description: Provides a quick way to combine and minify all scripts and styles and cache them in your content folder.
    5  * Version: 1.8.7
     5 * Version: 1.8.8
    66 * Author: Seismic Pixels
    77 * Author URI: http://www.seismicpixels.com
     
    1111global $spos_version;
    1212//global $spos_db_version;
    13 $spos_version = '1.8.7';
     13$spos_version = '1.8.8';
    1414
    1515//global $spos_dir;
     
    3535    }
    3636}
    37 add_action( 'init', 'spos_init', 100 );
     37if ( !wp_doing_ajax() ) {
     38    add_action( 'init', 'spos_init', 100 );
     39}
    3840
    3941function spos_activation_hook() {
Note: See TracChangeset for help on using the changeset viewer.