Changeset 1966596
- Timestamp:
- 10/31/2018 04:27:09 PM (7 years ago)
- Location:
- optimize-scripts-styles/trunk
- Files:
-
- 4 edited
-
library/functions.php (modified) (15 diffs)
-
library/pages/spos-admin.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
sp-optimize-scripts.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
optimize-scripts-styles/trunk/library/functions.php
r1938888 r1966596 27 27 /* ACTIONS & FILTERS */ 28 28 if ( $remove_scripts ) { 29 add_action( 'wp_print_scripts', 'spos_dequeue_scripts', 9 9);30 add_action( 'wp_footer', 'spos_dequeue_scripts', 1 9); // some additional scripts may be added after wp_print_scripts29 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 31 31 } 32 32 33 33 if ( $remove_styles ) { 34 add_action( 'wp_print_styles', 'spos_dequeue_styles', 9 9);34 add_action( 'wp_print_styles', 'spos_dequeue_styles', 98 ); 35 35 } 36 36 … … 135 135 function spos_minify_head_scripts() { 136 136 global $spos_settings; 137 if ( !is_admin() ) {137 if ( !is_admin() && !isset( $spos_settings['processed_header'] ) ) { 138 138 $start_time = microtime(true); 139 139 global $wp_scripts; … … 163 163 // this helps to eliminate problems with php files masquerading as javascript 164 164 if ( substr( $wp_scripts->registered[$script_name]->src, -3 ) !== '.js' ) continue; 165 165 166 166 $footer = isset( $wp_scripts->registered[$script_name]->extra['group'] ) && $wp_scripts->registered[$script_name]->extra['group'] == 1 ? true : false; 167 167 if ( !$footer && … … 184 184 $data = rtrim( $data, "\r\n" ); 185 185 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"; 187 188 } 188 189 … … 197 198 // remove existing scripts since they are included in the stored files 198 199 foreach ( $header_scripts as $script_name ) { 200 $wp_scripts->done[] = $wp_scripts->registered[$script_name]->handle; 199 201 wp_dequeue_script( $wp_scripts->registered[$script_name]->handle ); 200 $wp_scripts->done[] = $wp_scripts->registered[$script_name]->handle;201 202 } 202 203 … … 204 205 $script_url = WP_CONTENT_URL . '/cache/scripts/' . $md5; 205 206 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 ); 208 209 } 209 210 … … 292 293 fclose( $script_file ); 293 294 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 ); 296 297 297 298 // flag file … … 299 300 $execution_time = ( $end_time - $start_time ); 300 301 $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'; 302 307 303 308 //$flag_path = WP_CONTENT_DIR . '/cache/scripts/' . $md5 . '.txt'; … … 305 310 fwrite( $flag_file, $info ); 306 311 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; 310 322 } 311 323 } … … 347 359 $data = rtrim( $data, "\r\n" ); 348 360 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"; 350 363 } 351 364 … … 385 398 $script_url = WP_CONTENT_URL . '/cache/scripts/' . $md5; 386 399 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-' ); 389 402 } 390 403 … … 478 491 fclose( $script_file ); 479 492 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-' ); 482 495 483 496 // flag file … … 485 498 $execution_time = ( $end_time - $start_time ); 486 499 $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'; 488 505 489 506 //$flag_path = WP_CONTENT_DIR . '/cache/scripts/' . $md5; … … 491 508 fwrite( $flag_file, $info ); 492 509 fclose( $flag_file ); 510 511 if ( $testing ) { 512 echo '<pre>' . $info . '</pre>'; 513 } 493 514 } 494 515 … … 674 695 $execution_time = ( $end_time - $start_time ); 675 696 $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 677 702 //$flag_path = WP_CONTENT_DIR . '/cache/styles/' . $md5; 678 703 $flag_file = fopen( $flag_path, 'w' ); -
optimize-scripts-styles/trunk/library/pages/spos-admin.php
r1938888 r1966596 167 167 foreach ( $files as $filename ) { 168 168 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 />'; 171 171 } 172 172 } else { … … 186 186 foreach ( $files as $filename ) { 187 187 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 />'; 190 190 } 191 191 } else { -
optimize-scripts-styles/trunk/readme.txt
r1938888 r1966596 4 4 Tags: scripts, styles, optimize, optimization, minify, compress, seo, performance, combine 5 5 Requires at least: 4.0 6 Tested up to: 4.9. 86 Tested up to: 4.9.7 7 7 Requires PHP: 5.6 8 Stable tag: 1.8. 78 Stable tag: 1.8.8 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 91 91 == Changelog == 92 92 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 93 100 = 1.8.7 = 94 101 * [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) 95 103 * [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 98 106 * Cosmetic udpates to the admin area 99 107 * Added a Refresh button to the cached files area for easier testing -
optimize-scripts-styles/trunk/sp-optimize-scripts.php
r1938888 r1966596 3 3 * Plugin Name: Optimize Scripts & Styles 4 4 * Description: Provides a quick way to combine and minify all scripts and styles and cache them in your content folder. 5 * Version: 1.8. 75 * Version: 1.8.8 6 6 * Author: Seismic Pixels 7 7 * Author URI: http://www.seismicpixels.com … … 11 11 global $spos_version; 12 12 //global $spos_db_version; 13 $spos_version = '1.8. 7';13 $spos_version = '1.8.8'; 14 14 15 15 //global $spos_dir; … … 35 35 } 36 36 } 37 add_action( 'init', 'spos_init', 100 ); 37 if ( !wp_doing_ajax() ) { 38 add_action( 'init', 'spos_init', 100 ); 39 } 38 40 39 41 function spos_activation_hook() {
Note: See TracChangeset
for help on using the changeset viewer.