[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-admin/includes/ -> class-theme-installer-skin.php (source)

   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       * @param array $args
  24       */
  25  	public function __construct( $args = array() ) {
  26          $defaults = array(
  27              'type'  => 'web',
  28              'url'   => '',
  29              'theme' => '',
  30              'nonce' => '',
  31              'title' => '',
  32          );
  33          $args     = wp_parse_args( $args, $defaults );
  34  
  35          $this->type = $args['type'];
  36          $this->api  = isset( $args['api'] ) ? $args['api'] : array();
  37  
  38          parent::__construct( $args );
  39      }
  40  
  41      /**
  42       */
  43  	public function before() {
  44          if ( ! empty( $this->api ) ) {
  45              $this->upgrader->strings['process_success'] = sprintf(
  46                  $this->upgrader->strings['process_success_specific'],
  47                  $this->api->name,
  48                  $this->api->version
  49              );
  50          }
  51      }
  52  
  53      /**
  54       */
  55  	public function after() {
  56          if ( empty( $this->upgrader->result['destination_name'] ) ) {
  57              return;
  58          }
  59  
  60          $theme_info = $this->upgrader->theme_info();
  61          if ( empty( $theme_info ) ) {
  62              return;
  63          }
  64  
  65          $name       = $theme_info->display( 'Name' );
  66          $stylesheet = $this->upgrader->result['destination_name'];
  67          $template   = $theme_info->get_template();
  68  
  69          $activate_link = add_query_arg(
  70              array(
  71                  'action'     => 'activate',
  72                  'template'   => urlencode( $template ),
  73                  'stylesheet' => urlencode( $stylesheet ),
  74              ),
  75              admin_url( 'themes.php' )
  76          );
  77          $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
  78  
  79          $install_actions = array();
  80  
  81          if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  82              $customize_url = add_query_arg(
  83                  array(
  84                      'theme'  => urlencode( $stylesheet ),
  85                      'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ),
  86                  ),
  87                  admin_url( 'customize.php' )
  88              );
  89  
  90              $install_actions['preview'] = sprintf(
  91                  '<a href="%s" class="hide-if-no-customize load-customize">' .
  92                  '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
  93                  esc_url( $customize_url ),
  94                  __( 'Live Preview' ),
  95                  /* translators: %s: Theme name. */
  96                  sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name )
  97              );
  98          }
  99  
 100          $install_actions['activate'] = sprintf(
 101              '<a href="%s" class="activatelink">' .
 102              '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
 103              esc_url( $activate_link ),
 104              __( 'Activate' ),
 105              /* translators: %s: Theme name. */
 106              sprintf( __( 'Activate &#8220;%s&#8221;' ), $name )
 107          );
 108  
 109          if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) {
 110              $install_actions['network_enable'] = sprintf(
 111                  '<a href="%s" target="_parent">%s</a>',
 112                  esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ),
 113                  __( 'Network Enable' )
 114              );
 115          }
 116  
 117          if ( $this->type == 'web' ) {
 118              $install_actions['themes_page'] = sprintf(
 119                  '<a href="%s" target="_parent">%s</a>',
 120                  self_admin_url( 'theme-install.php' ),
 121                  __( 'Return to Theme Installer' )
 122              );
 123          } elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) {
 124              $install_actions['themes_page'] = sprintf(
 125                  '<a href="%s" target="_parent">%s</a>',
 126                  self_admin_url( 'themes.php' ),
 127                  __( 'Return to Themes page' )
 128              );
 129          }
 130  
 131          if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) {
 132              unset( $install_actions['activate'], $install_actions['preview'] );
 133          }
 134  
 135          /**
 136           * Filters the list of action links available following a single theme installation.
 137           *
 138           * @since 2.8.0
 139           *
 140           * @param string[] $install_actions Array of theme action links.
 141           * @param object   $api             Object containing WordPress.org API theme data.
 142           * @param string   $stylesheet      Theme directory name.
 143           * @param WP_Theme $theme_info      Theme object.
 144           */
 145          $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
 146          if ( ! empty( $install_actions ) ) {
 147              $this->feedback( implode( ' | ', (array) $install_actions ) );
 148          }
 149      }
 150  }


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7