[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/ -> update.php (source)

   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  if ( isset( $_GET['action'] ) ) {
  21      $plugin = isset( $_REQUEST['plugin'] ) ? trim( $_REQUEST['plugin'] ) : '';
  22      $theme  = isset( $_REQUEST['theme'] ) ? urldecode( $_REQUEST['theme'] ) : '';
  23      $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
  24  
  25      if ( 'update-selected' === $action ) {
  26          if ( ! current_user_can( 'update_plugins' ) ) {
  27              wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  28          }
  29  
  30          check_admin_referer( 'bulk-update-plugins' );
  31  
  32          if ( isset( $_GET['plugins'] ) ) {
  33              $plugins = explode( ',', stripslashes( $_GET['plugins'] ) );
  34          } elseif ( isset( $_POST['checked'] ) ) {
  35              $plugins = (array) $_POST['checked'];
  36          } else {
  37              $plugins = array();
  38          }
  39  
  40          $plugins = array_map( 'urldecode', $plugins );
  41  
  42          $url   = 'update.php?action=update-selected&amp;plugins=' . urlencode( implode( ',', $plugins ) );
  43          $nonce = 'bulk-update-plugins';
  44  
  45          wp_enqueue_script( 'updates' );
  46          iframe_header();
  47  
  48          $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  49          $upgrader->bulk_upgrade( $plugins );
  50  
  51          iframe_footer();
  52  
  53      } elseif ( 'upgrade-plugin' === $action ) {
  54          if ( ! current_user_can( 'update_plugins' ) ) {
  55              wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  56          }
  57  
  58          check_admin_referer( 'upgrade-plugin_' . $plugin );
  59  
  60          $title        = __( 'Update Plugin' );
  61          $parent_file  = 'plugins.php';
  62          $submenu_file = 'plugins.php';
  63  
  64          wp_enqueue_script( 'updates' );
  65          require_once ABSPATH . 'wp-admin/admin-header.php';
  66  
  67          $nonce = 'upgrade-plugin_' . $plugin;
  68          $url   = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
  69  
  70          $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ) );
  71          $upgrader->upgrade( $plugin );
  72  
  73          require_once ABSPATH . 'wp-admin/admin-footer.php';
  74  
  75      } elseif ( 'activate-plugin' === $action ) {
  76          if ( ! current_user_can( 'update_plugins' ) ) {
  77              wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  78          }
  79  
  80          check_admin_referer( 'activate-plugin_' . $plugin );
  81          if ( ! isset( $_GET['failure'] ) && ! isset( $_GET['success'] ) ) {
  82              wp_redirect( admin_url( 'update.php?action=activate-plugin&failure=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
  83              activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
  84              wp_redirect( admin_url( 'update.php?action=activate-plugin&success=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
  85              die();
  86          }
  87          iframe_header( __( 'Plugin Reactivation' ), true );
  88          if ( isset( $_GET['success'] ) ) {
  89              echo '<p>' . __( 'Plugin reactivated successfully.' ) . '</p>';
  90          }
  91  
  92          if ( isset( $_GET['failure'] ) ) {
  93              echo '<p>' . __( 'Plugin failed to reactivate due to a fatal error.' ) . '</p>';
  94  
  95              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 );
  96              ini_set( 'display_errors', true ); // Ensure that fatal errors are displayed.
  97              wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
  98              include WP_PLUGIN_DIR . '/' . $plugin;
  99          }
 100          iframe_footer();
 101      } elseif ( 'install-plugin' === $action ) {
 102  
 103          if ( ! current_user_can( 'install_plugins' ) ) {
 104              wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
 105          }
 106  
 107          include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api().
 108  
 109          check_admin_referer( 'install-plugin_' . $plugin );
 110          $api = plugins_api(
 111              'plugin_information',
 112              array(
 113                  'slug'   => $plugin,
 114                  'fields' => array(
 115                      'sections' => false,
 116                  ),
 117              )
 118          );
 119  
 120          if ( is_wp_error( $api ) ) {
 121              wp_die( $api );
 122          }
 123  
 124          $title        = __( 'Plugin Installation' );
 125          $parent_file  = 'plugins.php';
 126          $submenu_file = 'plugin-install.php';
 127          require_once ABSPATH . 'wp-admin/admin-header.php';
 128  
 129          /* translators: %s: Plugin name and version. */
 130          $title = sprintf( __( 'Installing Plugin: %s' ), $api->name . ' ' . $api->version );
 131          $nonce = 'install-plugin_' . $plugin;
 132          $url   = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
 133          if ( isset( $_GET['from'] ) ) {
 134              $url .= '&from=' . urlencode( stripslashes( $_GET['from'] ) );
 135          }
 136  
 137          $type = 'web'; // Install plugin type, From Web or an Upload.
 138  
 139          $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
 140          $upgrader->install( $api->download_link );
 141  
 142          require_once ABSPATH . 'wp-admin/admin-footer.php';
 143  
 144      } elseif ( 'upload-plugin' === $action ) {
 145  
 146          if ( ! current_user_can( 'upload_plugins' ) ) {
 147              wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
 148          }
 149  
 150          check_admin_referer( 'plugin-upload' );
 151  
 152          $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
 153  
 154          $title        = __( 'Upload Plugin' );
 155          $parent_file  = 'plugins.php';
 156          $submenu_file = 'plugin-install.php';
 157          require_once ABSPATH . 'wp-admin/admin-header.php';
 158  
 159          /* translators: %s: File name. */
 160          $title = sprintf( __( 'Installing Plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
 161          $nonce = 'plugin-upload';
 162          $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' );
 163          $type  = 'upload'; // Install plugin type, From Web or an Upload.
 164  
 165          $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
 166          $result   = $upgrader->install( $file_upload->package );
 167  
 168          if ( $result || is_wp_error( $result ) ) {
 169              $file_upload->cleanup();
 170          }
 171  
 172          require_once ABSPATH . 'wp-admin/admin-footer.php';
 173  
 174      } elseif ( 'upgrade-theme' === $action ) {
 175  
 176          if ( ! current_user_can( 'update_themes' ) ) {
 177              wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
 178          }
 179  
 180          check_admin_referer( 'upgrade-theme_' . $theme );
 181  
 182          wp_enqueue_script( 'updates' );
 183  
 184          $title        = __( 'Update Theme' );
 185          $parent_file  = 'themes.php';
 186          $submenu_file = 'themes.php';
 187          require_once ABSPATH . 'wp-admin/admin-header.php';
 188  
 189          $nonce = 'upgrade-theme_' . $theme;
 190          $url   = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
 191  
 192          $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
 193          $upgrader->upgrade( $theme );
 194  
 195          require_once ABSPATH . 'wp-admin/admin-footer.php';
 196      } elseif ( 'update-selected-themes' === $action ) {
 197          if ( ! current_user_can( 'update_themes' ) ) {
 198              wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
 199          }
 200  
 201          check_admin_referer( 'bulk-update-themes' );
 202  
 203          if ( isset( $_GET['themes'] ) ) {
 204              $themes = explode( ',', stripslashes( $_GET['themes'] ) );
 205          } elseif ( isset( $_POST['checked'] ) ) {
 206              $themes = (array) $_POST['checked'];
 207          } else {
 208              $themes = array();
 209          }
 210  
 211          $themes = array_map( 'urldecode', $themes );
 212  
 213          $url   = 'update.php?action=update-selected-themes&amp;themes=' . urlencode( implode( ',', $themes ) );
 214          $nonce = 'bulk-update-themes';
 215  
 216          wp_enqueue_script( 'updates' );
 217          iframe_header();
 218  
 219          $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
 220          $upgrader->bulk_upgrade( $themes );
 221  
 222          iframe_footer();
 223      } elseif ( 'install-theme' === $action ) {
 224  
 225          if ( ! current_user_can( 'install_themes' ) ) {
 226              wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
 227          }
 228  
 229          include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // For themes_api().
 230  
 231          check_admin_referer( 'install-theme_' . $theme );
 232          $api = themes_api(
 233              'theme_information',
 234              array(
 235                  'slug'   => $theme,
 236                  'fields' => array(
 237                      'sections' => false,
 238                      'tags'     => false,
 239                  ),
 240              )
 241          ); // Save on a bit of bandwidth.
 242  
 243          if ( is_wp_error( $api ) ) {
 244              wp_die( $api );
 245          }
 246  
 247          $title        = __( 'Install Themes' );
 248          $parent_file  = 'themes.php';
 249          $submenu_file = 'themes.php';
 250          require_once ABSPATH . 'wp-admin/admin-header.php';
 251  
 252          /* translators: %s: Theme name and version. */
 253          $title = sprintf( __( 'Installing Theme: %s' ), $api->name . ' ' . $api->version );
 254          $nonce = 'install-theme_' . $theme;
 255          $url   = 'update.php?action=install-theme&theme=' . urlencode( $theme );
 256          $type  = 'web'; // Install theme type, From Web or an Upload.
 257  
 258          $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
 259          $upgrader->install( $api->download_link );
 260  
 261          require_once ABSPATH . 'wp-admin/admin-footer.php';
 262  
 263      } elseif ( 'upload-theme' === $action ) {
 264  
 265          if ( ! current_user_can( 'upload_themes' ) ) {
 266              wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
 267          }
 268  
 269          check_admin_referer( 'theme-upload' );
 270  
 271          $file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
 272  
 273          $title        = __( 'Upload Theme' );
 274          $parent_file  = 'themes.php';
 275          $submenu_file = 'theme-install.php';
 276  
 277          require_once ABSPATH . 'wp-admin/admin-header.php';
 278  
 279          /* translators: %s: File name. */
 280          $title = sprintf( __( 'Installing Theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
 281          $nonce = 'theme-upload';
 282          $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' );
 283          $type  = 'upload'; // Install theme type, From Web or an Upload.
 284  
 285          $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
 286          $result   = $upgrader->install( $file_upload->package );
 287  
 288          if ( $result || is_wp_error( $result ) ) {
 289              $file_upload->cleanup();
 290          }
 291  
 292          require_once ABSPATH . 'wp-admin/admin-footer.php';
 293  
 294      } else {
 295          /**
 296           * Fires when a custom plugin or theme update request is received.
 297           *
 298           * The dynamic portion of the hook name, `$action`, refers to the action
 299           * provided in the request for wp-admin/update.php. Can be used to
 300           * provide custom update functionality for themes and plugins.
 301           *
 302           * @since 2.8.0
 303           */
 304          do_action( "update-custom_{$action}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 305      }
 306  }


Generated: Sun Jul 5 01:00:04 2020 Cross-referenced by PHPXref 0.7.1