PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/update.php

http://github.com/wordpress/wordpress
PHP | 306 lines | 211 code | 75 blank | 20 comment | 39 complexity | 6c9abe46f975374d98b1c814c49e43f0 MD5 | raw file
Possible License(s): 0BSD
  1. <?php
  2. /**
  3. * Update/Install Plugin/Theme administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. if ( ! defined( 'IFRAME_REQUEST' )
  9. && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ), true )
  10. ) {
  11. define( 'IFRAME_REQUEST', true );
  12. }
  13. /** WordPress Administration Bootstrap */
  14. require_once __DIR__ . '/admin.php';
  15. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  16. if ( isset( $_GET['action'] ) ) {
  17. $plugin = isset( $_REQUEST['plugin'] ) ? trim( $_REQUEST['plugin'] ) : '';
  18. $theme = isset( $_REQUEST['theme'] ) ? urldecode( $_REQUEST['theme'] ) : '';
  19. $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
  20. if ( 'update-selected' == $action ) {
  21. if ( ! current_user_can( 'update_plugins' ) ) {
  22. wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  23. }
  24. check_admin_referer( 'bulk-update-plugins' );
  25. if ( isset( $_GET['plugins'] ) ) {
  26. $plugins = explode( ',', stripslashes( $_GET['plugins'] ) );
  27. } elseif ( isset( $_POST['checked'] ) ) {
  28. $plugins = (array) $_POST['checked'];
  29. } else {
  30. $plugins = array();
  31. }
  32. $plugins = array_map( 'urldecode', $plugins );
  33. $url = 'update.php?action=update-selected&amp;plugins=' . urlencode( implode( ',', $plugins ) );
  34. $nonce = 'bulk-update-plugins';
  35. wp_enqueue_script( 'updates' );
  36. iframe_header();
  37. $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  38. $upgrader->bulk_upgrade( $plugins );
  39. iframe_footer();
  40. } elseif ( 'upgrade-plugin' == $action ) {
  41. if ( ! current_user_can( 'update_plugins' ) ) {
  42. wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  43. }
  44. check_admin_referer( 'upgrade-plugin_' . $plugin );
  45. $title = __( 'Update Plugin' );
  46. $parent_file = 'plugins.php';
  47. $submenu_file = 'plugins.php';
  48. wp_enqueue_script( 'updates' );
  49. require_once ABSPATH . 'wp-admin/admin-header.php';
  50. $nonce = 'upgrade-plugin_' . $plugin;
  51. $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
  52. $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ) );
  53. $upgrader->upgrade( $plugin );
  54. require_once ABSPATH . 'wp-admin/admin-footer.php';
  55. } elseif ( 'activate-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. check_admin_referer( 'activate-plugin_' . $plugin );
  60. if ( ! isset( $_GET['failure'] ) && ! isset( $_GET['success'] ) ) {
  61. wp_redirect( admin_url( 'update.php?action=activate-plugin&failure=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
  62. activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
  63. wp_redirect( admin_url( 'update.php?action=activate-plugin&success=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
  64. die();
  65. }
  66. iframe_header( __( 'Plugin Reactivation' ), true );
  67. if ( isset( $_GET['success'] ) ) {
  68. echo '<p>' . __( 'Plugin reactivated successfully.' ) . '</p>';
  69. }
  70. if ( isset( $_GET['failure'] ) ) {
  71. echo '<p>' . __( 'Plugin failed to reactivate due to a fatal error.' ) . '</p>';
  72. 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 );
  73. ini_set( 'display_errors', true ); // Ensure that fatal errors are displayed.
  74. wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
  75. include WP_PLUGIN_DIR . '/' . $plugin;
  76. }
  77. iframe_footer();
  78. } elseif ( 'install-plugin' == $action ) {
  79. if ( ! current_user_can( 'install_plugins' ) ) {
  80. wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
  81. }
  82. include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api().
  83. check_admin_referer( 'install-plugin_' . $plugin );
  84. $api = plugins_api(
  85. 'plugin_information',
  86. array(
  87. 'slug' => $plugin,
  88. 'fields' => array(
  89. 'sections' => false,
  90. ),
  91. )
  92. );
  93. if ( is_wp_error( $api ) ) {
  94. wp_die( $api );
  95. }
  96. $title = __( 'Plugin Installation' );
  97. $parent_file = 'plugins.php';
  98. $submenu_file = 'plugin-install.php';
  99. require_once ABSPATH . 'wp-admin/admin-header.php';
  100. /* translators: %s: Plugin name and version. */
  101. $title = sprintf( __( 'Installing Plugin: %s' ), $api->name . ' ' . $api->version );
  102. $nonce = 'install-plugin_' . $plugin;
  103. $url = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
  104. if ( isset( $_GET['from'] ) ) {
  105. $url .= '&from=' . urlencode( stripslashes( $_GET['from'] ) );
  106. }
  107. $type = 'web'; // Install plugin type, From Web or an Upload.
  108. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
  109. $upgrader->install( $api->download_link );
  110. require_once ABSPATH . 'wp-admin/admin-footer.php';
  111. } elseif ( 'upload-plugin' == $action ) {
  112. if ( ! current_user_can( 'upload_plugins' ) ) {
  113. wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
  114. }
  115. check_admin_referer( 'plugin-upload' );
  116. $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
  117. $title = __( 'Upload Plugin' );
  118. $parent_file = 'plugins.php';
  119. $submenu_file = 'plugin-install.php';
  120. require_once ABSPATH . 'wp-admin/admin-header.php';
  121. /* translators: %s: File name. */
  122. $title = sprintf( __( 'Installing Plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
  123. $nonce = 'plugin-upload';
  124. $url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' );
  125. $type = 'upload'; // Install plugin type, From Web or an Upload.
  126. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
  127. $result = $upgrader->install( $file_upload->package );
  128. if ( $result || is_wp_error( $result ) ) {
  129. $file_upload->cleanup();
  130. }
  131. require_once ABSPATH . 'wp-admin/admin-footer.php';
  132. } elseif ( 'upgrade-theme' == $action ) {
  133. if ( ! current_user_can( 'update_themes' ) ) {
  134. wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
  135. }
  136. check_admin_referer( 'upgrade-theme_' . $theme );
  137. wp_enqueue_script( 'updates' );
  138. $title = __( 'Update Theme' );
  139. $parent_file = 'themes.php';
  140. $submenu_file = 'themes.php';
  141. require_once ABSPATH . 'wp-admin/admin-header.php';
  142. $nonce = 'upgrade-theme_' . $theme;
  143. $url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
  144. $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
  145. $upgrader->upgrade( $theme );
  146. require_once ABSPATH . 'wp-admin/admin-footer.php';
  147. } elseif ( 'update-selected-themes' == $action ) {
  148. if ( ! current_user_can( 'update_themes' ) ) {
  149. wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
  150. }
  151. check_admin_referer( 'bulk-update-themes' );
  152. if ( isset( $_GET['themes'] ) ) {
  153. $themes = explode( ',', stripslashes( $_GET['themes'] ) );
  154. } elseif ( isset( $_POST['checked'] ) ) {
  155. $themes = (array) $_POST['checked'];
  156. } else {
  157. $themes = array();
  158. }
  159. $themes = array_map( 'urldecode', $themes );
  160. $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode( implode( ',', $themes ) );
  161. $nonce = 'bulk-update-themes';
  162. wp_enqueue_script( 'updates' );
  163. iframe_header();
  164. $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  165. $upgrader->bulk_upgrade( $themes );
  166. iframe_footer();
  167. } elseif ( 'install-theme' == $action ) {
  168. if ( ! current_user_can( 'install_themes' ) ) {
  169. wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
  170. }
  171. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // For themes_api().
  172. check_admin_referer( 'install-theme_' . $theme );
  173. $api = themes_api(
  174. 'theme_information',
  175. array(
  176. 'slug' => $theme,
  177. 'fields' => array(
  178. 'sections' => false,
  179. 'tags' => false,
  180. ),
  181. )
  182. ); // Save on a bit of bandwidth.
  183. if ( is_wp_error( $api ) ) {
  184. wp_die( $api );
  185. }
  186. $title = __( 'Install Themes' );
  187. $parent_file = 'themes.php';
  188. $submenu_file = 'themes.php';
  189. require_once ABSPATH . 'wp-admin/admin-header.php';
  190. /* translators: %s: Theme name and version. */
  191. $title = sprintf( __( 'Installing Theme: %s' ), $api->name . ' ' . $api->version );
  192. $nonce = 'install-theme_' . $theme;
  193. $url = 'update.php?action=install-theme&theme=' . urlencode( $theme );
  194. $type = 'web'; // Install theme type, From Web or an Upload.
  195. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
  196. $upgrader->install( $api->download_link );
  197. require_once ABSPATH . 'wp-admin/admin-footer.php';
  198. } elseif ( 'upload-theme' == $action ) {
  199. if ( ! current_user_can( 'upload_themes' ) ) {
  200. wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
  201. }
  202. check_admin_referer( 'theme-upload' );
  203. $file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
  204. $title = __( 'Upload Theme' );
  205. $parent_file = 'themes.php';
  206. $submenu_file = 'theme-install.php';
  207. require_once ABSPATH . 'wp-admin/admin-header.php';
  208. /* translators: %s: File name. */
  209. $title = sprintf( __( 'Installing Theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
  210. $nonce = 'theme-upload';
  211. $url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' );
  212. $type = 'upload'; // Install theme type, From Web or an Upload.
  213. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
  214. $result = $upgrader->install( $file_upload->package );
  215. if ( $result || is_wp_error( $result ) ) {
  216. $file_upload->cleanup();
  217. }
  218. require_once ABSPATH . 'wp-admin/admin-footer.php';
  219. } else {
  220. /**
  221. * Fires when a custom plugin or theme update request is received.
  222. *
  223. * The dynamic portion of the hook name, `$action`, refers to the action
  224. * provided in the request for wp-admin/update.php. Can be used to
  225. * provide custom update functionality for themes and plugins.
  226. *
  227. * @since 2.8.0
  228. */
  229. do_action( "update-custom_{$action}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  230. }
  231. }