PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/includes/class-wp-upgrader-skins.php

https://bitbucket.org/acipriani/madeinapulia.com
PHP | 784 lines | 513 code | 123 blank | 148 comment | 100 complexity | 9d8c132ccaf6caf1d752be0beeaf051a MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * The User Interface "Skins" for the WordPress File Upgrader
  4. *
  5. * @package WordPress
  6. * @subpackage Upgrader
  7. * @since 2.8.0
  8. */
  9. /**
  10. * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
  11. *
  12. * @package WordPress
  13. * @subpackage Upgrader
  14. * @since 2.8.0
  15. */
  16. class WP_Upgrader_Skin {
  17. public $upgrader;
  18. public $done_header = false;
  19. public $done_footer = false;
  20. public $result = false;
  21. public $options = array();
  22. public function __construct($args = array()) {
  23. $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
  24. $this->options = wp_parse_args($args, $defaults);
  25. }
  26. /**
  27. * @param WP_Upgrader $upgrader
  28. */
  29. public function set_upgrader(&$upgrader) {
  30. if ( is_object($upgrader) )
  31. $this->upgrader =& $upgrader;
  32. $this->add_strings();
  33. }
  34. public function add_strings() {
  35. }
  36. public function set_result($result) {
  37. $this->result = $result;
  38. }
  39. public function request_filesystem_credentials( $error = false, $context = false, $allow_relaxed_file_ownership = false ) {
  40. $url = $this->options['url'];
  41. if ( ! $context ) {
  42. $context = $this->options['context'];
  43. }
  44. if ( !empty($this->options['nonce']) ) {
  45. $url = wp_nonce_url($url, $this->options['nonce']);
  46. }
  47. $extra_fields = array();
  48. return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
  49. }
  50. public function header() {
  51. if ( $this->done_header ) {
  52. return;
  53. }
  54. $this->done_header = true;
  55. echo '<div class="wrap">';
  56. echo '<h2>' . $this->options['title'] . '</h2>';
  57. }
  58. public function footer() {
  59. if ( $this->done_footer ) {
  60. return;
  61. }
  62. $this->done_footer = true;
  63. echo '</div>';
  64. }
  65. public function error($errors) {
  66. if ( ! $this->done_header )
  67. $this->header();
  68. if ( is_string($errors) ) {
  69. $this->feedback($errors);
  70. } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
  71. foreach ( $errors->get_error_messages() as $message ) {
  72. if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
  73. $this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
  74. else
  75. $this->feedback($message);
  76. }
  77. }
  78. }
  79. public function feedback($string) {
  80. if ( isset( $this->upgrader->strings[$string] ) )
  81. $string = $this->upgrader->strings[$string];
  82. if ( strpos($string, '%') !== false ) {
  83. $args = func_get_args();
  84. $args = array_splice($args, 1);
  85. if ( $args ) {
  86. $args = array_map( 'strip_tags', $args );
  87. $args = array_map( 'esc_html', $args );
  88. $string = vsprintf($string, $args);
  89. }
  90. }
  91. if ( empty($string) )
  92. return;
  93. show_message($string);
  94. }
  95. public function before() {}
  96. public function after() {}
  97. /**
  98. * Output JavaScript that calls function to decrement the update counts.
  99. *
  100. * @since 3.9.0
  101. *
  102. * @param string $type Type of update count to decrement. Likely values include 'plugin',
  103. * 'theme', 'translation', etc.
  104. */
  105. protected function decrement_update_count( $type ) {
  106. if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
  107. return;
  108. }
  109. if ( defined( 'IFRAME_REQUEST' ) ) {
  110. echo '<script type="text/javascript">
  111. if ( window.postMessage && JSON ) {
  112. window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
  113. }
  114. </script>';
  115. } else {
  116. echo '<script type="text/javascript">
  117. (function( wp ) {
  118. if ( wp && wp.updates.decrementCount ) {
  119. wp.updates.decrementCount( "' . $type . '" );
  120. }
  121. })( window.wp );
  122. </script>';
  123. }
  124. }
  125. }
  126. /**
  127. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  128. *
  129. * @package WordPress
  130. * @subpackage Upgrader
  131. * @since 2.8.0
  132. */
  133. class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
  134. public $plugin = '';
  135. public $plugin_active = false;
  136. public $plugin_network_active = false;
  137. public function __construct($args = array()) {
  138. $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
  139. $args = wp_parse_args($args, $defaults);
  140. $this->plugin = $args['plugin'];
  141. $this->plugin_active = is_plugin_active( $this->plugin );
  142. $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
  143. parent::__construct($args);
  144. }
  145. public function after() {
  146. $this->plugin = $this->upgrader->plugin_info();
  147. if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
  148. echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) .'"></iframe>';
  149. }
  150. $this->decrement_update_count( 'plugin' );
  151. $update_actions = array(
  152. 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
  153. 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
  154. );
  155. if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
  156. unset( $update_actions['activate_plugin'] );
  157. /**
  158. * Filter the list of action links available following a single plugin update.
  159. *
  160. * @since 2.7.0
  161. *
  162. * @param array $update_actions Array of plugin action links.
  163. * @param string $plugin Path to the plugin file.
  164. */
  165. $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
  166. if ( ! empty($update_actions) )
  167. $this->feedback(implode(' | ', (array)$update_actions));
  168. }
  169. }
  170. /**
  171. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  172. *
  173. * @package WordPress
  174. * @subpackage Upgrader
  175. * @since 3.0.0
  176. */
  177. class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
  178. public $in_loop = false;
  179. public $error = false;
  180. public function __construct($args = array()) {
  181. $defaults = array( 'url' => '', 'nonce' => '' );
  182. $args = wp_parse_args($args, $defaults);
  183. parent::__construct($args);
  184. }
  185. public function add_strings() {
  186. $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
  187. $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>');
  188. $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
  189. $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>'.__('Show Details').'</span><span class="hidden">'.__('Hide Details').'</span>.</a>';
  190. $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
  191. }
  192. /**
  193. * @param string $string
  194. */
  195. public function feedback($string) {
  196. if ( isset( $this->upgrader->strings[$string] ) )
  197. $string = $this->upgrader->strings[$string];
  198. if ( strpos($string, '%') !== false ) {
  199. $args = func_get_args();
  200. $args = array_splice($args, 1);
  201. if ( $args ) {
  202. $args = array_map( 'strip_tags', $args );
  203. $args = array_map( 'esc_html', $args );
  204. $string = vsprintf($string, $args);
  205. }
  206. }
  207. if ( empty($string) )
  208. return;
  209. if ( $this->in_loop )
  210. echo "$string<br />\n";
  211. else
  212. echo "<p>$string</p>\n";
  213. }
  214. public function header() {
  215. // Nothing, This will be displayed within a iframe.
  216. }
  217. public function footer() {
  218. // Nothing, This will be displayed within a iframe.
  219. }
  220. public function error($error) {
  221. if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
  222. $this->error = $this->upgrader->strings[$error];
  223. if ( is_wp_error($error) ) {
  224. $messages = array();
  225. foreach ( $error->get_error_messages() as $emessage ) {
  226. if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
  227. $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
  228. else
  229. $messages[] = $emessage;
  230. }
  231. $this->error = implode(', ', $messages);
  232. }
  233. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  234. }
  235. public function bulk_header() {
  236. $this->feedback('skin_upgrade_start');
  237. }
  238. public function bulk_footer() {
  239. $this->feedback('skin_upgrade_end');
  240. }
  241. public function before($title = '') {
  242. $this->in_loop = true;
  243. printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count);
  244. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
  245. echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
  246. $this->flush_output();
  247. }
  248. public function after($title = '') {
  249. echo '</p></div>';
  250. if ( $this->error || ! $this->result ) {
  251. if ( $this->error )
  252. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
  253. else
  254. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
  255. echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
  256. }
  257. if ( $this->result && ! is_wp_error( $this->result ) ) {
  258. if ( ! $this->error )
  259. echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>';
  260. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  261. }
  262. $this->reset();
  263. $this->flush_output();
  264. }
  265. public function reset() {
  266. $this->in_loop = false;
  267. $this->error = false;
  268. }
  269. public function flush_output() {
  270. wp_ob_end_flush_all();
  271. flush();
  272. }
  273. }
  274. class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
  275. public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
  276. public function __construct($args = array()) {
  277. parent::__construct($args);
  278. }
  279. public function add_strings() {
  280. parent::add_strings();
  281. $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
  282. }
  283. public function before($title = '') {
  284. parent::before($this->plugin_info['Title']);
  285. }
  286. public function after($title = '') {
  287. parent::after($this->plugin_info['Title']);
  288. $this->decrement_update_count( 'plugin' );
  289. }
  290. public function bulk_footer() {
  291. parent::bulk_footer();
  292. $update_actions = array(
  293. 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
  294. 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
  295. );
  296. if ( ! current_user_can( 'activate_plugins' ) )
  297. unset( $update_actions['plugins_page'] );
  298. /**
  299. * Filter the list of action links available following bulk plugin updates.
  300. *
  301. * @since 3.0.0
  302. *
  303. * @param array $update_actions Array of plugin action links.
  304. * @param array $plugin_info Array of information for the last-updated plugin.
  305. */
  306. $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
  307. if ( ! empty($update_actions) )
  308. $this->feedback(implode(' | ', (array)$update_actions));
  309. }
  310. }
  311. class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
  312. public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
  313. public function __construct($args = array()) {
  314. parent::__construct($args);
  315. }
  316. public function add_strings() {
  317. parent::add_strings();
  318. $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
  319. }
  320. public function before($title = '') {
  321. parent::before( $this->theme_info->display('Name') );
  322. }
  323. public function after($title = '') {
  324. parent::after( $this->theme_info->display('Name') );
  325. $this->decrement_update_count( 'theme' );
  326. }
  327. public function bulk_footer() {
  328. parent::bulk_footer();
  329. $update_actions = array(
  330. 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
  331. 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
  332. );
  333. if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
  334. unset( $update_actions['themes_page'] );
  335. /**
  336. * Filter the list of action links available following bulk theme updates.
  337. *
  338. * @since 3.0.0
  339. *
  340. * @param array $update_actions Array of theme action links.
  341. * @param array $theme_info Array of information for the last-updated theme.
  342. */
  343. $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
  344. if ( ! empty($update_actions) )
  345. $this->feedback(implode(' | ', (array)$update_actions));
  346. }
  347. }
  348. /**
  349. * Plugin Installer Skin for WordPress Plugin Installer.
  350. *
  351. * @package WordPress
  352. * @subpackage Upgrader
  353. * @since 2.8.0
  354. */
  355. class Plugin_Installer_Skin extends WP_Upgrader_Skin {
  356. public $api;
  357. public $type;
  358. public function __construct($args = array()) {
  359. $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
  360. $args = wp_parse_args($args, $defaults);
  361. $this->type = $args['type'];
  362. $this->api = isset($args['api']) ? $args['api'] : array();
  363. parent::__construct($args);
  364. }
  365. public function before() {
  366. if ( !empty($this->api) )
  367. $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
  368. }
  369. public function after() {
  370. $plugin_file = $this->upgrader->plugin_info();
  371. $install_actions = array();
  372. $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
  373. if ( 'import' == $from )
  374. $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin &amp; Run Importer') . '</a>';
  375. else
  376. $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
  377. if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
  378. $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>';
  379. unset( $install_actions['activate_plugin'] );
  380. }
  381. if ( 'import' == $from )
  382. $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
  383. else if ( $this->type == 'web' )
  384. $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>';
  385. else
  386. $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>';
  387. if ( ! $this->result || is_wp_error($this->result) ) {
  388. unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
  389. } elseif ( ! current_user_can( 'activate_plugins' ) ) {
  390. unset( $install_actions['activate_plugin'] );
  391. }
  392. /**
  393. * Filter the list of action links available following a single plugin installation.
  394. *
  395. * @since 2.7.0
  396. *
  397. * @param array $install_actions Array of plugin action links.
  398. * @param object $api Object containing WordPress.org API plugin data. Empty
  399. * for non-API installs, such as when a plugin is installed
  400. * via upload.
  401. * @param string $plugin_file Path to the plugin file.
  402. */
  403. $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
  404. if ( ! empty($install_actions) )
  405. $this->feedback(implode(' | ', (array)$install_actions));
  406. }
  407. }
  408. /**
  409. * Theme Installer Skin for the WordPress Theme Installer.
  410. *
  411. * @package WordPress
  412. * @subpackage Upgrader
  413. * @since 2.8.0
  414. */
  415. class Theme_Installer_Skin extends WP_Upgrader_Skin {
  416. public $api;
  417. public $type;
  418. public function __construct($args = array()) {
  419. $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
  420. $args = wp_parse_args($args, $defaults);
  421. $this->type = $args['type'];
  422. $this->api = isset($args['api']) ? $args['api'] : array();
  423. parent::__construct($args);
  424. }
  425. public function before() {
  426. if ( !empty($this->api) )
  427. $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
  428. }
  429. public function after() {
  430. if ( empty($this->upgrader->result['destination_name']) )
  431. return;
  432. $theme_info = $this->upgrader->theme_info();
  433. if ( empty( $theme_info ) )
  434. return;
  435. $name = $theme_info->display('Name');
  436. $stylesheet = $this->upgrader->result['destination_name'];
  437. $template = $theme_info->get_template();
  438. $preview_link = add_query_arg( array(
  439. 'preview' => 1,
  440. 'template' => urlencode( $template ),
  441. 'stylesheet' => urlencode( $stylesheet ),
  442. ), trailingslashit( home_url() ) );
  443. $activate_link = add_query_arg( array(
  444. 'action' => 'activate',
  445. 'template' => urlencode( $template ),
  446. 'stylesheet' => urlencode( $stylesheet ),
  447. ), admin_url('themes.php') );
  448. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  449. $install_actions = array();
  450. $install_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
  451. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  452. $install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
  453. }
  454. $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
  455. if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
  456. $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
  457. if ( $this->type == 'web' )
  458. $install_actions['themes_page'] = '<a href="' . self_admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>';
  459. elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
  460. $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
  461. if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
  462. unset( $install_actions['activate'], $install_actions['preview'] );
  463. /**
  464. * Filter the list of action links available following a single theme installation.
  465. *
  466. * @since 2.8.0
  467. *
  468. * @param array $install_actions Array of theme action links.
  469. * @param object $api Object containing WordPress.org API theme data.
  470. * @param string $stylesheet Theme directory name.
  471. * @param WP_Theme $theme_info Theme object.
  472. */
  473. $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
  474. if ( ! empty($install_actions) )
  475. $this->feedback(implode(' | ', (array)$install_actions));
  476. }
  477. }
  478. /**
  479. * Theme Upgrader Skin for WordPress Theme Upgrades.
  480. *
  481. * @package WordPress
  482. * @subpackage Upgrader
  483. * @since 2.8.0
  484. */
  485. class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
  486. public $theme = '';
  487. public function __construct($args = array()) {
  488. $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
  489. $args = wp_parse_args($args, $defaults);
  490. $this->theme = $args['theme'];
  491. parent::__construct($args);
  492. }
  493. public function after() {
  494. $this->decrement_update_count( 'theme' );
  495. $update_actions = array();
  496. if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
  497. $name = $theme_info->display('Name');
  498. $stylesheet = $this->upgrader->result['destination_name'];
  499. $template = $theme_info->get_template();
  500. $preview_link = add_query_arg( array(
  501. 'preview' => 1,
  502. 'template' => urlencode( $template ),
  503. 'stylesheet' => urlencode( $stylesheet ),
  504. ), trailingslashit( home_url() ) );
  505. $activate_link = add_query_arg( array(
  506. 'action' => 'activate',
  507. 'template' => urlencode( $template ),
  508. 'stylesheet' => urlencode( $stylesheet ),
  509. ), admin_url('themes.php') );
  510. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  511. if ( get_stylesheet() == $stylesheet ) {
  512. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  513. $update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Customize &#8220;%s&#8221;'), $name ) ) . '">' . __('Customize') . '</a>';
  514. }
  515. } elseif ( current_user_can( 'switch_themes' ) ) {
  516. $update_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
  517. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  518. $update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
  519. }
  520. $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
  521. }
  522. if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
  523. unset( $update_actions['preview'], $update_actions['activate'] );
  524. }
  525. $update_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
  526. /**
  527. * Filter the list of action links available following a single theme update.
  528. *
  529. * @since 2.8.0
  530. *
  531. * @param array $update_actions Array of theme action links.
  532. * @param string $theme Theme directory name.
  533. */
  534. $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
  535. if ( ! empty($update_actions) )
  536. $this->feedback(implode(' | ', (array)$update_actions));
  537. }
  538. }
  539. /**
  540. * Translation Upgrader Skin for WordPress Translation Upgrades.
  541. *
  542. * @package WordPress
  543. * @subpackage Upgrader
  544. * @since 3.7.0
  545. */
  546. class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
  547. public $language_update = null;
  548. public $done_header = false;
  549. public $done_footer = false;
  550. public $display_footer_actions = true;
  551. public function __construct( $args = array() ) {
  552. $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
  553. $args = wp_parse_args( $args, $defaults );
  554. if ( $args['skip_header_footer'] ) {
  555. $this->done_header = true;
  556. $this->done_footer = true;
  557. $this->display_footer_actions = false;
  558. }
  559. parent::__construct( $args );
  560. }
  561. public function before() {
  562. $name = $this->upgrader->get_name_for_update( $this->language_update );
  563. echo '<div class="update-messages lp-show-latest">';
  564. printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
  565. }
  566. public function error( $error ) {
  567. echo '<div class="lp-error">';
  568. parent::error( $error );
  569. echo '</div>';
  570. }
  571. public function after() {
  572. echo '</div>';
  573. }
  574. public function bulk_footer() {
  575. $this->decrement_update_count( 'translation' );
  576. $update_actions = array();
  577. $update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" title="' . esc_attr__( 'Go to WordPress Updates page' ) . '" target="_parent">' . __( 'Return to WordPress Updates' ) . '</a>';
  578. /**
  579. * Filter the list of action links available following a translations update.
  580. *
  581. * @since 3.7.0
  582. *
  583. * @param array $update_actions Array of translations update links.
  584. */
  585. $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
  586. if ( $update_actions && $this->display_footer_actions )
  587. $this->feedback( implode( ' | ', $update_actions ) );
  588. }
  589. }
  590. /**
  591. * Upgrader Skin for Automatic WordPress Upgrades
  592. *
  593. * This skin is designed to be used when no output is intended, all output
  594. * is captured and stored for the caller to process and log/email/discard.
  595. *
  596. * @package WordPress
  597. * @subpackage Upgrader
  598. * @since 3.7.0
  599. */
  600. class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
  601. protected $messages = array();
  602. public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
  603. if ( $context ) {
  604. $this->options['context'] = $context;
  605. }
  606. // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
  607. // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
  608. ob_start();
  609. $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
  610. ob_end_clean();
  611. return $result;
  612. }
  613. public function get_upgrade_messages() {
  614. return $this->messages;
  615. }
  616. /**
  617. * @param string|array|WP_Error $data
  618. */
  619. public function feedback( $data ) {
  620. if ( is_wp_error( $data ) )
  621. $string = $data->get_error_message();
  622. else if ( is_array( $data ) )
  623. return;
  624. else
  625. $string = $data;
  626. if ( ! empty( $this->upgrader->strings[ $string ] ) )
  627. $string = $this->upgrader->strings[ $string ];
  628. if ( strpos( $string, '%' ) !== false ) {
  629. $args = func_get_args();
  630. $args = array_splice( $args, 1 );
  631. if ( ! empty( $args ) )
  632. $string = vsprintf( $string, $args );
  633. }
  634. $string = trim( $string );
  635. // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
  636. $string = wp_kses( $string, array(
  637. 'a' => array(
  638. 'href' => true
  639. ),
  640. 'br' => true,
  641. 'em' => true,
  642. 'strong' => true,
  643. ) );
  644. if ( empty( $string ) )
  645. return;
  646. $this->messages[] = $string;
  647. }
  648. public function header() {
  649. ob_start();
  650. }
  651. public function footer() {
  652. $output = ob_get_contents();
  653. if ( ! empty( $output ) )
  654. $this->feedback( $output );
  655. ob_end_clean();
  656. }
  657. public function bulk_header() {}
  658. public function bulk_footer() {}
  659. public function before() {}
  660. public function after() {}
  661. }