/var/www/html_fr/wp-content/plugins/woocommerce-orders-tracking/includes/update.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
<?php
/**
 * VillaTheme_Plugin_Updater
 */

// no direct access allowed
if ( ! defined'ABSPATH' ) ) {
    die();
}

/**
 * The main challenge here is defining a dynamic dl link
 * for $update_plugins_transient->response[ $plugin_slug ]->package;
 *
 * Version 1.0.2
 */

if ( ! class_exists'VillaTheme_Plugin_Updater' ) ) {

    if ( ! 
class_exists'WP_Upgrader' ) ) {
        require_once 
ABSPATH 'wp-admin/includes/class-wp-upgrader.php';
    }
    if ( ! 
class_exists'Plugin_Upgrader' ) ) {
        require_once 
ABSPATH 'wp-admin/includes/class-plugin-upgrader.php';
    }

    class 
VillaTheme_Plugin_Updater extends Plugin_Upgrader {
        
/**
         * Plugin directory and main file name (e.g myplugin/myplugin.php)
         *
         * @var string
         */
        
public $plugin_slug;

        
/**
         * Plugin slug
         *
         * @var string
         */
        
public $slug;

        
/**
         * Set plugin info and add essential hooks
         *
         * @param string $plugin_slug The name of directory and main file name of plugin
         * @param string $slug Then slug name of plugin (optional)
         * @param string $setting_page_url URL of Setting page
         */
        
protected $setting_page_url;

        public function 
__construct$plugin_slug$slug ''$setting_page_url '#' ) {

            
parent::__construct();

            
$this->slug             $slug;
            
$this->plugin_slug      $plugin_slug;
            
$this->setting_page_url $setting_page_url;

            
add_action'admin_init', array( $this'plugin_update_rows' ), PHP_INT_MAX );
            
// a custom hook that fires on update.php page while upgrading the packages
            
add_action"update-custom_{$this->slug}-upgrade", array( $this'custom_upgrade_plugin' ) );
        }

        
/**
         * Fires on the page wp-admin/update.php?{$this->slug}-upgrade page
         *
         * @return void
         */
        
public function custom_upgrade_plugin() {
            
$plugin = isset( $_REQUEST['plugin'] ) ? trim$_REQUEST['plugin'] ) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended

            
if ( ! current_user_can'update_plugins' ) ) {
                
wp_dieesc_html__'You do not have sufficient permissions to update plugins for this site.' ) );
            }

            
check_admin_referer'upgrade-plugin_' $plugin );

            
wp_enqueue_script'updates' );

            require_once( 
ABSPATH 'wp-admin/admin-header.php' );

            
$nonce 'upgrade-plugin_' $plugin;
            
$url   'update.php?action=upgrade-plugin&plugin=' urlencode$plugin );

            if ( 
$this->update_plugin() ) {
                
do_action$plugin "_updated" );
            }

            
// return to plugins page link
            
?>
            <a href="<?php echo esc_urlself_admin_url'plugins.php' ) ) ?>"
               title="<?php echo esc_attr'Go to plugins page' ?>"
               target="_parent"><?php esc_html_e'Return to Plugins page' ?></a>
            <?php

            
include( ABSPATH 'wp-admin/admin-footer.php' );
        }


        
/**
         * Upgrade a plugin.
         *
         * @param string $plugin The basename path to the main plugin file.
         *
         * @return bool|WP_Error True if the upgrade was successful, false or a {@see WP_Error} object otherwise.
         */
        
public function update_plugin() {
            
/**
             * Initialize the WP_Filesystem
             */
            
global $wp_filesystem;
            if ( empty( 
$wp_filesystem ) ) {
                require_once( 
ABSPATH '/wp-admin/includes/file.php' );
                
WP_Filesystem();
            }

            
$plugin $this->plugin_slug;

            
$this->init();

            
$current get_site_transient'update_plugins' );
            if ( ! isset( 
$current->response$plugin ] ) ) {
                
$this->skin->before();
                
$this->skin->set_resultfalse );
                
