wp/wp-admin/includes/class-theme-upgrader-skin.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    14  * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
    14  * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
    15  *
    15  *
    16  * @see WP_Upgrader_Skin
    16  * @see WP_Upgrader_Skin
    17  */
    17  */
    18 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
    18 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
       
    19 
       
    20 	/**
       
    21 	 * Holds the theme slug in the Theme Directory.
       
    22 	 *
       
    23 	 * @since 2.8.0
       
    24 	 *
       
    25 	 * @var object
       
    26 	 */
    19 	public $theme = '';
    27 	public $theme = '';
    20 
    28 
    21 	/**
    29 	/**
    22 	 * @param array $args
    30 	 * Constructor.
       
    31 	 *
       
    32 	 * Sets up the theme upgrader skin.
       
    33 	 *
       
    34 	 * @since 2.8.0
       
    35 	 *
       
    36 	 * @param array $args Optional. The theme upgrader skin arguments to
       
    37 	 *                    override default options. Default empty array.
    23 	 */
    38 	 */
    24 	public function __construct( $args = array() ) {
    39 	public function __construct( $args = array() ) {
    25 		$defaults = array(
    40 		$defaults = array(
    26 			'url'   => '',
    41 			'url'   => '',
    27 			'theme' => '',
    42 			'theme' => '',
    34 
    49 
    35 		parent::__construct( $args );
    50 		parent::__construct( $args );
    36 	}
    51 	}
    37 
    52 
    38 	/**
    53 	/**
       
    54 	 * Action to perform following a single theme update.
       
    55 	 *
       
    56 	 * @since 2.8.0
    39 	 */
    57 	 */
    40 	public function after() {
    58 	public function after() {
    41 		$this->decrement_update_count( 'theme' );
    59 		$this->decrement_update_count( 'theme' );
    42 
    60 
    43 		$update_actions = array();
    61 		$update_actions = array();
    44 		if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
    62 		$theme_info     = $this->upgrader->theme_info();
       
    63 		if ( $theme_info ) {
    45 			$name       = $theme_info->display( 'Name' );
    64 			$name       = $theme_info->display( 'Name' );
    46 			$stylesheet = $this->upgrader->result['destination_name'];
    65 			$stylesheet = $this->upgrader->result['destination_name'];
    47 			$template   = $theme_info->get_template();
    66 			$template   = $theme_info->get_template();
    48 
    67 
    49 			$activate_link = add_query_arg(
    68 			$activate_link = add_query_arg(
    61 					'theme'  => urlencode( $stylesheet ),
    80 					'theme'  => urlencode( $stylesheet ),
    62 					'return' => urlencode( admin_url( 'themes.php' ) ),
    81 					'return' => urlencode( admin_url( 'themes.php' ) ),
    63 				),
    82 				),
    64 				admin_url( 'customize.php' )
    83 				admin_url( 'customize.php' )
    65 			);
    84 			);
    66 			if ( get_stylesheet() == $stylesheet ) {
    85 
       
    86 			if ( get_stylesheet() === $stylesheet ) {
    67 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    87 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    68 					$update_actions['preview']  = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">';
    88 					$update_actions['preview'] = sprintf(
    69 					$update_actions['preview'] .= '<span aria-hidden="true">' . __( 'Customize' ) . '</span>';
    89 						'<a href="%s" class="hide-if-no-customize load-customize">' .
    70 					/* translators: %s: theme name */
    90 						'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
    71 					$update_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
    91 						esc_url( $customize_url ),
       
    92 						__( 'Customize' ),
       
    93 						/* translators: %s: Theme name. */
       
    94 						sprintf( __( 'Customize &#8220;%s&#8221;' ), $name )
       
    95 					);
    72 				}
    96 				}
    73 			} elseif ( current_user_can( 'switch_themes' ) ) {
    97 			} elseif ( current_user_can( 'switch_themes' ) ) {
    74 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    98 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    75 					$update_actions['preview']  = '<a href="' . esc_url( $customize_url ) . '" class="hide-if-no-customize load-customize">';
    99 					$update_actions['preview'] = sprintf(
    76 					$update_actions['preview'] .= '<span aria-hidden="true">' . __( 'Live Preview' ) . '</span>';
   100 						'<a href="%s" class="hide-if-no-customize load-customize">' .
    77 					/* translators: %s: theme name */
   101 						'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
    78 					$update_actions['preview'] .= '<span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
   102 						esc_url( $customize_url ),
       
   103 						__( 'Live Preview' ),
       
   104 						/* translators: %s: Theme name. */
       
   105 						sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name )
       
   106 					);
    79 				}
   107 				}
    80 				$update_actions['activate']  = '<a href="' . esc_url( $activate_link ) . '" class="activatelink">';
   108 
    81 				$update_actions['activate'] .= '<span aria-hidden="true">' . __( 'Activate' ) . '</span>';
   109 				$update_actions['activate'] = sprintf(
    82 				/* translators: %s: theme name */
   110 					'<a href="%s" class="activatelink">' .
    83 				$update_actions['activate'] .= '<span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
   111 					'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
       
   112 					esc_url( $activate_link ),
       
   113 					__( 'Activate' ),
       
   114 					/* translators: %s: Theme name. */
       
   115 					sprintf( _x( 'Activate &#8220;%s&#8221;', 'theme' ), $name )
       
   116 				);
    84 			}
   117 			}
    85 
   118 
    86 			if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) {
   119 			if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) {
    87 				unset( $update_actions['preview'], $update_actions['activate'] );
   120 				unset( $update_actions['preview'], $update_actions['activate'] );
    88 			}
   121 			}
    89 		}
   122 		}
    90 
   123 
    91 		$update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
   124 		$update_actions['themes_page'] = sprintf(
       
   125 			'<a href="%s" target="_parent">%s</a>',
       
   126 			self_admin_url( 'themes.php' ),
       
   127 			__( 'Return to Themes page' )
       
   128 		);
    92 
   129 
    93 		/**
   130 		/**
    94 		 * Filters the list of action links available following a single theme update.
   131 		 * Filters the list of action links available following a single theme update.
    95 		 *
   132 		 *
    96 		 * @since 2.8.0
   133 		 * @since 2.8.0