PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/update.php

https://bitbucket.org/zachisit/zachis.it-m
PHP | 257 lines | 174 code | 76 blank | 7 comment | 37 complexity | d6e5fced67ba1870ebaebda92179c333 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. 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 );
  64. @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  65. include(WP_PLUGIN_DIR . '/' . $plugin);
  66. }
  67. iframe_footer();
  68. } elseif ( 'install-plugin' == $action ) {
  69. if ( ! current_user_can('install_plugins') )
  70. wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
  71. include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
  72. check_admin_referer('install-plugin_' . $plugin);
  73. $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  74. if ( is_wp_error($api) )
  75. wp_die($api);
  76. $title = __('Plugin Install');
  77. $parent_file = 'plugins.php';
  78. $submenu_file = 'plugin-install.php';
  79. require_once(ABSPATH . 'wp-admin/admin-header.php');
  80. $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
  81. $nonce = 'install-plugin_' . $plugin;
  82. $url = 'update.php?action=install-plugin&plugin=' . $plugin;
  83. if ( isset($_GET['from']) )
  84. $url .= '&from=' . urlencode(stripslashes($_GET['from']));
  85. $type = 'web'; //Install plugin type, From Web or an Upload.
  86. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  87. $upgrader->install($api->download_link);
  88. include(ABSPATH . 'wp-admin/admin-footer.php');
  89. } elseif ( 'upload-plugin' == $action ) {
  90. if ( ! current_user_can('install_plugins') )
  91. wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
  92. check_admin_referer('plugin-upload');
  93. $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
  94. $title = __('Upload Plugin');
  95. $parent_file = 'plugins.php';
  96. $submenu_file = 'plugin-install.php';
  97. require_once(ABSPATH . 'wp-admin/admin-header.php');
  98. $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
  99. $nonce = 'plugin-upload';
  100. $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin');
  101. $type = 'upload'; //Install plugin type, From Web or an Upload.
  102. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  103. $result = $upgrader->install( $file_upload->package );
  104. if ( $result || is_wp_error($result) )
  105. $file_upload->cleanup();
  106. include(ABSPATH . 'wp-admin/admin-footer.php');
  107. } elseif ( 'upgrade-theme' == $action ) {
  108. if ( ! current_user_can('update_themes') )
  109. wp_die(__('You do not have sufficient permissions to update themes for this site.'));
  110. check_admin_referer('upgrade-theme_' . $theme);
  111. wp_enqueue_script( 'customize-loader' );
  112. $title = __('Update Theme');
  113. $parent_file = 'themes.php';
  114. $submenu_file = 'themes.php';
  115. require_once(ABSPATH . 'wp-admin/admin-header.php');
  116. $nonce = 'upgrade-theme_' . $theme;
  117. $url = 'update.php?action=upgrade-theme&theme=' . $theme;
  118. $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
  119. $upgrader->upgrade($theme);
  120. include(ABSPATH . 'wp-admin/admin-footer.php');
  121. } elseif ( 'update-selected-themes' == $action ) {
  122. if ( ! current_user_can( 'update_themes' ) )
  123. wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
  124. check_admin_referer( 'bulk-update-themes' );
  125. if ( isset( $_GET['themes'] ) )
  126. $themes = explode( ',', stripslashes($_GET['themes']) );
  127. elseif ( isset( $_POST['checked'] ) )
  128. $themes = (array) $_POST['checked'];
  129. else
  130. $themes = array();
  131. $themes = array_map('urldecode', $themes);
  132. $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
  133. $nonce = 'bulk-update-themes';
  134. wp_enqueue_script('jquery');
  135. iframe_header();
  136. $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  137. $upgrader->bulk_upgrade( $themes );
  138. iframe_footer();
  139. } elseif ( 'install-theme' == $action ) {
  140. if ( ! current_user_can('install_themes') )
  141. wp_die(__('You do not have sufficient permissions to install themes for this site.'));
  142. include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
  143. check_admin_referer('install-theme_' . $theme);
  144. $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
  145. if ( is_wp_error($api) )
  146. wp_die($api);
  147. wp_enqueue_script( 'customize-loader' );
  148. $title = __('Install Themes');
  149. $parent_file = 'themes.php';
  150. $submenu_file = 'themes.php';
  151. require_once(ABSPATH . 'wp-admin/admin-header.php');
  152. $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
  153. $nonce = 'install-theme_' . $theme;
  154. $url = 'update.php?action=install-theme&theme=' . $theme;
  155. $type = 'web'; //Install theme type, From Web or an Upload.
  156. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  157. $upgrader->install($api->download_link);
  158. include(ABSPATH . 'wp-admin/admin-footer.php');
  159. } elseif ( 'upload-theme' == $action ) {
  160. if ( ! current_user_can('install_themes') )
  161. wp_die(__('You do not have sufficient permissions to install themes for this site.'));
  162. check_admin_referer('theme-upload');
  163. $file_upload = new File_Upload_Upgrader('themezip', 'package');
  164. wp_enqueue_script( 'customize-loader' );
  165. $title = __('Upload Theme');
  166. $parent_file = 'themes.php';
  167. $submenu_file = 'theme-install.php';
  168. require_once(ABSPATH . 'wp-admin/admin-header.php');
  169. $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
  170. $nonce = 'theme-upload';
  171. $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme');
  172. $type = 'upload'; //Install plugin type, From Web or an Upload.
  173. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  174. $result = $upgrader->install( $file_upload->package );
  175. if ( $result || is_wp_error($result) )
  176. $file_upload->cleanup();
  177. include(ABSPATH . 'wp-admin/admin-footer.php');
  178. } else {
  179. do_action('update-custom_' . $action);
  180. }
  181. }