class-theme-installer-skin.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Upgrader API: Theme_Installer_Skin class
  4. *
  5. * @package WordPress
  6. * @subpackage Upgrader
  7. * @since 4.6.0
  8. */
  9. /**
  10. * Theme Installer Skin for the WordPress Theme Installer.
  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_Installer_Skin extends WP_Upgrader_Skin {
  18. public $api;
  19. public $type;
  20. /**
  21. *
  22. * @param array $args
  23. */
  24. public function __construct($args = array()) {
  25. $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
  26. $args = wp_parse_args($args, $defaults);
  27. $this->type = $args['type'];
  28. $this->api = isset($args['api']) ? $args['api'] : array();
  29. parent::__construct($args);
  30. }
  31. /**
  32. */
  33. public function before() {
  34. if ( !empty($this->api) )
  35. $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
  36. }
  37. /**
  38. */
  39. public function after() {
  40. if ( empty($this->upgrader->result['destination_name']) )
  41. return;
  42. $theme_info = $this->upgrader->theme_info();
  43. if ( empty( $theme_info ) )
  44. return;
  45. $name = $theme_info->display('Name');
  46. $stylesheet = $this->upgrader->result['destination_name'];
  47. $template = $theme_info->get_template();
  48. $activate_link = add_query_arg( array(
  49. 'action' => 'activate',
  50. 'template' => urlencode( $template ),
  51. 'stylesheet' => urlencode( $stylesheet ),
  52. ), admin_url('themes.php') );
  53. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  54. $install_actions = array();
  55. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  56. $customize_url = add_query_arg(
  57. array(
  58. 'theme' => urlencode( $stylesheet ),
  59. 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ),
  60. ),
  61. admin_url( 'customize.php' )
  62. );
  63. $install_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>';
  64. }
  65. $install_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>';
  66. if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
  67. $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
  68. if ( $this->type == 'web' )
  69. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>';
  70. elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
  71. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
  72. if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
  73. unset( $install_actions['activate'], $install_actions['preview'] );
  74. /**
  75. * Filters the list of action links available following a single theme installation.
  76. *
  77. * @since 2.8.0
  78. *
  79. * @param array $install_actions Array of theme action links.
  80. * @param object $api Object containing WordPress.org API theme data.
  81. * @param string $stylesheet Theme directory name.
  82. * @param WP_Theme $theme_info Theme object.
  83. */
  84. $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
  85. if ( ! empty($install_actions) )
  86. $this->feedback(implode(' | ', (array)$install_actions));
  87. }
  88. }