WP hooks navigation: Home/browse • Actions index • Filters index
To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).
The best way to understand what a hook does is to look at where it occurs in the source code.
do_action( "hook_name" )
apply_filters( "hook_name", "what_to_filter" )
.Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.
This hook occurs 5 times in this file.
Line | Code |
---|---|
167 |
|
168 | // Get the URL to the zip file |
169 | $r = $current->response[ $plugin ]; |
170 |
|
171 | if ( empty($r->package) ) |
172 | return new WP_Error('no_package', __('Upgrade package not available.')); |
173 |
|
174 | // Download the package |
175 | $package = $r->package; |
176 | apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); |
177 | $file = download_url($package); |
178 |
|
179 | if ( is_wp_error($file) ) |
180 | return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message()); |
181 |
|
182 | $working_dir = $base . 'wp-content/upgrade/' . basename($plugin, '.php'); |
183 |
|
184 | // Clean up working directory |
185 | if ( $wp_filesystem->is_dir($working_dir) ) |
186 | $wp_filesystem->delete($working_dir, true); |
187 |
|
188 | apply_filters('update_feedback', __('Unpacking the update')); |
189 | // Unzip package to working directory |
190 | $result = unzip_file($file, $working_dir); |
191 | if ( is_wp_error($result) ) { |
192 | unlink($file); |
193 | $wp_filesystem->delete($working_dir, true); |
194 | return $result; |
195 | } |
196 |
|
197 | // Once extracted, delete the package |
198 | unlink($file); |
199 |
|
200 | if ( is_plugin_active($plugin) ) { |
201 | //Deactivate the plugin silently, Prevent deactivation hooks from running. |
202 | apply_filters('update_feedback', __('Deactivating the plugin')); |
203 | deactivate_plugins($plugin, true); |
204 | } |
205 |
|
206 | // Remove the existing plugin. |
207 | apply_filters('update_feedback', __('Removing the old version of the plugin')); |
208 | $plugin_dir = dirname($base . PLUGINDIR . "/$plugin"); |
209 | $plugin_dir = trailingslashit($plugin_dir); |
210 | |
211 | // If plugin is in its own directory, recursively delete the directory. |
212 | if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder |
213 | $deleted = $wp_filesystem->delete($plugin_dir, true); |
214 | else |
215 | $deleted = $wp_filesystem->delete($base . PLUGINDIR . "/$plugin"); |
216 |
|
217 | if ( !$deleted ) { |
218 | $wp_filesystem->delete($working_dir, true); |
219 | return new WP_Error('delete_failed', __('Could not remove the old plugin')); |
220 | } |
221 |
|
222 | apply_filters('update_feedback', __('Installing the latest version')); |
223 | // Copy new version of plugin into place. |
224 | if ( !copy_dir($working_dir, $base . PLUGINDIR) ) { |
225 | //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. |
226 | return new WP_Error('install_failed', __('Installation failed')); |
227 | } |
228 |
|
229 | //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin |
230 | $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); |
231 |
|