From 8ca76ddd0a97d3186fa3dab159c2bff1e5819728 Mon Sep 17 00:00:00 2001
From: Andrew Ozz
Date: Wed, 17 Jun 2020 23:58:15 +0000
Subject: [PATCH] Plugins and Themes Auto-Updates: allow overriding of the HTML
for the auto-update setting link. This will let plugins show better/specific
information when they are overriding the auto-update settings, for example
"Updates are managed by ... plugin".
Introduces: `theme_auto_update_setting_html`, `plugin_auto_update_setting_html`, and `theme_auto_update_setting_template` filters.
Props audrasjb, pbiron, azaozz.
Fixes #50280.
git-svn-id: https://develop.svn.wordpress.org/trunk@48077 602fd350-edb4-49c9-b593-d223f7449a82
---
.../class-wp-ms-themes-list-table.php | 25 +++++--
.../includes/class-wp-plugins-list-table.php | 27 ++++++--
src/wp-admin/themes.php | 68 +++++++++++++------
3 files changed, 89 insertions(+), 31 deletions(-)
diff --git a/src/wp-admin/includes/class-wp-ms-themes-list-table.php b/src/wp-admin/includes/class-wp-ms-themes-list-table.php
index 5b8c44ae92..8c039ec767 100644
--- a/src/wp-admin/includes/class-wp-ms-themes-list-table.php
+++ b/src/wp-admin/includes/class-wp-ms-themes-list-table.php
@@ -742,24 +742,39 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$url = add_query_arg( $query_args, 'themes.php' );
- printf(
+ $html[] = sprintf(
'',
wp_nonce_url( $url, 'updates' ),
$action
);
- echo '';
- echo '' . $text . '';
- echo '';
+ $html[] = '';
+ $html[] = '' . $text . '';
+ $html[] = '';
$available_updates = get_site_transient( 'update_themes' );
if ( isset( $available_updates->response[ $stylesheet ] ) ) {
- printf(
+ $html[] = sprintf(
'%s
',
$time_class,
wp_get_auto_update_message()
);
}
+
+ $html = implode( '', $html );
+
+ /**
+ * Filters the HTML of the auto-updates setting for each theme in the Themes list table.
+ *
+ * @since 5.5.0
+ *
+ * @param string $html The HTML for theme’s auto-update setting including toggle auto-update action link
+ * and time to next update.
+ * @param string $stylesheet Directory name of the theme.
+ * @param WP_Theme $theme WP_Theme object.
+ */
+ echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
+
echo '';
}
diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php
index d3233b451b..d5f61b6ad9 100644
--- a/src/wp-admin/includes/class-wp-plugins-list-table.php
+++ b/src/wp-admin/includes/class-wp-plugins-list-table.php
@@ -1041,6 +1041,8 @@ class WP_Plugins_List_Table extends WP_List_Table {
echo "";
+ $html = array();
+
if ( in_array( $plugin_file, $auto_updates, true ) ) {
$text = __( 'Disable auto-updates' );
$action = 'disable';
@@ -1060,26 +1062,41 @@ class WP_Plugins_List_Table extends WP_List_Table {
$url = add_query_arg( $query_args, 'plugins.php' );
- printf(
+ $html[] = sprintf(
'',
wp_nonce_url( $url, 'updates' ),
$action
);
- echo '';
- echo '' . $text . '';
- echo '';
+ $html[] = '';
+ $html[] = '' . $text . '';
+ $html[] = '';
$available_updates = get_site_transient( 'update_plugins' );
if ( isset( $available_updates->response[ $plugin_file ] ) ) {
- printf(
+ $html[] = sprintf(
' %s ',
$time_class,
wp_get_auto_update_message()
);
}
+ $html = implode( '', $html );
+
+ /**
+ * Filters the HTML of the auto-updates setting for each plugin in the Plugins list table.
+ *
+ * @since 5.5.0
+ *
+ * @param string $html The HTML of the plugin's auto-update column content,
+ * including toggle auto-update action links and time to next update.
+ * @param string $plugin_file Path to the plugin file relative to the plugins directory.
+ * @param array $plugin_data An array of plugin data.
+ */
+ echo apply_filters( 'plugin_auto_update_setting_html', $html, $plugin_file, $plugin_data );
+
+
echo '';
echo ' | ';
diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php
index 5d09cfb2ad..b6551fcbc9 100644
--- a/src/wp-admin/themes.php
+++ b/src/wp-admin/themes.php
@@ -549,6 +549,52 @@ if ( ! is_multisite() && $broken_themes ) {
+ <# if ( data.autoupdate ) { #>
+
+
+ ' . __( 'Disable auto-updates' ) . '
+
+ <# } else { #>
+
+
+ ' . __( 'Enable auto-updates' ) . '
+
+ <# } #>
+ <# if ( data.hasUpdate ) { #>
+ <# if ( data.autoupdate ) { #>
+
+ <# } else { #>
+
+ <# } #>
+
' . wp_get_auto_update_message() . '
+ <# } #>
+
+
+ ';
+
+ /**
+ * Filters the JavaScript template used in Backbone to display the auto-update setting for a theme (in the overlay).
+ *
+ * See {@see wp_prepare_themes_for_js()} for the properties of the `data` object.
+ *
+ * @since 5.5.0
+ *
+ * @param string $template The template for displaying the auto-update setting link.
+ */
+ return apply_filters( 'theme_auto_update_setting_template', $template );
+}
+
/*
* The tmpl-theme template is synchronized with PHP above!
*/
@@ -648,27 +694,7 @@ if ( ! is_multisite() && $broken_themes ) {
<# if ( data.actions.autoupdate ) { #>
-
- <# if ( data.autoupdate ) { #>
-
-
-
-
- <# } else { #>
-
-
-
-
- <# } #>
- <# if ( data.hasUpdate ) { #>
- <# if ( data.autoupdate) { #>
-
- <# } else { #>
-
- <# } #>
- <# } #>
-
-
+
<# } #>
<# if ( data.hasUpdate ) { #>