/wp-admin/includes/class-theme-installer-skin.php

  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. /** 
  11. * Theme Installer Skin for the WordPress Theme Installer. 
  12. * 
  13. * @since 2.8.0 
  14. * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. 
  15. * 
  16. * @see WP_Upgrader_Skin 
  17. */ 
  18. class Theme_Installer_Skin extends WP_Upgrader_Skin { 
  19. public $api; 
  20. public $type; 
  21.  
  22. /** 
  23. * 
  24. * @param array $args 
  25. */ 
  26. public function __construct($args = array()) { 
  27. $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); 
  28. $args = wp_parse_args($args, $defaults); 
  29.  
  30. $this->type = $args['type']; 
  31. $this->api = isset($args['api']) ? $args['api'] : array(); 
  32.  
  33. parent::__construct($args); 
  34.  
  35. /** 
  36. * @access public 
  37. */ 
  38. public function before() { 
  39. if ( !empty($this->api) ) 
  40. $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); 
  41.  
  42. /** 
  43. * @access public 
  44. */ 
  45. public function after() { 
  46. if ( empty($this->upgrader->result['destination_name']) ) 
  47. return; 
  48.  
  49. $theme_info = $this->upgrader->theme_info(); 
  50. if ( empty( $theme_info ) ) 
  51. return; 
  52.  
  53. $name = $theme_info->display('Name'); 
  54. $stylesheet = $this->upgrader->result['destination_name']; 
  55. $template = $theme_info->get_template(); 
  56.  
  57. $activate_link = add_query_arg( array( 
  58. 'action' => 'activate',  
  59. 'template' => urlencode( $template ),  
  60. 'stylesheet' => urlencode( $stylesheet ),  
  61. ), admin_url('themes.php') ); 
  62. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); 
  63.  
  64. $install_actions = array(); 
  65.  
  66. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { 
  67. $install_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview “%s”' ), $name ) . '</span></a>'; 
  68. $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate “%s”' ), $name ) . '</span></a>'; 
  69.  
  70. if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) 
  71. $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>'; 
  72.  
  73. if ( $this->type == 'web' ) 
  74. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>'; 
  75. elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) 
  76. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>'; 
  77.  
  78. if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) 
  79. unset( $install_actions['activate'], $install_actions['preview'] ); 
  80.  
  81. /** 
  82. * Filters the list of action links available following a single theme installation. 
  83. * 
  84. * @since 2.8.0 
  85. * 
  86. * @param array $install_actions Array of theme action links. 
  87. * @param object $api Object containing WordPress.org API theme data. 
  88. * @param string $stylesheet Theme directory name. 
  89. * @param WP_Theme $theme_info Theme object. 
  90. */ 
  91. $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info ); 
  92. if ( ! empty($install_actions) ) 
  93. $this->feedback(implode(' | ', (array)$install_actions)); 
.