wp/wp-admin/includes/class-theme-upgrader-skin.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    17  */
    17  */
    18 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
    18 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
    19 	public $theme = '';
    19 	public $theme = '';
    20 
    20 
    21 	/**
    21 	/**
    22 	 *
       
    23 	 * @param array $args
    22 	 * @param array $args
    24 	 */
    23 	 */
    25 	public function __construct($args = array()) {
    24 	public function __construct( $args = array() ) {
    26 		$defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
    25 		$defaults = array(
    27 		$args = wp_parse_args($args, $defaults);
    26 			'url'   => '',
       
    27 			'theme' => '',
       
    28 			'nonce' => '',
       
    29 			'title' => __( 'Update Theme' ),
       
    30 		);
       
    31 		$args     = wp_parse_args( $args, $defaults );
    28 
    32 
    29 		$this->theme = $args['theme'];
    33 		$this->theme = $args['theme'];
    30 
    34 
    31 		parent::__construct($args);
    35 		parent::__construct( $args );
    32 	}
    36 	}
    33 
    37 
    34 	/**
    38 	/**
    35 	 */
    39 	 */
    36 	public function after() {
    40 	public function after() {
    37 		$this->decrement_update_count( 'theme' );
    41 		$this->decrement_update_count( 'theme' );
    38 
    42 
    39 		$update_actions = array();
    43 		$update_actions = array();
    40 		if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
    44 		if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
    41 			$name       = $theme_info->display('Name');
    45 			$name       = $theme_info->display( 'Name' );
    42 			$stylesheet = $this->upgrader->result['destination_name'];
    46 			$stylesheet = $this->upgrader->result['destination_name'];
    43 			$template   = $theme_info->get_template();
    47 			$template   = $theme_info->get_template();
    44 
    48 
    45 			$activate_link = add_query_arg( array(
    49 			$activate_link = add_query_arg(
    46 				'action'     => 'activate',
    50 				array(
    47 				'template'   => urlencode( $template ),
    51 					'action'     => 'activate',
    48 				'stylesheet' => urlencode( $stylesheet ),
    52 					'template'   => urlencode( $template ),
    49 			), admin_url('themes.php') );
    53 					'stylesheet' => urlencode( $stylesheet ),
       
    54 				),
       
    55 				admin_url( 'themes.php' )
       
    56 			);
    50 			$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
    57 			$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
    51 
    58 
    52 			$customize_url = add_query_arg(
    59 			$customize_url = add_query_arg(
    53 				array(
    60 				array(
    54 					'theme' => urlencode( $stylesheet ),
    61 					'theme'  => urlencode( $stylesheet ),
    55 					'return' => urlencode( admin_url( 'themes.php' ) ),
    62 					'return' => urlencode( admin_url( 'themes.php' ) ),
    56 				),
    63 				),
    57 				admin_url( 'customize.php' )
    64 				admin_url( 'customize.php' )
    58 			);
    65 			);
    59 			if ( get_stylesheet() == $stylesheet ) {
    66 			if ( get_stylesheet() == $stylesheet ) {
    60 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    67 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    61 					$update_actions['preview']  = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
    68 					$update_actions['preview']  = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">';
       
    69 					$update_actions['preview'] .= '<span aria-hidden="true">' . __( 'Customize' ) . '</span>';
       
    70 					/* translators: %s: theme name */
       
    71 					$update_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
    62 				}
    72 				}
    63 			} elseif ( current_user_can( 'switch_themes' ) ) {
    73 			} elseif ( current_user_can( 'switch_themes' ) ) {
    64 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    74 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    65 					$update_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>';
    75 					$update_actions['preview']  = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">';
       
    76 					$update_actions['preview'] .= '<span aria-hidden="true">' . __( 'Live Preview' ) . '</span>';
       
    77 					/* translators: %s: theme name */
       
    78 					$update_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
    66 				}
    79 				}
    67 				$update_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>';
    80 				$update_actions['activate']  = '<a href="' . esc_url( $activate_link ) . '" class="activatelink">';
       
    81 				$update_actions['activate'] .= '<span aria-hidden="true">' . __( 'Activate' ) . '</span>';
       
    82 				/* translators: %s: theme name */
       
    83 				$update_actions['activate'] .= '<span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
    68 			}
    84 			}
    69 
    85 
    70 			if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
    86 			if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) {
    71 				unset( $update_actions['preview'], $update_actions['activate'] );
    87 				unset( $update_actions['preview'], $update_actions['activate'] );
       
    88 			}
    72 		}
    89 		}
    73 
    90 
    74 		$update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
    91 		$update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
    75 
    92 
    76 		/**
    93 		/**
    77 		 * Filters the list of action links available following a single theme update.
    94 		 * Filters the list of action links available following a single theme update.
    78 		 *
    95 		 *
    79 		 * @since 2.8.0
    96 		 * @since 2.8.0
    80 		 *
    97 		 *
    81 		 * @param array  $update_actions Array of theme action links.
    98 		 * @param string[] $update_actions Array of theme action links.
    82 		 * @param string $theme          Theme directory name.
    99 		 * @param string   $theme          Theme directory name.
    83 		 */
   100 		 */
    84 		$update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
   101 		$update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
    85 
   102 
    86 		if ( ! empty($update_actions) )
   103 		if ( ! empty( $update_actions ) ) {
    87 			$this->feedback(implode(' | ', (array)$update_actions));
   104 			$this->feedback( implode( ' | ', (array) $update_actions ) );
       
   105 		}
    88 	}
   106 	}
    89 }
   107 }