[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Update/Install Plugin/Theme administration panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 if ( ! defined( 'IFRAME_REQUEST' ) 10 && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ), true ) 11 ) { 12 define( 'IFRAME_REQUEST', true ); 13 } 14 15 /** WordPress Administration Bootstrap */ 16 require_once __DIR__ . '/admin.php'; 17 18 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 19 20 wp_enqueue_script( 'wp-a11y' ); 21 22 if ( isset( $_GET['action'] ) ) { 23 $plugin = isset( $_REQUEST['plugin'] ) ? trim( $_REQUEST['plugin'] ) : ''; 24 $theme = isset( $_REQUEST['theme'] ) ? urldecode( $_REQUEST['theme'] ) : ''; 25 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; 26 27 if ( 'update-selected' === $action ) { 28 if ( ! current_user_can( 'update_plugins' ) ) { 29 wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) ); 30 } 31 32 check_admin_referer( 'bulk-update-plugins' ); 33 34 if ( isset( $_GET['plugins'] ) ) { 35 $plugins = explode( ',', stripslashes( $_GET['plugins'] ) ); 36 } elseif ( isset( $_POST['checked'] ) ) { 37 $plugins = (array) $_POST['checked']; 38 } else { 39 $plugins = array(); 40 } 41 42 $plugins = array_map( 'urldecode', $plugins ); 43 44 $url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) ); 45 $nonce = 'bulk-update-plugins'; 46 47 wp_enqueue_script( 'updates' ); 48 iframe_header(); 49 50 $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); 51 $upgrader->bulk_upgrade( $plugins ); 52 53 iframe_footer(); 54 55 } elseif ( 'upgrade-plugin' === $action ) { 56 if ( ! current_user_can( 'update_plugins' ) ) { 57 wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) ); 58 } 59 60 check_admin_referer( 'upgrade-plugin_' . $plugin ); 61 62 // Used in the HTML title tag. 63 $title = __( 'Update Plugin' ); 64 $parent_file = 'plugins.php'; 65 $submenu_file = 'plugins.php'; 66 67 wp_enqueue_script( 'updates' ); 68 require_once ABSPATH . 'wp-admin/admin-header.php'; 69 70 $nonce = 'upgrade-plugin_' . $plugin; 71 $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin ); 72 73 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ) ); 74 $upgrader->upgrade( $plugin ); 75 76 require_once ABSPATH . 'wp-admin/admin-footer.php'; 77 78 } elseif ( 'activate-plugin' === $action ) { 79 if ( ! current_user_can( 'update_plugins' ) ) { 80 wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) ); 81 } 82 83 check_admin_referer( 'activate-plugin_' . $plugin ); 84 if ( ! isset( $_GET['failure'] ) && ! isset( $_GET['success'] ) ) { 85 wp_redirect( admin_url( 'update.php?action=activate-plugin&failure=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) ); 86 activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true ); 87 wp_redirect( admin_url( 'update.php?action=activate-plugin&success=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) ); 88 die(); 89 } 90 iframe_header( __( 'Plugin Reactivation' ), true ); 91 if ( isset( $_GET['success'] ) ) { 92 echo '<p>' . __( 'Plugin reactivated successfully.' ) . '</p>'; 93 } 94 95 if ( isset( $_GET['failure'] ) ) { 96 echo '<p>' . __( 'Plugin failed to reactivate due to a fatal error.' ) . '</p>'; 97 98 error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR ); 99 ini_set( 'display_errors', true ); // Ensure that fatal errors are displayed. 100 wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); 101 include WP_PLUGIN_DIR . '/' . $plugin; 102 } 103 iframe_footer(); 104 } elseif ( 'install-plugin' === $action ) { 105 106 if ( ! current_user_can( 'install_plugins' ) ) { 107 wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) ); 108 } 109 110 include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api(). 111 112 check_admin_referer( 'install-plugin_' . $plugin ); 113 $api = plugins_api( 114 'plugin_information', 115 array( 116 'slug' => $plugin, 117 'fields' => array( 118 'sections' => false, 119 ), 120 ) 121 ); 122 123 if ( is_wp_error( $api ) ) { 124 wp_die( $api ); 125 } 126 127 // Used in the HTML title tag. 128 $title = __( 'Plugin Installation' ); 129 $parent_file = 'plugins.php'; 130 $submenu_file = 'plugin-install.php'; 131 132 require_once ABSPATH . 'wp-admin/admin-header.php'; 133 134 /* translators: %s: Plugin name and version. */ 135 $title = sprintf( __( 'Installing Plugin: %s' ), $api->name . ' ' . $api->version ); 136 $nonce = 'install-plugin_' . $plugin; 137 $url = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin ); 138 if ( isset( $_GET['from'] ) ) { 139 $url .= '&from=' . urlencode( stripslashes( $_GET['from'] ) ); 140 } 141 142 $type = 'web'; // Install plugin type, From Web or an Upload. 143 144 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) ); 145 $upgrader->install( $api->download_link ); 146 147 require_once ABSPATH . 'wp-admin/admin-footer.php'; 148 149 } elseif ( 'upload-plugin' === $action ) { 150 151 if ( ! current_user_can( 'upload_plugins' ) ) { 152 wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) ); 153 } 154 155 check_admin_referer( 'plugin-upload' ); 156 157 $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' ); 158 159 // Used in the HTML title tag. 160 $title = __( 'Upload Plugin' ); 161 $parent_file = 'plugins.php'; 162 $submenu_file = 'plugin-install.php'; 163 164 require_once ABSPATH . 'wp-admin/admin-header.php'; 165 166 /* translators: %s: File name. */ 167 $title = sprintf( __( 'Installing plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) ); 168 $nonce = 'plugin-upload'; 169 $url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' ); 170 $type = 'upload'; // Install plugin type, From Web or an Upload. 171 172 $overwrite = isset( $_GET['overwrite'] ) ? sanitize_text_field( $_GET['overwrite'] ) : ''; 173 $overwrite = in_array( $overwrite, array( 'update-plugin', 'downgrade-plugin' ), true ) ? $overwrite : ''; 174 175 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) ); 176 $result = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) ); 177 178 if ( $result || is_wp_error( $result ) ) { 179 $file_upload->cleanup(); 180 } 181 182 require_once ABSPATH . 'wp-admin/admin-footer.php'; 183 184 } elseif ( 'upload-plugin-cancel-overwrite' === $action ) { 185 if ( ! current_user_can( 'upload_plugins' ) ) { 186 wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) ); 187 } 188 189 check_admin_referer( 'plugin-upload-cancel-overwrite' ); 190 191 // Make sure the attachment still exists, or File_Upload_Upgrader will call wp_die() 192 // that shows a generic "Please select a file" error. 193 if ( ! empty( $_GET['package'] ) ) { 194 $attachment_id = (int) $_GET['package']; 195 196 if ( get_post( $attachment_id ) ) { 197 $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' ); 198 $file_upload->cleanup(); 199 } 200 } 201 202 wp_redirect( self_admin_url( 'plugin-install.php' ) ); 203 exit; 204 } elseif ( 'upgrade-theme' === $action ) { 205 206 if ( ! current_user_can( 'update_themes' ) ) { 207 wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) ); 208 } 209 210 check_admin_referer( 'upgrade-theme_' . $theme ); 211 212 wp_enqueue_script( 'updates' ); 213 214 // Used in the HTML title tag. 215 $title = __( 'Update Theme' ); 216 $parent_file = 'themes.php'; 217 $submenu_file = 'themes.php'; 218 219 require_once ABSPATH . 'wp-admin/admin-header.php'; 220 221 $nonce = 'upgrade-theme_' . $theme; 222 $url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme ); 223 224 $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) ); 225 $upgrader->upgrade( $theme ); 226 227 require_once ABSPATH . 'wp-admin/admin-footer.php'; 228 } elseif ( 'update-selected-themes' === $action ) { 229 if ( ! current_user_can( 'update_themes' ) ) { 230 wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) ); 231 } 232 233 check_admin_referer( 'bulk-update-themes' ); 234 235 if ( isset( $_GET['themes'] ) ) { 236 $themes = explode( ',', stripslashes( $_GET['themes'] ) ); 237 } elseif ( isset( $_POST['checked'] ) ) { 238 $themes = (array) $_POST['checked']; 239 } else { 240 $themes = array(); 241 } 242 243 $themes = array_map( 'urldecode', $themes ); 244 245 $url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) ); 246 $nonce = 'bulk-update-themes'; 247 248 wp_enqueue_script( 'updates' ); 249 iframe_header(); 250 251 $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); 252 $upgrader->bulk_upgrade( $themes ); 253 254 iframe_footer(); 255 } elseif ( 'install-theme' === $action ) { 256 257 if ( ! current_user_can( 'install_themes' ) ) { 258 wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) ); 259 } 260 261 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // For themes_api(). 262 263 check_admin_referer( 'install-theme_' . $theme ); 264 $api = themes_api( 265 'theme_information', 266 array( 267 'slug' => $theme, 268 'fields' => array( 269 'sections' => false, 270 'tags' => false, 271 ), 272 ) 273 ); // Save on a bit of bandwidth. 274 275 if ( is_wp_error( $api ) ) { 276 wp_die( $api ); 277 } 278 279 // Used in the HTML title tag. 280 $title = __( 'Install Themes' ); 281 $parent_file = 'themes.php'; 282 $submenu_file = 'themes.php'; 283 284 require_once ABSPATH . 'wp-admin/admin-header.php'; 285 286 /* translators: %s: Theme name and version. */ 287 $title = sprintf( __( 'Installing Theme: %s' ), $api->name . ' ' . $api->version ); 288 $nonce = 'install-theme_' . $theme; 289 $url = 'update.php?action=install-theme&theme=' . urlencode( $theme ); 290 $type = 'web'; // Install theme type, From Web or an Upload. 291 292 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) ); 293 $upgrader->install( $api->download_link ); 294 295 require_once ABSPATH . 'wp-admin/admin-footer.php'; 296 297 } elseif ( 'upload-theme' === $action ) { 298 299 if ( ! current_user_can( 'upload_themes' ) ) { 300 wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) ); 301 } 302 303 check_admin_referer( 'theme-upload' ); 304 305 $file_upload = new File_Upload_Upgrader( 'themezip', 'package' ); 306 307 // Used in the HTML title tag. 308 $title = __( 'Upload Theme' ); 309 $parent_file = 'themes.php'; 310 $submenu_file = 'theme-install.php'; 311 312 require_once ABSPATH . 'wp-admin/admin-header.php'; 313 314 /* translators: %s: File name. */ 315 $title = sprintf( __( 'Installing theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) ); 316 $nonce = 'theme-upload'; 317 $url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' ); 318 $type = 'upload'; // Install theme type, From Web or an Upload. 319 320 $overwrite = isset( $_GET['overwrite'] ) ? sanitize_text_field( $_GET['overwrite'] ) : ''; 321 $overwrite = in_array( $overwrite, array( 'update-theme', 'downgrade-theme' ), true ) ? $overwrite : ''; 322 323 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) ); 324 $result = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) ); 325 326 if ( $result || is_wp_error( $result ) ) { 327 $file_upload->cleanup(); 328 } 329 330 require_once ABSPATH . 'wp-admin/admin-footer.php'; 331 332 } elseif ( 'upload-theme-cancel-overwrite' === $action ) { 333 if ( ! current_user_can( 'upload_themes' ) ) { 334 wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) ); 335 } 336 337 check_admin_referer( 'theme-upload-cancel-overwrite' ); 338 339 // Make sure the attachment still exists, or File_Upload_Upgrader will call wp_die() 340 // that shows a generic "Please select a file" error. 341 if ( ! empty( $_GET['package'] ) ) { 342 $attachment_id = (int) $_GET['package']; 343 344 if ( get_post( $attachment_id ) ) { 345 $file_upload = new File_Upload_Upgrader( 'themezip', 'package' ); 346 $file_upload->cleanup(); 347 } 348 } 349 350 wp_redirect( self_admin_url( 'theme-install.php' ) ); 351 exit; 352 } else { 353 /** 354 * Fires when a custom plugin or theme update request is received. 355 * 356 * The dynamic portion of the hook name, `$action`, refers to the action 357 * provided in the request for wp-admin/update.php. Can be used to 358 * provide custom update functionality for themes and plugins. 359 * 360 * @since 2.8.0 361 */ 362 do_action( "update-custom_{$action}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 363 } 364 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Dec 24 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |