class-theme-upgrader-skin.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Upgrader API: Theme_Upgrader_Skin class
  4. *
  5. * @package WordPress
  6. * @subpackage Upgrader
  7. * @since 4.6.0
  8. */
  9. /**
  10. * Theme Upgrader Skin for WordPress Theme Upgrades.
  11. *
  12. * @since 2.8.0
  13. * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
  14. *
  15. * @see WP_Upgrader_Skin
  16. */
  17. class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
  18. public $theme = '';
  19. /**
  20. *
  21. * @param array $args
  22. */
  23. public function __construct($args = array()) {
  24. $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
  25. $args = wp_parse_args($args, $defaults);
  26. $this->theme = $args['theme'];
  27. parent::__construct($args);
  28. }
  29. /**
  30. */
  31. public function after() {
  32. $this->decrement_update_count( 'theme' );
  33. $update_actions = array();
  34. if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
  35. $name = $theme_info->display('Name');
  36. $stylesheet = $this->upgrader->result['destination_name'];
  37. $template = $theme_info->get_template();
  38. $activate_link = add_query_arg( array(
  39. 'action' => 'activate',
  40. 'template' => urlencode( $template ),
  41. 'stylesheet' => urlencode( $stylesheet ),
  42. ), admin_url('themes.php') );
  43. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  44. $customize_url = add_query_arg(
  45. array(
  46. 'theme' => urlencode( $stylesheet ),
  47. 'return' => urlencode( admin_url( 'themes.php' ) ),
  48. ),
  49. admin_url( 'customize.php' )
  50. );
  51. if ( get_stylesheet() == $stylesheet ) {
  52. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  53. $update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
  54. }
  55. } elseif ( current_user_can( 'switch_themes' ) ) {
  56. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  57. $update_actions['preview'] = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
  58. }
  59. $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
  60. }
  61. if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
  62. unset( $update_actions['preview'], $update_actions['activate'] );
  63. }
  64. $update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
  65. /**
  66. * Filters the list of action links available following a single theme update.
  67. *
  68. * @since 2.8.0
  69. *
  70. * @param array $update_actions Array of theme action links.
  71. * @param string $theme Theme directory name.
  72. */
  73. $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
  74. if ( ! empty($update_actions) )
  75. $this->feedback(implode(' | ', (array)$update_actions));
  76. }
  77. }