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 |
|---|---|
| 108 | |
| 109 | // Get the URL to the zip file |
| 110 | $r = $current->response[ $plugin ]; |
| 111 | |
| 112 | if ( empty($r->package) ) |
| 113 | return new WP_Error('no_package', __('Upgrade package not available.')); |
| 114 | |
| 115 | // Download the package |
| 116 | $package = $r->package; |
| 117 | apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); |
| 118 | $download_file = download_url($package); |
| 119 | |
| 120 | if ( is_wp_error($download_file) ) |
| 121 | return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message()); |
| 122 | |
| 123 | $working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php'); |
| 124 | |
| 125 | // Clean up working directory |
| 126 | if ( $wp_filesystem->is_dir($working_dir) ) |
| 127 | $wp_filesystem->delete($working_dir, true); |
| 128 | |
| 129 | apply_filters('update_feedback', __('Unpacking the update')); |
| 130 | // Unzip package to working directory |
| 131 | $result = unzip_file($download_file, $working_dir); |
| 132 | |
| 133 | // Once extracted, delete the package |
| 134 | unlink($download_file); |
| 135 | |
| 136 | if ( is_wp_error($result) ) { |
| 137 | $wp_filesystem->delete($working_dir, true); |
| 138 | return $result; |
| 139 | } |
| 140 | |
| 141 | if ( is_plugin_active($plugin) ) { |
| 142 | //Deactivate the plugin silently, Prevent deactivation hooks from running. |
| 143 | apply_filters('update_feedback', __('Deactivating the plugin')); |
| 144 | deactivate_plugins($plugin, true); |
| 145 | } |
| 146 | |
| 147 | // Remove the existing plugin. |
| 148 | apply_filters('update_feedback', __('Removing the old version of the plugin')); |
| 149 | $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); |
| 150 | |
| 151 | // If plugin is in its own directory, recursively delete the directory. |
| 152 | if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder |
| 153 | $deleted = $wp_filesystem->delete($this_plugin_dir, true); |
| 154 | else |
| 155 | $deleted = $wp_filesystem->delete($plugins_dir . $plugin); |
| 156 | |
| 157 | if ( ! $deleted ) { |
| 158 | $wp_filesystem->delete($working_dir, true); |
| 159 | return new WP_Error('delete_failed', __('Could not remove the old plugin')); |
| 160 | } |
| 161 | |
| 162 | apply_filters('update_feedback', __('Installing the latest version')); |
| 163 | // Copy new version of plugin into place. |
| 164 | $result = copy_dir($working_dir, $plugins_dir); |
| 165 | if ( is_wp_error($result) ) { |
| 166 | //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. |
| 167 | return $result; |
| 168 | } |
| 169 | |
| 170 | //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin |
| 171 | $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); |