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