wp/wp-admin/includes/class-theme-upgrader.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    90 		/* translators: 1: Theme name, 2: Theme version. */
    90 		/* translators: 1: Theme name, 2: Theme version. */
    91 		$this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' );
    91 		$this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' );
    92 		/* translators: %s: Theme name. */
    92 		/* translators: %s: Theme name. */
    93 		$this->strings['parent_theme_not_found'] = sprintf( __( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' );
    93 		$this->strings['parent_theme_not_found'] = sprintf( __( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' );
    94 		/* translators: %s: Theme error. */
    94 		/* translators: %s: Theme error. */
    95 		$this->strings['current_theme_has_errors'] = __( 'The current theme has the following error: "%s".' );
    95 		$this->strings['current_theme_has_errors'] = __( 'The active theme has the following error: "%s".' );
    96 
    96 
    97 		if ( ! empty( $this->skin->overwrite ) ) {
    97 		if ( ! empty( $this->skin->overwrite ) ) {
    98 			if ( 'update-theme' === $this->skin->overwrite ) {
    98 			if ( 'update-theme' === $this->skin->overwrite ) {
    99 				$this->strings['installing_package'] = __( 'Updating the theme&#8230;' );
    99 				$this->strings['installing_package'] = __( 'Updating the theme&#8230;' );
   100 				$this->strings['process_failed']     = __( 'Theme update failed.' );
   100 				$this->strings['process_failed']     = __( 'Theme update failed.' );
   446 						'theme' => $theme,
   446 						'theme' => $theme,
   447 					),
   447 					),
   448 				)
   448 				)
   449 			);
   449 			);
   450 
   450 
   451 			$results[ $theme ] = $this->result;
   451 			$results[ $theme ] = $result;
   452 
   452 
   453 			// Prevent credentials auth screen from displaying multiple times.
   453 			// Prevent credentials auth screen from displaying multiple times.
   454 			if ( false === $result ) {
   454 			if ( false === $result ) {
   455 				break;
   455 				break;
   456 			}
   456 			}
   558 			return new WP_Error(
   558 			return new WP_Error(
   559 				'incompatible_archive_theme_no_name',
   559 				'incompatible_archive_theme_no_name',
   560 				$this->strings['incompatible_archive'],
   560 				$this->strings['incompatible_archive'],
   561 				sprintf(
   561 				sprintf(
   562 					/* translators: %s: style.css */
   562 					/* translators: %s: style.css */
   563 					__( 'The %s stylesheet doesn&#8217;t contain a valid theme header.' ),
   563 					__( 'The %s stylesheet does not contain a valid theme header.' ),
   564 					'<code>style.css</code>'
   564 					'<code>style.css</code>'
   565 				)
   565 				)
   566 			);
   566 			);
   567 		}
   567 		}
   568 
   568 
   569 		// If it's not a child theme, it must have at least an index.php to be legit.
   569 		/*
   570 		if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) {
   570 		 * Parent themes must contain an index file:
       
   571 		 * - classic themes require /index.php
       
   572 		 * - block themes require /templates/index.html or block-templates/index.html (deprecated 5.9.0).
       
   573 		 */
       
   574 		if (
       
   575 			empty( $info['Template'] ) &&
       
   576 			! file_exists( $working_directory . 'index.php' ) &&
       
   577 			! file_exists( $working_directory . 'templates/index.html' ) &&
       
   578 			! file_exists( $working_directory . 'block-templates/index.html' )
       
   579 		) {
   571 			return new WP_Error(
   580 			return new WP_Error(
   572 				'incompatible_archive_theme_no_index',
   581 				'incompatible_archive_theme_no_index',
   573 				$this->strings['incompatible_archive'],
   582 				$this->strings['incompatible_archive'],
   574 				sprintf(
   583 				sprintf(
   575 					/* translators: %s: index.php */
   584 					/* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: Template, 5: style.css */
   576 					__( 'The theme is missing the %s file.' ),
   585 					__( 'Template is missing. Standalone themes need to have a %1$s or %2$s template file. <a href="%3$s">Child themes</a> need to have a %4$s header in the %5$s stylesheet.' ),
   577 					'<code>index.php</code>'
   586 					'<code>templates/index.html</code>',
       
   587 					'<code>index.php</code>',
       
   588 					__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
       
   589 					'<code>Template</code>',
       
   590 					'<code>style.css</code>'
   578 				)
   591 				)
   579 			);
   592 			);
   580 		}
   593 		}
   581 
   594 
   582 		$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
   595 		$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
   607 
   620 
   608 		return $source;
   621 		return $source;
   609 	}
   622 	}
   610 
   623 
   611 	/**
   624 	/**
   612 	 * Turn on maintenance mode before attempting to upgrade the current theme.
   625 	 * Turn on maintenance mode before attempting to upgrade the active theme.
   613 	 *
   626 	 *
   614 	 * Hooked to the {@see 'upgrader_pre_install'} filter by Theme_Upgrader::upgrade() and
   627 	 * Hooked to the {@see 'upgrader_pre_install'} filter by Theme_Upgrader::upgrade() and
   615 	 * Theme_Upgrader::bulk_upgrade().
   628 	 * Theme_Upgrader::bulk_upgrade().
   616 	 *
   629 	 *
   617 	 * @since 2.8.0
   630 	 * @since 2.8.0
   618 	 *
   631 	 *
   619 	 * @param bool|WP_Error $return Upgrade offer return.
   632 	 * @param bool|WP_Error $response The installation response before the installation has started.
   620 	 * @param array         $theme  Theme arguments.
   633 	 * @param array         $theme    Theme arguments.
   621 	 * @return bool|WP_Error The passed in $return param or WP_Error.
   634 	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
   622 	 */
   635 	 */
   623 	public function current_before( $return, $theme ) {
   636 	public function current_before( $response, $theme ) {
   624 		if ( is_wp_error( $return ) ) {
   637 		if ( is_wp_error( $response ) ) {
   625 			return $return;
   638 			return $response;
   626 		}
   639 		}
   627 
   640 
   628 		$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
   641 		$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
   629 
   642 
   630 		// Only run if current theme
   643 		// Only run if active theme.
   631 		if ( get_stylesheet() !== $theme ) {
   644 		if ( get_stylesheet() !== $theme ) {
   632 			return $return;
   645 			return $response;
   633 		}
   646 		}
   634 
   647 
   635 		// Change to maintenance mode. Bulk edit handles this separately.
   648 		// Change to maintenance mode. Bulk edit handles this separately.
   636 		if ( ! $this->bulk ) {
   649 		if ( ! $this->bulk ) {
   637 			$this->maintenance_mode( true );
   650 			$this->maintenance_mode( true );
   638 		}
   651 		}
   639 
   652 
   640 		return $return;
   653 		return $response;
   641 	}
   654 	}
   642 
   655 
   643 	/**
   656 	/**
   644 	 * Turn off maintenance mode after upgrading the current theme.
   657 	 * Turn off maintenance mode after upgrading the active theme.
   645 	 *
   658 	 *
   646 	 * Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::upgrade()
   659 	 * Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::upgrade()
   647 	 * and Theme_Upgrader::bulk_upgrade().
   660 	 * and Theme_Upgrader::bulk_upgrade().
   648 	 *
   661 	 *
   649 	 * @since 2.8.0
   662 	 * @since 2.8.0
   650 	 *
   663 	 *
   651 	 * @param bool|WP_Error $return Upgrade offer return.
   664 	 * @param bool|WP_Error $response The installation response after the installation has finished.
   652 	 * @param array         $theme  Theme arguments.
   665 	 * @param array         $theme    Theme arguments.
   653 	 * @return bool|WP_Error The passed in $return param or WP_Error.
   666 	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
   654 	 */
   667 	 */
   655 	public function current_after( $return, $theme ) {
   668 	public function current_after( $response, $theme ) {
   656 		if ( is_wp_error( $return ) ) {
   669 		if ( is_wp_error( $response ) ) {
   657 			return $return;
   670 			return $response;
   658 		}
   671 		}
   659 
   672 
   660 		$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
   673 		$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
   661 
   674 
   662 		// Only run if current theme.
   675 		// Only run if active theme.
   663 		if ( get_stylesheet() !== $theme ) {
   676 		if ( get_stylesheet() !== $theme ) {
   664 			return $return;
   677 			return $response;
   665 		}
   678 		}
   666 
   679 
   667 		// Ensure stylesheet name hasn't changed after the upgrade:
   680 		// Ensure stylesheet name hasn't changed after the upgrade:
   668 		if ( get_stylesheet() === $theme && $theme !== $this->result['destination_name'] ) {
   681 		if ( get_stylesheet() === $theme && $theme !== $this->result['destination_name'] ) {
   669 			wp_clean_themes_cache();
   682 			wp_clean_themes_cache();
   673 
   686 
   674 		// Time to remove maintenance mode. Bulk edit handles this separately.
   687 		// Time to remove maintenance mode. Bulk edit handles this separately.
   675 		if ( ! $this->bulk ) {
   688 		if ( ! $this->bulk ) {
   676 			$this->maintenance_mode( false );
   689 			$this->maintenance_mode( false );
   677 		}
   690 		}
   678 		return $return;
   691 		return $response;
   679 	}
   692 	}
   680 
   693 
   681 	/**
   694 	/**
   682 	 * Delete the old theme during an upgrade.
   695 	 * Delete the old theme during an upgrade.
   683 	 *
   696 	 *