C:\xampp\htdocs\landing\wp-content\plugins\wp-smushit\core\class-installer.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
<?php
/**
 * Smush installer (update/upgrade procedures): Installer class
 *
 * @package Smush\Core
 * @since 2.8.0
 *
 * @author Anton Vanyukov <anton@incsub.com>
 *
 * @copyright (c) 2018, Incsub (http://incsub.com)
 */

namespace Smush\Core;

use 
WP_Smush;

if ( ! 
defined'WPINC' ) ) {
    die;
}

/**
 * Class Installer for handling updates and upgrades of the plugin.
 *
 * @since 2.8.0
 */
class Installer {

    
/**
     * Triggered on Smush deactivation.
     *
     * @since 3.1.0
     */
    
public static function smush_deactivated() {
        if ( ! 
class_exists'\\Smush\\Core\\Modules\\CDN' ) ) {
            require_once 
__DIR__ '/modules/class-cdn.php';
        }

        
Modules\CDN::unschedule_cron();
    }

    
/**
     * Check if a existing install or new.
     *
     * @since 2.8.0  Moved to this class from wp-smush.php file.
     */
    
public static function smush_activated() {
        if ( ! 
defined'WP_SMUSH_ACTIVATING' ) ) {
            
define'WP_SMUSH_ACTIVATING'true );
        }

        
$version get_site_optionWP_SMUSH_PREFIX 'version' );

        if ( ! 
class_exists'\\Smush\\Core\\Settings' ) ) {
            require_once 
__DIR__ '/class-settings.php';
        }

        
Settings::get_instance()->init();
        
$settings Settings::get_instance()->get();

        
// If the version is not saved or if the version is not same as the current version,.
        
if ( ! $version || WP_SMUSH_VERSION !== $version ) {
            global 
$wpdb;
            
// Check if there are any existing smush stats.
            
$results $wpdb->get_var(
                
$wpdb->prepare(
                    
"SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key=%s LIMIT 1",
                    
'wp-smpro-smush-data'
                
)
            ); 
// db call ok; no-cache ok.

            
if ( $results || ( isset( $settings['auto'] ) && false !== $settings['auto'] ) ) {
                
update_site_option'wp-smush-install-type''existing' );
            }

            
// Create directory smush table.
            
self::directory_smush_table();

            
// Store the plugin version in db.
            
update_site_optionWP_SMUSH_PREFIX 'version'WP_SMUSH_VERSION );
        }
    }

    
/**
     * Handle plugin upgrades.
     *
     * @since 2.8.0
     */
    
public static function upgrade_settings() {
        
// Avoid to execute this over an over in same thread.
        
if ( defined'WP_SMUSH_ACTIVATING' ) || ( defined'WP_SMUSH_UPGRADING' ) && WP_SMUSH_UPGRADING ) ) {
            return;
        }

        
$version get_site_optionWP_SMUSH_PREFIX 'version' );

        if ( 
false === $version ) {
            
self::smush_activated();
        }

        if ( 
false !== $version && WP_SMUSH_VERSION !== $version ) {
            if ( ! 
defined'WP_SMUSH_UPGRADING' ) ) {
                
define'WP_SMUSH_UPGRADING'true );
            }

            if ( 
version_compare$version'3.7.0''<' ) ) {
                
self::upgrade_3_7_0();
            }

            if ( 
version_compare$version'3.8.0''<' ) ) {
                
// Delete the flag for hiding the BF modal because it was removed.
                
delete_site_optionWP_SMUSH_PREFIX 'hide_blackfriday_modal' );
            }

            if ( 
version_compare$version'3.8.3''<' ) ) {
                
// Delete this unused setting, leftover from old smush.
                
delete_optionWP_SMUSH_PREFIX 'transparent_png' );
            }

            
// Create/upgrade directory smush table.
            
self::directory_smush_table();

            
// Store the latest plugin version in db.
            
update_site_optionWP_SMUSH_PREFIX 'version'WP_SMUSH_VERSION );
        }
    }

    
/**
     * Create or upgrade custom table for directory Smush.
     *
     * After creating or upgrading the custom table, update the path_hash
     * column value and structure if upgrading from old version.
     *
     * @since 2.9.0
     */
    
public static function directory_smush_table() {
        if ( ! 
class_exists'\\Smush\\Core\\Modules\\Abstract_Module' ) ) {
            require_once 
__DIR__ '/modules/class-abstract-module.php';
        }

        if ( ! 
class_exists'\\Smush\\Core\\Modules\\Dir' ) ) {
            require_once 
__DIR__ '/modules/class-dir.php';
        }

        
// No need to continue on sub sites.
        
if ( ! Modules\Dir::should_continue() ) {
            return;
        }

        
// Create a class object, if doesn't exists.
        
if ( ! is_objectWP_Smush::get_instance()->core()->mod->dir ) ) {
            
WP_Smush::get_instance()->core()->mod->dir = new Modules\Dir();
        }

        
// Create/upgrade directory smush table.
        
WP_Smush::get_instance()->core()->mod->dir->create_table();
    }

    
/**
     * Upgrade to 3.7.0
     *
     * @since 3.7.0
     */
    
private static function upgrade_3_7_0() {
        
delete_site_optionWP_SMUSH_PREFIX 'run_recheck' );

        
// Fix the "None" animation in lazy-load options.
        
$lazy Settings::get_instance()->get_settingWP_SMUSH_PREFIX 'lazy_load' );

        if ( ! 
$lazy || ! isset( $lazy['animation'] ) || ! isset( $lazy['animation']['selected'] ) ) {
            return;
        }

        if ( 
'0' === $lazy['animation']['selected'] ) {
            
$lazy['animation']['selected'] = 'none';
            
Settings::get_instance()->set_settingWP_SMUSH_PREFIX 'lazy_load'$lazy );
        }
    }
}
x

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