PageRenderTime 1536ms CodeModel.GetById 57ms RepoModel.GetById 5ms app.codeStats 1ms

/wp-admin/update.php

https://bitbucket.org/aukhanev/xdn-wordpress31
PHP | 254 lines | 176 code | 71 blank | 7 comment | 34 complexity | 20ebfddceae81c72610a8601ba7cfd58 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('./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('jquery');
  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. require_once(ABSPATH . 'wp-admin/admin-header.php');
  43. $nonce = 'upgrade-plugin_' . $plugin;
  44. $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
  45. $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
  46. $upgrader->upgrade($plugin);
  47. include(ABSPATH . 'wp-admin/admin-footer.php');
  48. } elseif ('activate-plugin' == $action ) {
  49. if ( ! current_user_can('update_plugins') )
  50. wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
  51. check_admin_referer('activate-plugin_' . $plugin);
  52. if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
  53. wp_redirect( admin_url('update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
  54. activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
  55. wp_redirect( admin_url('update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
  56. die();
  57. }
  58. iframe_header( __('Plugin Reactivation'), true );
  59. if ( isset($_GET['success']) )
  60. echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
  61. if ( isset($_GET['failure']) ){
  62. echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
  63. if ( defined('E_RECOVERABLE_ERROR') )
  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. else
  66. error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
  67. @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  68. include(WP_PLUGIN_DIR . '/' . $plugin);
  69. }
  70. iframe_footer();
  71. } elseif ( 'install-plugin' == $action ) {
  72. if ( ! current_user_can('install_plugins') )
  73. wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
  74. include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
  75. check_admin_referer('install-plugin_' . $plugin);
  76. $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  77. if ( is_wp_error($api) )
  78. wp_die($api);
  79. $title = __('Plugin Install');
  80. $parent_file = 'plugins.php';
  81. $submenu_file = 'plugin-install.php';
  82. require_once(ABSPATH . 'wp-admin/admin-header.php');
  83. $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
  84. $nonce = 'install-plugin_' . $plugin;
  85. $url = 'update.php?action=install-plugin&plugin=' . $plugin;
  86. if ( isset($_GET['from']) )
  87. $url .= '&from=' . urlencode(stripslashes($_GET['from']));
  88. $type = 'web'; //Install plugin type, From Web or an Upload.
  89. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  90. $upgrader->install($api->download_link);
  91. include(ABSPATH . 'wp-admin/admin-footer.php');
  92. } elseif ( 'upload-plugin' == $action ) {
  93. if ( ! current_user_can('install_plugins') )
  94. wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
  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'), basename( $file_upload->filename ) );
  102. $nonce = 'plugin-upload';
  103. $url = add_query_arg(array('package' => $file_upload->filename ), '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. $upgrader->install( $file_upload->package );
  107. include(ABSPATH . 'wp-admin/admin-footer.php');
  108. } elseif ( 'upgrade-theme' == $action ) {
  109. if ( ! current_user_can('update_themes') )
  110. wp_die(__('You do not have sufficient permissions to update themes for this site.'));
  111. check_admin_referer('upgrade-theme_' . $theme);
  112. add_thickbox();
  113. wp_enqueue_script('theme-preview');
  114. $title = __('Update Theme');
  115. $parent_file = 'themes.php';
  116. $submenu_file = 'themes.php';
  117. require_once(ABSPATH . 'wp-admin/admin-header.php');
  118. $nonce = 'upgrade-theme_' . $theme;
  119. $url = 'update.php?action=upgrade-theme&theme=' . $theme;
  120. $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
  121. $upgrader->upgrade($theme);
  122. include(ABSPATH . 'wp-admin/admin-footer.php');
  123. } elseif ( 'update-selected-themes' == $action ) {
  124. if ( ! current_user_can( 'update_themes' ) )
  125. wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
  126. check_admin_referer( 'bulk-update-themes' );
  127. if ( isset( $_GET['themes'] ) )
  128. $themes = explode( ',', stripslashes($_GET['themes']) );
  129. elseif ( isset( $_POST['checked'] ) )
  130. $themes = (array) $_POST['checked'];
  131. else
  132. $themes = array();
  133. $themes = array_map('urldecode', $themes);
  134. $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
  135. $nonce = 'bulk-update-themes';
  136. wp_enqueue_script('jquery');
  137. iframe_header();
  138. $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  139. $upgrader->bulk_upgrade( $themes );
  140. iframe_footer();
  141. } elseif ( 'install-theme' == $action ) {
  142. if ( ! current_user_can('install_themes') )
  143. wp_die(__('You do not have sufficient permissions to install themes for this site.'));
  144. include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
  145. check_admin_referer('install-theme_' . $theme);
  146. $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  147. if ( is_wp_error($api) )
  148. wp_die($api);
  149. add_thickbox();
  150. wp_enqueue_script('theme-preview');
  151. $title = __('Install Themes');
  152. $parent_file = 'themes.php';
  153. $submenu_file = 'themes.php';
  154. require_once(ABSPATH . 'wp-admin/admin-header.php');
  155. $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
  156. $nonce = 'install-theme_' . $theme;
  157. $url = 'update.php?action=install-theme&theme=' . $theme;
  158. $type = 'web'; //Install theme type, From Web or an Upload.
  159. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  160. $upgrader->install($api->download_link);
  161. include(ABSPATH . 'wp-admin/admin-footer.php');
  162. } elseif ( 'upload-theme' == $action ) {
  163. if ( ! current_user_can('install_themes') )
  164. wp_die(__('You do not have sufficient permissions to install themes for this site.'));
  165. check_admin_referer('theme-upload');
  166. $file_upload = new File_Upload_Upgrader('themezip', 'package');
  167. $title = __('Upload Theme');
  168. $parent_file = 'themes.php';
  169. $submenu_file = 'theme-install.php';
  170. add_thickbox();
  171. wp_enqueue_script('theme-preview');
  172. require_once(ABSPATH . 'wp-admin/admin-header.php');
  173. $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
  174. $nonce = 'theme-upload';
  175. $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
  176. $type = 'upload'; //Install plugin type, From Web or an Upload.
  177. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  178. $upgrader->install( $file_upload->package );
  179. include(ABSPATH . 'wp-admin/admin-footer.php');
  180. } else {
  181. do_action('update-custom_' . $action);
  182. }
  183. }