$this->skin->error'up_to_date' );
                
$this->skin->after();

                return 
false;
            }

            
// Get the URL to the zip file
            
$r $current->response$plugin ];

            
add_filter'upgrader_pre_install', array( $this'deactivate_plugin_before_upgrade' ), 10);
            
add_filter'upgrader_clear_destination', array( $this'delete_old_plugin' ), 10);

            
$this->run( array(
                
'package'           => $r->package,
                
'destination'       => WP_PLUGIN_DIR,
                
'clear_destination' => true,
                
'clear_working'     => true,
                
'hook_extra'        => array(
                    
'plugin' => $plugin,
                    
'type'   => 'plugin',
                    
'action' => 'update',
                ),
            ) );

            
// Cleanup our hooks, in case something else does a upgrade on this connection.
            
remove_filter'upgrader_pre_install', array( $this'deactivate_plugin_before_upgrade' ) );
            
remove_filter'upgrader_clear_destination', array( $this'delete_old_plugin' ) );

            if ( ! 
$this->result || is_wp_error$this->result ) ) {
                return 
$this->result;
            }

            
// Force refresh of plugin update information
            
delete_site_transient'update_plugins' );
            
wp_cache_delete'plugins''plugins' );

            return 
true;
        }

        
/**
         * Add hooks for modifying the plugin row context
         */
        
public function plugin_update_rows() {
            
remove_action"after_plugin_row_{$this->plugin_slug}"'wp_plugin_update_row'10 );
            
add_action"after_plugin_row_{$this->plugin_slug}", array( $this'plugin_update_row' ), 10);
        }

        
/**
         * Override the plugin row context
         *
         * @param string $file The plugin file path
         * @param array $plugin_data Plugin information
         *
         * @return void
         */
        
public function plugin_update_row$file$plugin_data ) {
            
$current get_site_transient'update_plugins' );

            if ( ! isset( 
$current->response$file ] ) ) {
                return;
            }

            
$r $current->response$file ];

            
$plugins_allowedtags = array(
                
'a'       => array(
                    
'href'  => array(),
                    
'title' => array()
                ),
                
'abbr'    => array(
                    
'title' => array()
                ),
                
'acronym' => array(
                    
'title' => array()
                ),
                
'code'    => array(),
                
'em'      => array(),
                
'strong'  => array()
            );

            
$plugin_name   wp_kses$plugin_data['Name'], $plugins_allowedtags );
            
$details_url   add_query_arg( array(
                
'tab'       => 'plugin-information',
                
'plugin'    => $this->slug,
                
'section'   => 'changelog',
                
'TB_iframe' => 'true',
                
'width'     => '772',
                
'height'    => '909',
            ), 
admin_url'plugin-install.php' ) );
            
$wp_list_table _get_list_table'WP_Plugins_List_Table' );

            if ( 
is_network_admin() || ! is_multisite() ) {
                
?>
                <tr class="plugin-update-tr">
                    <td colspan="<?php echo esc_attr$wp_list_table->get_column_count() ) ?>"
                        class="plugin-update colspanchange">
                        <div class="notice inline notice-warning notice-alt">
                            <p>
                                <?php
                                
echo wp_kses_postsprintf__'New version of %1$s available. You can download or <a href="%2$s" class="thickbox open-plugin-details-modal" title="%3$s">view version %4$s</a>. Please make sure that you fill your auto-update key in <a href="%5$s">Setting page</a>.' ) ,// phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
                                        
$plugin_nameesc_url$details_url ), esc_attr$plugin_name ), $r->new_versionesc_url$this->setting_page_url ))
                                );
                                
do_action"in_plugin_update_message-{$file}"$plugin_data$r );
                                
?>
                            </p>
                        </div>
                    </td>
                </tr>
                <?php
            
}
        }
    }
}