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

/wp-admin/update.php

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