| 1 |
<?php |
| 2 |
/* |
| 3 |
* below code handles updates and is only included by autoptimize.php if/ when needed |
| 4 |
*/ |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 7 |
|
| 8 |
$majorUp = false; |
| 9 |
$autoptimize_major_version=substr($autoptimize_db_version,0,3); |
| 10 |
|
| 11 |
switch($autoptimize_major_version) { |
| 12 |
case "1.6": |
| 13 |
// from back in the days when I did not yet consider multisite |
| 14 |
// if user was on version 1.6.x, force advanced options to be shown by default |
| 15 |
update_option('autoptimize_show_adv','1'); |
| 16 |
|
| 17 |
// and remove old options |
| 18 |
$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"); |
| 19 |
foreach ($to_delete_options as $del_opt) { |
| 20 |
delete_option( $del_opt ); |
| 21 |
} |
| 22 |
$majorUp = true; |
| 23 |
case "1.7": |
| 24 |
// force 3.8 dashicons in CSS exclude options when upgrading from 1.7 to 1.8 |
| 25 |
if ( !is_multisite() ) { |
| 26 |
$css_exclude = get_option('autoptimize_css_exclude'); |
| 27 |
if (empty($css_exclude)) { |
| 28 |
$css_exclude = "admin-bar.min.css, dashicons.min.css"; |
| 29 |
} else if (strpos($css_exclude,"dashicons.min.css")===false) { |
| 30 |
$css_exclude .= ", dashicons.min.css"; |
| 31 |
} |
| 32 |
update_option('autoptimize_css_exclude',$css_exclude); |
| 33 |
} else { |
| 34 |
global $wpdb; |
| 35 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 36 |
$original_blog_id = get_current_blog_id(); |
| 37 |
foreach ( $blog_ids as $blog_id ) { |
| 38 |
switch_to_blog( $blog_id ); |
| 39 |
$css_exclude = get_option('autoptimize_css_exclude'); |
| 40 |
if (empty($css_exclude)) { |
| 41 |
$css_exclude = "admin-bar.min.css, dashicons.min.css"; |
| 42 |
} else if (strpos($css_exclude,"dashicons.min.css")===false) { |
| 43 |
$css_exclude .= ", dashicons.min.css"; |
| 44 |
} |
| 45 |
update_option('autoptimize_css_exclude',$css_exclude); |
| 46 |
} |
| 47 |
switch_to_blog( $original_blog_id ); |
| 48 |
} |
| 49 |
$majorUp = true; |
| 50 |
case "1.9": |
| 51 |
/* |
| 52 |
* 2.0 will not aggregate inline CSS/JS by default, but we want users |
| 53 |
* upgrading from 1.9 to keep their inline code aggregated by default. |
| 54 |
*/ |
| 55 |
if ( !is_multisite() ) { |
| 56 |
update_option('autoptimize_css_include_inline','on'); |
| 57 |
update_option('autoptimize_js_include_inline','on'); |
| 58 |
} else { |
| 59 |
global $wpdb; |
| 60 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 61 |
$original_blog_id = get_current_blog_id(); |
| 62 |
foreach ( $blog_ids as $blog_id ) { |
| 63 |
switch_to_blog( $blog_id ); |
| 64 |
update_option('autoptimize_css_include_inline','on'); |
| 65 |
update_option('autoptimize_js_include_inline','on'); |
| 66 |
} |
| 67 |
switch_to_blog( $original_blog_id ); |
| 68 |
} |
| 69 |
$majorUp = true; |
| 70 |
case "2.2": |
| 71 |
/* |
| 72 |
* 2.3 has no "remove google fonts" in main screen, moved to "extra" |
| 73 |
*/ |
| 74 |
if ( !is_multisite() ) { |
| 75 |
$_nogooglefont = get_option('autoptimize_css_nogooglefont',''); |
| 76 |
$_ao_extrasetting = get_option('autoptimize_extra_settings',''); |
| 77 |
if ( ($_nogooglefont == 1) && ( empty($_ao_extrasetting) ) ) { |
| 78 |
$_aoextra_removegfonts = array("autoptimize_extra_checkbox_field_1"=>"0","autoptimize_extra_checkbox_field_0"=>"0","autoptimize_extra_radio_field_4"=>"1","autoptimize_extra_text_field_2"=>"","autoptimize_extra_text_field_3"=>""); |
| 79 |
update_option( 'autoptimize_extra_settings', $_aoextra_removegfonts ); |
| 80 |
} |
| 81 |
delete_option('autoptimize_css_nogooglefont'); |
| 82 |
} else { |
| 83 |
global $wpdb; |
| 84 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 85 |
$original_blog_id = get_current_blog_id(); |
| 86 |
foreach ( $blog_ids as $blog_id ) { |
| 87 |
switch_to_blog( $blog_id ); |
| 88 |
$_nogooglefont = get_option('autoptimize_css_nogooglefont',''); |
| 89 |
$_ao_extrasetting = get_option('autoptimize_extra_settings',''); |
| 90 |
if ( ($_nogooglefont == 1) && ( empty($_ao_extrasetting) ) ) { |
| 91 |
$_aoextra_removegfonts = array("autoptimize_extra_checkbox_field_1"=>"0","autoptimize_extra_checkbox_field_0"=>"0","autoptimize_extra_radio_field_4"=>"1","autoptimize_extra_text_field_2"=>"","autoptimize_extra_text_field_3"=>""); |
| 92 |
update_option( 'autoptimize_extra_settings', $_aoextra_removegfonts ); |
| 93 |
} |
| 94 |
delete_option('autoptimize_css_nogooglefont'); |
| 95 |
} |
| 96 |
switch_to_blog( $original_blog_id ); |
| 97 |
} |
| 98 |
$majorUp = true; |
| 99 |
} |
| 100 |
|
| 101 |
if ( $majorUp === true ) { |
| 102 |
// clear cache and notify user to check result if major upgrade |
| 103 |
autoptimizeCache::clearall(); |
| 104 |
add_action('admin_notices', 'autoptimize_update_config_notice'); |
| 105 |
} |
| 106 |
|