| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Autoptimize Helper |
| 4 |
Plugin URI: http://blog.futtta.be/autoptimize |
| 5 |
Description: Autoptimize Helper contains some helper functions to make Autoptimize even more flexible |
| 6 |
Author: Frank Goossens (futtta) |
| 7 |
Version: 0.2 |
| 8 |
Author URI: http://blog.futtta.be/ |
| 9 |
*/ |
| 10 |
|
| 11 |
/* autoptimize_filter_css_datauri_maxsize: change the threshold at which background images are turned into data uri's; |
| 12 |
|
| 13 |
@param $urisize: default size |
| 14 |
@return: your own preferred size */ |
| 15 |
// add_filter('autoptimize_filter_css_datauri_maxsize','my_ao_override_dataursize',10,1); |
| 16 |
function my_ao_override_dataursize($urisizeIn) { |
| 17 |
return 100000; |
| 18 |
} |
| 19 |
|
| 20 |
/* autoptimize_filter_css_datauri_exclude: exclude background images from being turned into data uri's; |
| 21 |
|
| 22 |
@param $imageexcl: default images excluded (empty) |
| 23 |
@return: comma-seperated list of images to exclude */ |
| 24 |
// add_filter('autoptimize_filter_css_datauri_exclude','my_ao_exclude_image',10,1); |
| 25 |
function my_ao_exclude_image($imageexcl) { |
| 26 |
return $imageexcl . ", adfreebutton.jpg, otherimage.png"; |
| 27 |
} |
| 28 |
|
| 29 |
/* autoptimize_filter_js_defer: change flag added to javascript |
| 30 |
|
| 31 |
@param $defer: default value, "" when forced in head, "defer " when not forced in head |
| 32 |
@return: new value */ |
| 33 |
// add_filter('autoptimize_filter_js_defer','my_ao_override_defer',10,1); |
| 34 |
function my_ao_override_defer($defer) { |
| 35 |
return $defer."async "; |
| 36 |
} |
| 37 |
|
| 38 |
/* autoptimize_filter_noptimize: stop autoptimize from optimizing, e.g. based on URL as in example |
| 39 |
|
| 40 |
@return: boolean, true or false */ |
| 41 |
// add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,1); |
| 42 |
function my_ao_noptimize( $flag_in ) { |
| 43 |
if (strpos($_SERVER['REQUEST_URI'],'no-autoptimize-now')!==false) { |
| 44 |
return true; |
| 45 |
} else { |
| 46 |
return $flag_in; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/* autoptimize_filter_js_exclude; JS optimization exclude strings, as configured in admin page |
| 51 |
|
| 52 |
@param $exclude: comma-seperated list of exclude strings |
| 53 |
@return: comma-seperated list of exclude strings */ |
| 54 |
// add_filter('autoptimize_filter_js_exclude','my_ao_override_jsexclude',10,1); |
| 55 |
function my_ao_override_jsexclude($exclude) { |
| 56 |
return $exclude.", customize-support"; |
| 57 |
} |
| 58 |
|
| 59 |
/* autoptimize_filter_css_exclude: CSS optimization exclude strings, as configured in admin page |
| 60 |
|
| 61 |
@param $exclude: comma-seperated list of exclude strings |
| 62 |
@return: comma-seperated list of exclude strings */ |
| 63 |
// add_filter('autoptimize_filter_css_exclude','my_ao_override_cssexclude',10,1); |
| 64 |
function my_ao_override_cssexclude($exclude) { |
| 65 |
return $exclude.", recentcomments"; |
| 66 |
} |
| 67 |
|
| 68 |
/* autoptimize_filter_js_movelast: internal array of what script can be moved to the bottom of the HTML |
| 69 |
|
| 70 |
@param array $movelast |
| 71 |
@return: updated array */ |
| 72 |
// add_filter('autoptimize_filter_js_movelast','my_ao_override_movelast',10,1); |
| 73 |
function my_ao_override_movelast($movelast) { |
| 74 |
$movelast[]="console.log"; |
| 75 |
return $movelast; |
| 76 |
} |
| 77 |
|
| 78 |
/* autoptimize_filter_css_replacetag: where in the HTML is optimized CSS injected |
| 79 |
|
| 80 |
@param array $replacetag, containing the html-tag and the method (inject "before", "after" or "replace") |
| 81 |
@return array with updated values */ |
| 82 |
// add_filter('autoptimize_filter_css_replacetag','my_ao_override_css_replacetag',10,1); |
| 83 |
function my_ao_override_css_replacetag($replacetag) { |
| 84 |
return array("<head>","after"); |
| 85 |
} |
| 86 |
|
| 87 |
/* autoptimize_filter_js_replacetag: where in the HTML is optimized JS injected |
| 88 |
|
| 89 |
@param array $replacetag, containing the html-tag and the method (inject "before", "after" or "replace") |
| 90 |
@return array with updated values */ |
| 91 |
// add_filter('autoptimize_filter_js_replacetag','my_ao_override_js_replacetag',10,1); |
| 92 |
function my_ao_override_js_replacetag($replacetag) { |
| 93 |
return array("<injectjs />","replace"); |
| 94 |
} |
| 95 |
|
| 96 |
/* autoptimize_js_do_minify: do we want to minify? if set to false autoptimize effectively only aggregates, but does not minify |
| 97 |
|
| 98 |
@return: boolean true or false */ |
| 99 |
// add_filter('autoptimize_js_do_minify','my_ao_js_minify',10,1); |
| 100 |
function my_ao_js_minify() { |
| 101 |
return false; |
| 102 |
} |
| 103 |
|
| 104 |
/* autoptimize_css_do_minify: do we want to minify? if set to false autoptimize effectively only aggregates, but does not minify |
| 105 |
|
| 106 |
@return: boolean true or false */ |
| 107 |
// add_filter('autoptimize_css_do_minify','my_ao_css_minify',10,1); |
| 108 |
function my_ao_css_minify() { |
| 109 |
return false; |
| 110 |
} |
| 111 |
|
| 112 |
/* autoptimize_js_include_inline: do we want AO to also aggregate inline JS? |
| 113 |
|
| 114 |
@return: boolean true or false */ |
| 115 |
// add_filter('autoptimize_js_include_inline','my_ao_js_include_inline',10,1); |
| 116 |
function my_ao_js_include_inline() { |
| 117 |
return false; |
| 118 |
} |
| 119 |
|
| 120 |
/* autoptimize_css_include_inline: do we want AO to also aggregate inline CSS? |
| 121 |
|
| 122 |
@return: boolean true or false */ |
| 123 |
// add_filter('autoptimize_css_include_inline','my_ao_css_include_inline',10,1); |
| 124 |
function my_ao_css_include_inline() { |
| 125 |
return false; |
| 126 |
} |
| 127 |
|
| 128 |
/* autoptimize_filter_css_defer_inline: what CSS to inline when "defer and inline" is activated |
| 129 |
|
| 130 |
@param $inlined: string with above the fold CSS as configured in admin |
| 131 |
@return: updated string with above the fold CSS */ |
| 132 |
// add_filter('autoptimize_filter_css_defer_inline','my_ao_css_defer_inline',10,1); |
| 133 |
function my_ao_css_defer_inline($inlined) { |
| 134 |
return $inlined."h2,h1{color:red !important;}"; |
| 135 |
} |
| 136 |
|
| 137 |
/* autoptimize_filter_css_fonts_cdn: do we want to move fonts to the CDN-url as well |
| 138 |
|
| 139 |
@return: false (default) or true */ |
| 140 |
// add_filter('autoptimize_filter_css_fonts_cdn','my_css_cdnfont',10,0); |
| 141 |
function my_css_cdnfont(){ |
| 142 |
return true; |
| 143 |
} |
| 144 |
|