| 1 |
<?php |
| 2 |
/* |
| 3 |
* below code handles updates and is only included by autoptimize.php if/ when needed |
| 4 |
*/ |
| 5 |
|
| 6 |
$majorUp = false; |
| 7 |
$autoptimize_major_version=substr($autoptimize_db_version,0,3); |
| 8 |
|
| 9 |
switch($autoptimize_major_version) { |
| 10 |
case "1.6": |
| 11 |
// from back in the days when I did not yet consider multisite |
| 12 |
// if user was on version 1.6.x, force advanced options to be shown by default |
| 13 |
update_option('autoptimize_show_adv','1'); |
| 14 |
|
| 15 |
// and remove old options |
| 16 |
$to_delete_options=array("autoptimize_cdn_css","autoptimize_cdn_css_url","autoptimize_cdn_js","autoptimize_cdn_js_url","autoptimize_cdn_img","autoptimize_cdn_img_url","autoptimize_css_yui","autoptimize_js_yui"); |
| 17 |
foreach ($to_delete_options as $del_opt) { |
| 18 |
delete_option( $del_opt ); |
| 19 |
} |
| 20 |
$majorUp = true; |
| 21 |
case "1.7": |
| 22 |
// force 3.8 dashicons in CSS exclude options when upgrading from 1.7 to 1.8 |
| 23 |
if ( !is_multisite() ) { |
| 24 |
$css_exclude = get_option('autoptimize_css_exclude'); |
| 25 |
if (empty($css_exclude)) { |
| 26 |
$css_exclude = "admin-bar.min.css, dashicons.min.css"; |
| 27 |
} else if (strpos($css_exclude,"dashicons.min.css")===false) { |
| 28 |
$css_exclude .= ", dashicons.min.css"; |
| 29 |
} |
| 30 |
update_option('autoptimize_css_exclude',$css_exclude); |
| 31 |
} else { |
| 32 |
global $wpdb; |
| 33 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 34 |
$original_blog_id = get_current_blog_id(); |
| 35 |
foreach ( $blog_ids as $blog_id ) { |
| 36 |
switch_to_blog( $blog_id ); |
| 37 |
$css_exclude = get_option('autoptimize_css_exclude'); |
| 38 |
if (empty($css_exclude)) { |
| 39 |
$css_exclude = "admin-bar.min.css, dashicons.min.css"; |
| 40 |
} else if (strpos($css_exclude,"dashicons.min.css")===false) { |
| 41 |
$css_exclude .= ", dashicons.min.css"; |
| 42 |
} |
| 43 |
update_option('autoptimize_css_exclude',$css_exclude); |
| 44 |
} |
| 45 |
switch_to_blog( $original_blog_id ); |
| 46 |
} |
| 47 |
$majorUp = true; |
| 48 |
case "1.9": |
| 49 |
/* |
| 50 |
* 2.0 will not aggregate inline CSS/JS by default, but we want users |
| 51 |
* upgrading from 1.9 to keep their inline code aggregated by default. |
| 52 |
*/ |
| 53 |
if ( !is_multisite() ) { |
| 54 |
update_option('autoptimize_css_include_inline','on'); |
| 55 |
update_option('autoptimize_js_include_inline','on'); |
| 56 |
} else { |
| 57 |
global $wpdb; |
| 58 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 59 |
$original_blog_id = get_current_blog_id(); |
| 60 |
foreach ( $blog_ids as $blog_id ) { |
| 61 |
switch_to_blog( $blog_id ); |
| 62 |
update_option('autoptimize_css_include_inline','on'); |
| 63 |
update_option('autoptimize_js_include_inline','on'); |
| 64 |
} |
| 65 |
switch_to_blog( $original_blog_id ); |
| 66 |
} |
| 67 |
$majorUp = true; |
| 68 |
} |
| 69 |
|
| 70 |
if ( $majorUp === true ) { |
| 71 |
// clear cache and notify user to check result if major upgrade |
| 72 |
autoptimizeCache::clearall(); |
| 73 |
add_action('admin_notices', 'autoptimize_update_config_notice'); |
| 74 |
} |
| 75 |
|