Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

99 linhas
3.8 KiB

  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. * @access public
  33. */
  34. public function before() {
  35. if ( !empty($this->api) )
  36. $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
  37. }
  38. /**
  39. * @access public
  40. */
  41. public function after() {
  42. if ( empty($this->upgrader->result['destination_name']) )
  43. return;
  44. $theme_info = $this->upgrader->theme_info();
  45. if ( empty( $theme_info ) )
  46. return;
  47. $name = $theme_info->display('Name');
  48. $stylesheet = $this->upgrader->result['destination_name'];
  49. $template = $theme_info->get_template();
  50. $activate_link = add_query_arg( array(
  51. 'action' => 'activate',
  52. 'template' => urlencode( $template ),
  53. 'stylesheet' => urlencode( $stylesheet ),
  54. ), admin_url('themes.php') );
  55. $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  56. $install_actions = array();
  57. if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  58. $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 &#8220;%s&#8221;' ), $name ) . '</span></a>';
  59. }
  60. $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>';
  61. if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
  62. $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>';
  63. if ( $this->type == 'web' )
  64. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>';
  65. elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
  66. $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
  67. if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
  68. unset( $install_actions['activate'], $install_actions['preview'] );
  69. /**
  70. * Filters the list of action links available following a single theme installation.
  71. *
  72. * @since 2.8.0
  73. *
  74. * @param array $install_actions Array of theme action links.
  75. * @param object $api Object containing WordPress.org API theme data.
  76. * @param string $stylesheet Theme directory name.
  77. * @param WP_Theme $theme_info Theme object.
  78. */
  79. $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
  80. if ( ! empty($install_actions) )
  81. $this->feedback(implode(' | ', (array)$install_actions));
  82. }
  83. }