class-theme-upgrader-skin.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * @param array $args
  21. */
  22. public function __construct( $args = array() ) {
  23. $defaults = array(
  24. 'url' => '',
  25. 'theme' => '',
  26. 'nonce' => '',
  27. 'title' => __( 'Update Theme' ),
  28. );
  29. $args = wp_parse_args( $args, $defaults );
  30. $this->theme = $args['theme'];
  31. parent::__construct( $args );
  32. }
  33. /**
  34. */
  35. public function after() {
  36. $this->decrement_update_count( 'theme' );
  37. $update_actions = array();
  38. $theme_info = $this->upgrader->theme_info();
  39. if ( $theme_info ) {
  40. $name = $theme_info->display( 'Name' );
  41. $stylesheet = $this->upgrader->result['destination_name'];
  42. $template = $theme_info->get_template();
  43. $activate_link = add_query_arg(
  44. array(
  45. 'action' => 'activate',
  46. 'template' => urlencode( $template ),
  47. 'stylesheet' => urlencode( $stylesheet ),
  48. ),
  49. admin_url( 'themes.php' )
  50. );
  51. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  52. $customize_url = add_query_arg(
  53. array(
  54. 'theme' => urlencode( $stylesheet ),
  55. 'return' => urlencode( admin_url( 'themes.php' ) ),
  56. ),
  57. admin_url( 'customize.php' )
  58. );
  59. if ( get_stylesheet() == $stylesheet ) {
  60. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  61. $update_actions['preview'] = sprintf(
  62. '<a href="%s" class="hide-if-no-customize load-customize">' .
  63. '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
  64. esc_url( $customize_url ),
  65. __( 'Customize' ),
  66. /* translators: %s: Theme name. */
  67. sprintf( __( 'Customize &#8220;%s&#8221;' ), $name )
  68. );
  69. }
  70. } elseif ( current_user_can( 'switch_themes' ) ) {
  71. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  72. $update_actions['preview'] = sprintf(
  73. '<a href="%s" class="hide-if-no-customize load-customize">' .
  74. '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
  75. esc_url( $customize_url ),
  76. __( 'Live Preview' ),
  77. /* translators: %s: Theme name. */
  78. sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name )
  79. );
  80. }
  81. $update_actions['activate'] = sprintf(
  82. '<a href="%s" class="activatelink">' .
  83. '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
  84. esc_url( $activate_link ),
  85. __( 'Activate' ),
  86. /* translators: %s: Theme name. */
  87. sprintf( __( 'Activate &#8220;%s&#8221;' ), $name )
  88. );
  89. }
  90. if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) {
  91. unset( $update_actions['preview'], $update_actions['activate'] );
  92. }
  93. }
  94. $update_actions['themes_page'] = sprintf(
  95. '<a href="%s" target="_parent">%s</a>',
  96. self_admin_url( 'themes.php' ),
  97. __( 'Return to Themes page' )
  98. );
  99. /**
  100. * Filters the list of action links available following a single theme update.
  101. *
  102. * @since 2.8.0
  103. *
  104. * @param string[] $update_actions Array of theme action links.
  105. * @param string $theme Theme directory name.
  106. */
  107. $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
  108. if ( ! empty( $update_actions ) ) {
  109. $this->feedback( implode( ' | ', (array) $update_actions ) );
  110. }
  111. }
  112. }