C:\xampp\htdocs\landing\wp-content\plugins\autoptimize\classes\autoptimizeVersionUpdatesHandler.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/**
 * Handles version updates and should only be instantiated in autoptimize.php if/when needed.
 */

if ( ! defined'ABSPATH' ) ) {
    exit;
}

class 
autoptimizeVersionUpdatesHandler
{
    
/**
     * The current major version string.
     *
     * @var string
     */
    
protected $current_major_version null;

    public function 
__construct$current_version )
    {
        
$this->current_major_version substr$current_version0);
    }

    
/**
     * Runs all needed upgrade procedures (depending on the
     * current major version specified during class instantiation)
     */
    
public function run_needed_major_upgrades()
    {
        
$major_update false;

        switch ( 
$this->current_major_version ) {
            case 
'1.6':
                
$this->upgrade_from_1_6();
                
$major_update true;
                
// No break, intentionally, so all upgrades are ran during a single request...
            
case '1.7':
                
$this->upgrade_from_1_7();
                
$major_update true;
                
// No break, intentionally, so all upgrades are ran during a single request...
            
case '1.9':
                
$this->upgrade_from_1_9();
                
$major_update true;
                
// No break, intentionally, so all upgrades are ran during a single request...
            
case '2.2':
                
$this->upgrade_from_2_2();
                
$major_update true;
                
// No break, intentionally, so all upgrades are ran during a single request...
            
case '2.4':
                if ( 
autoptimizeOptionWrapper::get_option'autoptimize_version''none' ) == '2.4.2' ) {
                    
$this->upgrade_from_2_4_2();
                }
                
$this->upgrade_from_2_4();
                
$major_update false;
                
// No break, intentionally, so all upgrades are ran during a single request...
            
case '2.7':
                
$this->upgrade_from_2_7();
                
$major_update true;
                
// No break, intentionally, so all upgrades are ran during a single request...
        
}

        if ( 
true === $major_update ) {
            
$this->on_major_version_update();
        }
    }

    
/**
     * Checks specified version against the one stored in the database under `autoptimize_version` and performs
     * any major upgrade routines if needed.
     * Updates the database version to the specified $target if it's different to the one currently stored there.
     *
     * @param string $target Target version to check against (ie., the currently running one).
     */
    
public static function check_installed_and_update$target )
    {
        
$db_version autoptimizeOptionWrapper::get_option'autoptimize_version''none' );
        if ( 
$db_version !== $target ) {
            if ( 
'none' === $db_version ) {
                
add_action'admin_notices''autoptimizeMain::notice_installed' );
            } else {
                
$updater = new self$db_version );
                
$updater->run_needed_major_upgrades();
            }

            
// Versions differed, upgrades happened if needed, store the new version.
            
autoptimizeOptionWrapper::update_option'autoptimize_version'$target );
        }
    }

    
/**
     * Called after any major version update (and it's accompanying upgrade procedure)
     * has happened. Clears cache and sets an admin notice.
     */
    
protected function on_major_version_update()
    {
        
// The transients guard here prevents stale object caches from busting the cache on every request.
        
if ( false == get_transient'autoptimize_stale_option_buster' ) ) {
            
set_transient'autoptimize_stale_option_buster''Mamsie & Liessie zehhe: ZWIJH!'HOUR_IN_SECONDS );
            
autoptimizeCache::clearall();
            
add_action'admin_notices''autoptimizeMain::notice_updated' );
        }
    }

    
/**
     * From back in the days when I did not yet consider multisite.
     */
    
private function upgrade_from_1_6()
    {
        
// If user was on version 1.6.x, force advanced options to be shown by default.
        
autoptimizeOptionWrapper::update_option'autoptimize_show_adv''1' );

        
// And remove old options.
        
$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',
        );
        foreach ( 
$to_delete_options as $del_opt ) {
            
delete_option$del_opt );
        }
    }

    
/**
     * Forces WP 3.8 dashicons in CSS exclude options when upgrading from 1.7 to 1.8
     *
     * @global $wpdb
     */
    
private function upgrade_from_1_7()
    {
        if ( ! 
is_multisite() ) {
            
$css_exclude autoptimizeOptionWrapper::get_option'autoptimize_css_exclude' );
            if ( empty( 
$css_exclude ) ) {
                
$css_exclude 'admin-bar.min.css, dashicons.min.css';
            } elseif ( 
false === strpos$css_exclude'dashicons.min.css' ) ) {
                
$css_exclude .= ', dashicons.min.css';
            }
            
autoptimizeOptionWrapper::update_option'autoptimize_css_exclude'$css_exclude );
        } 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 );
                
