From 7ea44b5add71c6df2a7ae0a7ed9eacd28bb114a6 Mon Sep 17 00:00:00 2001
From: Sergey Biryukov
Date: Tue, 28 Jul 2020 00:08:00 +0000
Subject: [PATCH] Themes: Display a message in theme grid and Theme Details
modal if a theme update requires a higher version of PHP or WordPress.
This applies to the Themes screen and the Customizer theme browser.
Props afragen, SergeyBiryukov.
See #48491.
git-svn-id: https://develop.svn.wordpress.org/trunk@48652 602fd350-edb4-49c9-b593-d223f7449a82
---
src/wp-admin/includes/theme.php | 107 ++++++++--
src/wp-admin/themes.php | 196 ++++++++++++++++--
.../class-wp-customize-theme-control.php | 87 ++++++--
3 files changed, 339 insertions(+), 51 deletions(-)
diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php
index 5738893a9e..2fd6efe513 100644
--- a/src/wp-admin/includes/theme.php
+++ b/src/wp-admin/includes/theme.php
@@ -684,27 +684,34 @@ function wp_prepare_themes_for_js( $themes = null ) {
);
}
+ $update_requires_wp = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null;
+ $update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null;
+
$auto_update = in_array( $slug, $auto_updates, true );
$auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update';
$prepared_themes[ $slug ] = array(
- 'id' => $slug,
- 'name' => $theme->display( 'Name' ),
- 'screenshot' => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
- 'description' => $theme->display( 'Description' ),
- 'author' => $theme->display( 'Author', false, true ),
- 'authorAndUri' => $theme->display( 'Author' ),
- 'tags' => $theme->display( 'Tags' ),
- 'version' => $theme->get( 'Version' ),
- 'compatibleWP' => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ),
- 'compatiblePHP' => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ),
- 'parent' => $parent,
- 'active' => $slug === $current_theme,
- 'hasUpdate' => isset( $updates[ $slug ] ),
- 'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
- 'update' => get_theme_update_available( $theme ),
- 'autoupdate' => $auto_update,
- 'actions' => array(
+ 'id' => $slug,
+ 'name' => $theme->display( 'Name' ),
+ 'screenshot' => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
+ 'description' => $theme->display( 'Description' ),
+ 'author' => $theme->display( 'Author', false, true ),
+ 'authorAndUri' => $theme->display( 'Author' ),
+ 'tags' => $theme->display( 'Tags' ),
+ 'version' => $theme->get( 'Version' ),
+ 'compatibleWP' => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ),
+ 'compatiblePHP' => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ),
+ 'updateResponse' => array(
+ 'compatibleWP' => is_wp_version_compatible( $update_requires_wp ),
+ 'compatiblePHP' => is_php_version_compatible( $update_requires_php ),
+ ),
+ 'parent' => $parent,
+ 'active' => $slug === $current_theme,
+ 'hasUpdate' => isset( $updates[ $slug ] ),
+ 'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
+ 'update' => get_theme_update_available( $theme ),
+ 'autoupdate' => $auto_update,
+ 'actions' => array(
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
'customize' => $customize_action,
'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
@@ -793,10 +800,68 @@ function customize_themes_print_templates() {
<# } #>
<# if ( data.hasUpdate ) { #>
-
-
- {{{ data.update }}}
-
+ <# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #>
+
+
+ {{{ data.update }}}
+
+ <# } else { #>
+
+
+
+ <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
+ Please update WordPress, and then learn more about updating PHP.' ),
+ self_admin_url( 'update-core.php' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ } elseif ( current_user_can( 'update_core' ) ) {
+ printf(
+ /* translators: %s: URL to WordPress Updates screen. */
+ ' ' . __( 'Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ } elseif ( current_user_can( 'update_php' ) ) {
+ printf(
+ /* translators: %s: URL to Update PHP page. */
+ ' ' . __( 'Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } else if ( ! data.updateResponse.compatibleWP ) { #>
+ Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ }
+ ?>
+ <# } else if ( ! data.updateResponse.compatiblePHP ) { #>
+ Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } #>
+
+
+ <# } #>
<# } #>
<# if ( data.parent ) { #>
diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php
index 03d917a070..280ba6be1e 100644
--- a/src/wp-admin/themes.php
+++ b/src/wp-admin/themes.php
@@ -389,13 +389,64 @@ foreach ( $themes as $theme ) :
-
-
-
Update now' ); ?>
+
+
+
+ Update now' ); ?>
+
+
+
+
-
+
+ Please update WordPress, and then learn more about updating PHP.' ),
+ self_admin_url( 'update-core.php' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ } elseif ( current_user_can( 'update_core' ) ) {
+ printf(
+ /* translators: %s: URL to WordPress Updates screen. */
+ ' ' . __( 'Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ } elseif ( current_user_can( 'update_php' ) ) {
+ printf(
+ /* translators: %s: URL to Update PHP page. */
+ ' ' . __( 'Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ } elseif ( ! $theme['updateResponse']['compatibleWP'] ) {
+ _e( 'There is a new version available, but it doesn’t work with your version of WordPress.' );
+ if ( current_user_can( 'update_core' ) ) {
+ printf(
+ /* translators: %s: URL to WordPress Updates screen. */
+ ' ' . __( 'Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ }
+ } elseif ( ! $theme['updateResponse']['compatiblePHP'] ) {
+ _e( 'There is a new version available, but it doesn’t work with your version of PHP.' );
+ if ( current_user_can( 'update_php' ) ) {
+ printf(
+ /* translators: %s: URL to Update PHP page. */
+ ' ' . __( 'Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ }
+ ?>
+
-
<# if ( data.hasUpdate ) { #>
- <# if ( data.hasPackage ) { #>
-
+ <# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #>
+
+ <# if ( data.hasPackage ) { #>
+ Update now' ); ?>
+ <# } else { #>
+
+ <# } #>
+
<# } else { #>
-
+
+ <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
+ Please update WordPress, and then learn more about updating PHP.' ),
+ self_admin_url( 'update-core.php' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ } elseif ( current_user_can( 'update_core' ) ) {
+ printf(
+ /* translators: %s: URL to WordPress Updates screen. */
+ ' ' . __( 'Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ } elseif ( current_user_can( 'update_php' ) ) {
+ printf(
+ /* translators: %s: URL to Update PHP page. */
+ ' ' . __( 'Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } else if ( ! data.updateResponse.compatibleWP ) { #>
+ Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ }
+ ?>
+ <# } else if ( ! data.updateResponse.compatiblePHP ) { #>
+ Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } #>
+
<# } #>
<# } #>
@@ -853,15 +961,73 @@ function wp_theme_auto_update_setting_template() {
<# } #>
- <# if ( data.actions.autoupdate ) { #>
-
+ <# if ( data.hasUpdate ) { #>
+ <# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #>
+
+
+ {{{ data.update }}}
+
+ <# } else { #>
+
+
+
+ <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
+ Please update WordPress, and then learn more about updating PHP.' ),
+ self_admin_url( 'update-core.php' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ } elseif ( current_user_can( 'update_core' ) ) {
+ printf(
+ /* translators: %s: URL to WordPress Updates screen. */
+ ' ' . __( 'Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ } elseif ( current_user_can( 'update_php' ) ) {
+ printf(
+ /* translators: %s: URL to Update PHP page. */
+ ' ' . __( 'Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } else if ( ! data.updateResponse.compatibleWP ) { #>
+ Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ }
+ ?>
+ <# } else if ( ! data.updateResponse.compatiblePHP ) { #>
+ Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } #>
+
+
+ <# } #>
<# } #>
- <# if ( data.hasUpdate ) { #>
-
-
- {{{ data.update }}}
-
+ <# if ( data.actions.autoupdate ) { #>
+
<# } #>
{{{ data.description }}}
diff --git a/src/wp-includes/customize/class-wp-customize-theme-control.php b/src/wp-includes/customize/class-wp-customize-theme-control.php
index 64dc33a3e4..03d9649ff8 100644
--- a/src/wp-includes/customize/class-wp-customize-theme-control.php
+++ b/src/wp-includes/customize/class-wp-customize-theme-control.php
@@ -90,21 +90,78 @@ class WP_Customize_Theme_Control extends WP_Customize_Control {
<# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #>
-
-
- ' . __( 'Update now' ) . ''
- );
- }
- ?>
-
-
+ <# if ( data.theme.updateResponse.compatibleWP && data.theme.updateResponse.compatiblePHP ) { #>
+
+
+ ' . __( 'Update now' ) . ''
+ );
+ }
+ ?>
+
+
+ <# } else { #>
+
+
+ <# if ( ! data.theme.updateResponse.compatibleWP && ! data.theme.updateResponse.compatiblePHP ) { #>
+ Please update WordPress, and then learn more about updating PHP.' ),
+ self_admin_url( 'update-core.php' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ } elseif ( current_user_can( 'update_core' ) ) {
+ printf(
+ /* translators: %s: URL to WordPress Updates screen. */
+ ' ' . __( 'Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ } elseif ( current_user_can( 'update_php' ) ) {
+ printf(
+ /* translators: %s: URL to Update PHP page. */
+ ' ' . __( 'Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } else if ( ! data.theme.updateResponse.compatibleWP ) { #>
+ Please update WordPress.' ),
+ self_admin_url( 'update-core.php' )
+ );
+ }
+ ?>
+ <# } else if ( ! data.theme.updateResponse.compatiblePHP ) { #>
+ Learn more about updating PHP.' ),
+ esc_url( wp_get_update_php_url() )
+ );
+ wp_update_php_annotation( '
', '' );
+ }
+ ?>
+ <# } #>
+
+
+ <# } #>
<# } #>
<# if ( ! data.theme.compatibleWP || ! data.theme.compatiblePHP ) { #>