From 7757ad5e9446e1013db072feb7e1340a434013d2 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 18 Jun 2020 00:00:13 +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. Built from https://develop.svn.wordpress.org/trunk@48077 git-svn-id: http://core.svn.wordpress.org/trunk@47844 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-ms-themes-list-table.php | 25 +++++-- .../includes/class-wp-plugins-list-table.php | 27 ++++++-- wp-admin/themes.php | 68 +++++++++++++------ wp-includes/version.php | 2 +- 4 files changed, 90 insertions(+), 32 deletions(-) diff --git a/wp-admin/includes/class-wp-ms-themes-list-table.php b/wp-admin/includes/class-wp-ms-themes-list-table.php index 5b8c44ae92..8c039ec767 100644 --- a/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/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/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index d3233b451b..d5f61b6ad9 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/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/wp-admin/themes.php b/wp-admin/themes.php index 5d09cfb2ad..b6551fcbc9 100644 --- a/wp-admin/themes.php +++ b/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 { #> + + <# } #> + +

+ '; + + /** + * 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 ) { #> diff --git a/wp-includes/version.php b/wp-includes/version.php index f703059a36..9bf52b1e3b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-48076'; +$wp_version = '5.5-alpha-48077'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.