$css_exclude autoptimizeOptionWrapper::get_option'autoptimize_css_exclude' );
                if ( empty( 
$css_exclude ) ) {
                    
$css_exclude 'admin-bar.min.css, dashicons.min.css';
                } elseif ( 
false === strpos$css_exclude'dashicons.min.css' ) ) {
                    
$css_exclude .= ', dashicons.min.css';
                }
                
autoptimizeOptionWrapper::update_option'autoptimize_css_exclude'$css_exclude );
            }
            
switch_to_blog$original_blog_id );
        }
    }

    
/**
     * 2.0 will not aggregate inline CSS/JS by default, but we want users
     * upgrading from 1.9 to keep their inline code aggregated by default.
     *
     * @global $wpdb
     */
    
private function upgrade_from_1_9()
    {
        if ( ! 
is_multisite() ) {
            
autoptimizeOptionWrapper::update_option'autoptimize_css_include_inline''on' );
            
autoptimizeOptionWrapper::update_option'autoptimize_js_include_inline''on' );
        } 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 );
                
autoptimizeOptionWrapper::update_option'autoptimize_css_include_inline''on' );
                
autoptimizeOptionWrapper::update_option'autoptimize_js_include_inline''on' );
            }
            
switch_to_blog$original_blog_id );
        }
    }

    
/**
     * 2.3 has no "remove google fonts" in main screen, moved to "extra"
     *
     * @global $wpdb
     */
    
private function upgrade_from_2_2()
    {
        if ( ! 
is_multisite() ) {
            
$this->do_2_2_settings_update();
        } 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 );
                
$this->do_2_2_settings_update();
            }
            
switch_to_blog$original_blog_id );
        }
    }

    
/**
     * Helper for 2.2 autoptimize_extra_settings upgrade to avoid duplicate code
     */
    
private function do_2_2_settings_update()
    {
        
$nogooglefont    autoptimizeOptionWrapper::get_option'autoptimize_css_nogooglefont''' );
        
$ao_extrasetting autoptimizeOptionWrapper::get_option'autoptimize_extra_settings''' );
        if ( ( 
$nogooglefont ) && ( empty( $ao_extrasetting ) ) ) {
            
autoptimizeOptionWrapper::update_option'autoptimize_extra_settings'autoptimizeConfig::get_ao_extra_default_options() );
        }
        
delete_option'autoptimize_css_nogooglefont' );
    }

    
/**
     * 2.4.2 introduced too many cronned ao_cachecheckers, make this right
     */
    
private function upgrade_from_2_4_2() {
        
// below code by Thomas Sjolshagen (http://eighty20results.com/)
        // as found on https://www.paidmembershipspro.com/deleting-oldextra-cron-events/.
        
$jobs _get_cron_array();

        
// Remove all ao_cachechecker cron jobs (for now).
        
foreach ( $jobs as $when => $job ) {
            
$name key$job );

            if ( 
false !== strpos$name'ao_cachechecker' ) ) {
                unset( 
$jobs$when ] );
            }
        }

        
// Save the data.
        
_set_cron_array$jobs );
    }

    
/**
     * Migrate imgopt options from autoptimize_extra_settings to autoptimize_imgopt_settings
     */
    
private function upgrade_from_2_4() {
        
$extra_settings  autoptimizeOptionWrapper::get_option'autoptimize_extra_settings''' );
        
$imgopt_settings autoptimizeOptionWrapper::get_option'autoptimize_imgopt_settings''' );
        if ( empty( 
$imgopt_settings ) && ! empty( $extra_settings ) ) {
            
$imgopt_settings autoptimizeConfig::get_ao_imgopt_default_options();
            if ( 
array_key_exists'autoptimize_extra_checkbox_field_5'$extra_settings ) ) {
                
$imgopt_settings['autoptimize_imgopt_checkbox_field_1'] = $extra_settings['autoptimize_extra_checkbox_field_5'];
            }
            if ( 
array_key_exists'autoptimize_extra_select_field_6'$extra_settings ) ) {
                
$imgopt_settings['autoptimize_imgopt_select_field_2'] = $extra_settings['autoptimize_extra_select_field_6'];
            }
            
autoptimizeOptionWrapper::update_option'autoptimize_imgopt_settings'$imgopt_settings );
        }
    }

    
/**
     * remove CCSS request limit option + update jquery exclusion to include WordPress 5.6 jquery.min.js.
     */    
    
private function upgrade_from_2_7() {
        
delete_option'autoptimize_ccss_rlimit' );
        
$js_exclusions get_option'autoptimize_js_exclude''' );
        if ( 
strpos$js_exclusions'js/jquery/jquery.js' ) !== false && strpos$js_exclusions'js/jquery/jquery.min.js' ) === false ) {
            
$js_exclusions .= ', js/jquery/jquery.min.js';
            
update_option'autoptimize_js_exclude'$js_exclusions );
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586