Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

290 wiersze
10 KiB

  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( __( 'Sorry, you are not allowed 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(__('Sorry, you are not allowed 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(__('Sorry, you are not allowed 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( __( 'Sorry, you are not allowed 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(
  76. 'slug' => $plugin,
  77. 'fields' => array(
  78. 'short_description' => false,
  79. 'sections' => false,
  80. 'requires' => false,
  81. 'rating' => false,
  82. 'ratings' => false,
  83. 'downloaded' => false,
  84. 'last_updated' => false,
  85. 'added' => false,
  86. 'tags' => false,
  87. 'compatibility' => false,
  88. 'homepage' => false,
  89. 'donate_link' => false,
  90. ),
  91. ) );
  92. if ( is_wp_error( $api ) ) {
  93. wp_die( $api );
  94. }
  95. $title = __('Plugin Install');
  96. $parent_file = 'plugins.php';
  97. $submenu_file = 'plugin-install.php';
  98. require_once(ABSPATH . 'wp-admin/admin-header.php');
  99. $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
  100. $nonce = 'install-plugin_' . $plugin;
  101. $url = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
  102. if ( isset($_GET['from']) )
  103. $url .= '&from=' . urlencode(stripslashes($_GET['from']));
  104. $type = 'web'; //Install plugin type, From Web or an Upload.
  105. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  106. $upgrader->install($api->download_link);
  107. include(ABSPATH . 'wp-admin/admin-footer.php');
  108. } elseif ( 'upload-plugin' == $action ) {
  109. if ( ! current_user_can( 'upload_plugins' ) ) {
  110. wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
  111. }
  112. check_admin_referer('plugin-upload');
  113. $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
  114. $title = __('Upload Plugin');
  115. $parent_file = 'plugins.php';
  116. $submenu_file = 'plugin-install.php';
  117. require_once(ABSPATH . 'wp-admin/admin-header.php');
  118. $title = sprintf( __('Installing Plugin from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
  119. $nonce = 'plugin-upload';
  120. $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin');
  121. $type = 'upload'; //Install plugin type, From Web or an Upload.
  122. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  123. $result = $upgrader->install( $file_upload->package );
  124. if ( $result || is_wp_error($result) )
  125. $file_upload->cleanup();
  126. include(ABSPATH . 'wp-admin/admin-footer.php');
  127. } elseif ( 'upgrade-theme' == $action ) {
  128. if ( ! current_user_can('update_themes') )
  129. wp_die(__('Sorry, you are not allowed to update themes for this site.'));
  130. check_admin_referer('upgrade-theme_' . $theme);
  131. wp_enqueue_script( 'customize-loader' );
  132. wp_enqueue_script( 'updates' );
  133. $title = __('Update Theme');
  134. $parent_file = 'themes.php';
  135. $submenu_file = 'themes.php';
  136. require_once(ABSPATH . 'wp-admin/admin-header.php');
  137. $nonce = 'upgrade-theme_' . $theme;
  138. $url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
  139. $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
  140. $upgrader->upgrade($theme);
  141. include(ABSPATH . 'wp-admin/admin-footer.php');
  142. } elseif ( 'update-selected-themes' == $action ) {
  143. if ( ! current_user_can( 'update_themes' ) )
  144. wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
  145. check_admin_referer( 'bulk-update-themes' );
  146. if ( isset( $_GET['themes'] ) )
  147. $themes = explode( ',', stripslashes($_GET['themes']) );
  148. elseif ( isset( $_POST['checked'] ) )
  149. $themes = (array) $_POST['checked'];
  150. else
  151. $themes = array();
  152. $themes = array_map('urldecode', $themes);
  153. $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
  154. $nonce = 'bulk-update-themes';
  155. wp_enqueue_script( 'updates' );
  156. iframe_header();
  157. $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  158. $upgrader->bulk_upgrade( $themes );
  159. iframe_footer();
  160. } elseif ( 'install-theme' == $action ) {
  161. if ( ! current_user_can('install_themes') )
  162. wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
  163. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); //for themes_api..
  164. check_admin_referer( 'install-theme_' . $theme );
  165. $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
  166. if ( is_wp_error($api) )
  167. wp_die($api);
  168. wp_enqueue_script( 'customize-loader' );
  169. $title = __('Install Themes');
  170. $parent_file = 'themes.php';
  171. $submenu_file = 'themes.php';
  172. require_once(ABSPATH . 'wp-admin/admin-header.php');
  173. $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
  174. $nonce = 'install-theme_' . $theme;
  175. $url = 'update.php?action=install-theme&theme=' . urlencode( $theme );
  176. $type = 'web'; //Install theme type, From Web or an Upload.
  177. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  178. $upgrader->install($api->download_link);
  179. include(ABSPATH . 'wp-admin/admin-footer.php');
  180. } elseif ( 'upload-theme' == $action ) {
  181. if ( ! current_user_can( 'upload_themes' ) ) {
  182. wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
  183. }
  184. check_admin_referer('theme-upload');
  185. $file_upload = new File_Upload_Upgrader('themezip', 'package');
  186. wp_enqueue_script( 'customize-loader' );
  187. $title = __('Upload Theme');
  188. $parent_file = 'themes.php';
  189. $submenu_file = 'theme-install.php';
  190. require_once(ABSPATH . 'wp-admin/admin-header.php');
  191. $title = sprintf( __('Installing Theme from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
  192. $nonce = 'theme-upload';
  193. $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme');
  194. $type = 'upload'; //Install plugin type, From Web or an Upload.
  195. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  196. $result = $upgrader->install( $file_upload->package );
  197. if ( $result || is_wp_error($result) )
  198. $file_upload->cleanup();
  199. include(ABSPATH . 'wp-admin/admin-footer.php');
  200. } else {
  201. /**
  202. * Fires when a custom plugin or theme update request is received.
  203. *
  204. * The dynamic portion of the hook name, `$action`, refers to the action
  205. * provided in the request for wp-admin/update.php. Can be used to
  206. * provide custom update functionality for themes and plugins.
  207. *
  208. * @since 2.8.0
  209. */
  210. do_action( "update-custom_{$action}" );
  211. }
  212. }