ptimize_cdn_url", "autoptimize_cachesize_notice","autoptimize_css_include_inline","autoptimize_js_include_inline","autoptimize_css_nogooglefont"); if ( !is_multisite() ) { foreach ($delete_options as $del_opt) { delete_option( $del_opt ); } } else { global $wpdb; $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); $original_blog_id = get_current_blog_id(); foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); foreach ($delete_options as $del_opt) { delete_option( $del_opt ); } } switch_to_blog( $original_blog_id ); } if ( wp_get_schedule( 'ao_cachechecker' ) ) { wp_clear_scheduled_hook( 'ao_cachechecker' ); } } function autoptimize_install_config_notice() { echo '

'; _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); echo '

'; } function autoptimize_update_config_notice() { echo '

'; _e('Autoptimize has just been updated. Please test your site now and adapt Autoptimize config if needed.', 'autoptimize' ); echo '

'; } function autoptimize_cache_unavailable_notice() { echo '

'; _e('Autoptimize cannot write to the cache directory (default: /wp-content/cache/autoptimize), please fix to enable CSS/ JS optimization!', 'autoptimize' ); echo '

'; } // Set up the buffering function autoptimize_start_buffering() { $ao_noptimize = false; // noptimize in qs to get non-optimized page for debugging if (array_key_exists("ao_noptimize",$_GET)) { if ($_GET["ao_noptimize"]==="1") { $ao_noptimize = true; } } // check for DONOTMINIFY constant as used by e.g. WooCommerce POS if (defined('DONOTMINIFY') && (constant('DONOTMINIFY')===true || constant('DONOTMINIFY')==="true")) { $ao_noptimize = true; } // filter you can use to block autoptimization on your own terms $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); if (!is_feed() && !$ao_noptimize && !is_admin()) { // Config element $conf = autoptimizeConfig::instance(); // Load our base class include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeBase.php'); // Load extra classes and set some vars if($conf->get('autoptimize_html')) { include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeHTML.php'); // BUG: new minify-html does not support keeping HTML comments, skipping for now // if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) { @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/minify-html.php'); // } else { // @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/minify-2.1.7-html.php'); // } } if($conf->get('autoptimize_js')) { include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeScripts.php'); if (!class_exists('JSMin')) { if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) { @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/jsmin-1.1.1.php'); } else { @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/minify-2.1.7-jsmin.php'); } } if ( ! defined( 'CONCATENATE_SCRIPTS' )) { define('CONCATENATE_SCRIPTS',false); } if ( ! defined( 'COMPRESS_SCRIPTS' )) { define('COMPRESS_SCRIPTS',false); } } if($conf->get('autoptimize_css')) { include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeStyles.php'); if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) { if (!class_exists('Minify_CSS_Compressor')) { @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/minify-css-compressor.php'); } } else { if (!class_exists('CSSmin')) { @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/yui-php-cssmin-2.4.8-4_fgo.php'); } } if ( ! defined( 'COMPRESS_CSS' )) { define('COMPRESS_CSS',false); } } // Now, start the real thing! ob_start('autoptimize_end_buffering'); } } // Action on end, this is where the magic happens function autoptimize_end_buffering($content) { if ( stripos($content,"get('autoptimize_js')) $classes[] = 'autoptimizeScripts'; if($conf->get('autoptimize_css')) $classes[] = 'autoptimizeStyles'; if($conf->get('autoptimize_html')) $classes[] = 'autoptimizeHTML'; // Set some options $classoptions = array( 'autoptimizeScripts' => array( 'justhead' => $conf->get('autoptimize_js_justhead'), 'forcehead' => $conf->get('autoptimize_js_forcehead'), 'trycatch' => $conf->get('autoptimize_js_trycatch'), 'js_exclude' => $conf->get('autoptimize_js_exclude'), 'cdn_url' => $conf->get('autoptimize_cdn_url'), 'include_inline' => $conf->get('autoptimize_js_include_inline') ), 'autoptimizeStyles' => array( 'justhead' => $conf->get('autoptimize_css_justhead'), 'datauris' => $conf->get('autoptimize_css_datauris'), 'defer' => $conf->get('autoptimize_css_defer'), 'defer_inline' => $conf->get('autoptimize_css_defer_inline'), 'inline' => $conf->get('autoptimize_css_inline'), 'css_exclude' => $conf->get('autoptimize_css_exclude'), 'cdn_url' => $conf->get('autoptimize_cdn_url'), 'include_inline' => $conf->get('autoptimize_css_include_inline'), 'nogooglefont' => $conf->get('autoptimize_css_nogooglefont') ), 'autoptimizeHTML' => array( 'keepcomments' => $conf->get('autoptimize_html_keepcomments') ) ); $content = apply_filters( 'autoptimize_filter_html_before_minify', $content ); // Run the classes foreach($classes as $name) { $instance = new $name($content); if($instance->read($classoptions[$name])) { $instance->minify(); $instance->cache(); $content = $instance->getcontent(); } unset($instance); } $content = apply_filters( 'autoptimize_html_after_minify', $content ); return $content; } function autoptimize_flush_pagecache($nothing) { if(function_exists('wp_cache_clear_cache')) { if (is_multisite()) { $blog_id = get_current_blog_id(); wp_cache_clear_cache($blog_id); } else { wp_cache_clear_cache(); } } else if ( has_action('cachify_flush_cache') ) { do_action('cachify_flush_cache'); } else if ( function_exists('w3tc_pgcache_flush') ) { w3tc_pgcache_flush(); // w3 total cache } else if ( function_exists('hyper_cache_invalidate') ) { hyper_cache_invalidate(); // hypercache } else if ( function_exists('wp_fast_cache_bulk_delete_all') ) { wp_fast_cache_bulk_delete_all(); // wp fast cache } else if (class_exists("WpFastestCache")) { $wpfc = new WpFastestCache(); // wp fastest cache $wpfc -> deleteCache(); } else if ( class_exists("c_ws_plugin__qcache_purging_routines") ) { c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache } else if ( class_exists("zencache")) { zencache::clear(); // zen cache } else if(file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')){ // fallback for WP-Super-Cache global $cache_path; if (is_multisite()) { $blog_id = get_current_blog_id(); prune_super_cache( get_supercache_dir( $blog_id ), true ); prune_super_cache( $cache_path . 'blogs/', true ); } else { prune_super_cache($cache_path.'supercache/',true); prune_super_cache($cache_path,true); } } } add_action('ao_flush_pagecache','autoptimize_flush_pagecache',10,1); if ( autoptimizeCache::cacheavail() ) { $conf = autoptimizeConfig::instance(); if( $conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') ) { // Hook to wordpress if (defined('AUTOPTIMIZE_INIT_EARLIER')) { add_action('init','autoptimize_start_buffering',-1); } else { add_action('template_redirect','autoptimize_start_buffering',2); } } } else { add_action('admin_notices', 'autoptimize_cache_unavailable_notice'); } register_uninstall_hook(__FILE__, "autoptimize_uninstall"); include_once('classlesses/autoptimizeCacheChecker.php'); // Do not pollute other plugins unset($conf);