wp/wp-admin/includes/class-theme-installer-skin.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    22 	public $overwrite;
    22 	public $overwrite;
    23 
    23 
    24 	private $is_downgrading = false;
    24 	private $is_downgrading = false;
    25 
    25 
    26 	/**
    26 	/**
       
    27 	 * Constructor.
       
    28 	 *
       
    29 	 * Sets up the theme installer skin.
       
    30 	 *
       
    31 	 * @since 2.8.0
       
    32 	 *
    27 	 * @param array $args
    33 	 * @param array $args
    28 	 */
    34 	 */
    29 	public function __construct( $args = array() ) {
    35 	public function __construct( $args = array() ) {
    30 		$defaults = array(
    36 		$defaults = array(
    31 			'type'      => 'web',
    37 			'type'      => 'web',
    44 
    50 
    45 		parent::__construct( $args );
    51 		parent::__construct( $args );
    46 	}
    52 	}
    47 
    53 
    48 	/**
    54 	/**
    49 	 * Action to perform before installing a theme.
    55 	 * Performs an action before installing a theme.
    50 	 *
    56 	 *
    51 	 * @since 2.8.0
    57 	 * @since 2.8.0
    52 	 */
    58 	 */
    53 	public function before() {
    59 	public function before() {
    54 		if ( ! empty( $this->api ) ) {
    60 		if ( ! empty( $this->api ) ) {
    64 	 * Hides the `process_failed` error when updating a theme by uploading a zip file.
    70 	 * Hides the `process_failed` error when updating a theme by uploading a zip file.
    65 	 *
    71 	 *
    66 	 * @since 5.5.0
    72 	 * @since 5.5.0
    67 	 *
    73 	 *
    68 	 * @param WP_Error $wp_error WP_Error object.
    74 	 * @param WP_Error $wp_error WP_Error object.
    69 	 * @return bool
    75 	 * @return bool True if the error should be hidden, false otherwise.
    70 	 */
    76 	 */
    71 	public function hide_process_failed( $wp_error ) {
    77 	public function hide_process_failed( $wp_error ) {
    72 		if (
    78 		if (
    73 			'upload' === $this->type &&
    79 			'upload' === $this->type &&
    74 			'' === $this->overwrite &&
    80 			'' === $this->overwrite &&
    79 
    85 
    80 		return false;
    86 		return false;
    81 	}
    87 	}
    82 
    88 
    83 	/**
    89 	/**
    84 	 * Action to perform following a single theme install.
    90 	 * Performs an action following a single theme install.
    85 	 *
    91 	 *
    86 	 * @since 2.8.0
    92 	 * @since 2.8.0
    87 	 */
    93 	 */
    88 	public function after() {
    94 	public function after() {
    89 		if ( $this->do_overwrite() ) {
    95 		if ( $this->do_overwrite() ) {
   127 			$install_actions['preview'] = sprintf(
   133 			$install_actions['preview'] = sprintf(
   128 				'<a href="%s" class="hide-if-no-customize load-customize">' .
   134 				'<a href="%s" class="hide-if-no-customize load-customize">' .
   129 				'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
   135 				'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
   130 				esc_url( $customize_url ),
   136 				esc_url( $customize_url ),
   131 				__( 'Live Preview' ),
   137 				__( 'Live Preview' ),
   132 				/* translators: %s: Theme name. */
   138 				/* translators: Hidden accessibility text. %s: Theme name. */
   133 				sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name )
   139 				sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name )
   134 			);
   140 			);
   135 		}
   141 		}
   136 
   142 
   137 		$install_actions['activate'] = sprintf(
   143 		$install_actions['activate'] = sprintf(
   138 			'<a href="%s" class="activatelink">' .
   144 			'<a href="%s" class="activatelink">' .
   139 			'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
   145 			'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
   140 			esc_url( $activate_link ),
   146 			esc_url( $activate_link ),
   141 			__( 'Activate' ),
   147 			_x( 'Activate', 'theme' ),
   142 			/* translators: %s: Theme name. */
   148 			/* translators: Hidden accessibility text. %s: Theme name. */
   143 			sprintf( _x( 'Activate &#8220;%s&#8221;', 'theme' ), $name )
   149 			sprintf( _x( 'Activate &#8220;%s&#8221;', 'theme' ), $name )
   144 		);
   150 		);
   145 
   151 
   146 		if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) {
   152 		if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) {
   147 			$install_actions['network_enable'] = sprintf(
   153 			$install_actions['network_enable'] = sprintf(
   186 			$this->feedback( implode( ' | ', (array) $install_actions ) );
   192 			$this->feedback( implode( ' | ', (array) $install_actions ) );
   187 		}
   193 		}
   188 	}
   194 	}
   189 
   195 
   190 	/**
   196 	/**
   191 	 * Check if the theme can be overwritten and output the HTML for overwriting a theme on upload.
   197 	 * Checks if the theme can be overwritten and outputs the HTML for overwriting a theme on upload.
   192 	 *
   198 	 *
   193 	 * @since 5.5.0
   199 	 * @since 5.5.0
   194 	 *
   200 	 *
   195 	 * @return bool Whether the theme can be overwritten and HTML was outputted.
   201 	 * @return bool Whether the theme can be overwritten and HTML was outputted.
   196 	 */
   202 	 */
   299 
   305 
   300 		if ( ! is_php_version_compatible( $requires_php ) ) {
   306 		if ( ! is_php_version_compatible( $requires_php ) ) {
   301 			$error = sprintf(
   307 			$error = sprintf(
   302 				/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
   308 				/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
   303 				__( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
   309 				__( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
   304 				phpversion(),
   310 				PHP_VERSION,
   305 				$requires_php
   311 				$requires_php
   306 			);
   312 			);
   307 
   313 
   308 			$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
   314 			$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
   309 			$can_update       = false;
   315 			$can_update       = false;
   326 		if ( $can_update ) {
   332 		if ( $can_update ) {
   327 			if ( $this->is_downgrading ) {
   333 			if ( $this->is_downgrading ) {
   328 				$warning = sprintf(
   334 				$warning = sprintf(
   329 					/* translators: %s: Documentation URL. */
   335 					/* translators: %s: Documentation URL. */
   330 					__( 'You are uploading an older version of the active theme. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ),
   336 					__( 'You are uploading an older version of the active theme. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ),
   331 					__( 'https://wordpress.org/support/article/wordpress-backups/' )
   337 					__( 'https://developer.wordpress.org/advanced-administration/security/backup/' )
   332 				);
   338 				);
   333 			} else {
   339 			} else {
   334 				$warning = sprintf(
   340 				$warning = sprintf(
   335 					/* translators: %s: Documentation URL. */
   341 					/* translators: %s: Documentation URL. */
   336 					__( 'You are updating a theme. Be sure to <a href="%s">back up your database and files</a> first.' ),
   342 					__( 'You are updating a theme. Be sure to <a href="%s">back up your database and files</a> first.' ),
   337 					__( 'https://wordpress.org/support/article/wordpress-backups/' )
   343 					__( 'https://developer.wordpress.org/advanced-administration/security/backup/' )
   338 				);
   344 				);
   339 			}
   345 			}
   340 
   346 
   341 			echo '<p class="update-from-upload-notice">' . $warning . '</p>';
   347 			echo '<p class="update-from-upload-notice">' . $warning . '</p>';
   342 
   348