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
This commit is contained in:
Andrew Ozz 2020-06-17 23:58:15 +00:00
parent dbceb01b83
commit 8ca76ddd0a
3 changed files with 89 additions and 31 deletions

View File

@ -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(
'<a href="%s" class="toggle-auto-update" data-wp-action="%s">',
wp_nonce_url( $url, 'updates' ),
$action
);
echo '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
echo '<span class="label">' . $text . '</span>';
echo '</a>';
$html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
$html[] = '<span class="label">' . $text . '</span>';
$html[] = '</a>';
$available_updates = get_site_transient( 'update_themes' );
if ( isset( $available_updates->response[ $stylesheet ] ) ) {
printf(
$html[] = sprintf(
'<div class="auto-update-time%s">%s</div>',
$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 themes 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 '<div class="auto-updates-error inline notice error hidden"><p></p></div>';
}

View File

@ -1041,6 +1041,8 @@ class WP_Plugins_List_Table extends WP_List_Table {
echo "<td class='column-auto-updates{$extra_classes}'>";
$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(
'<a href="%s" class="toggle-auto-update" data-wp-action="%s">',
wp_nonce_url( $url, 'updates' ),
$action
);
echo '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
echo '<span class="label">' . $text . '</span>';
echo '</a>';
$html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
$html[] = '<span class="label">' . $text . '</span>';
$html[] = '</a>';
$available_updates = get_site_transient( 'update_plugins' );
if ( isset( $available_updates->response[ $plugin_file ] ) ) {
printf(
$html[] = sprintf(
'<div class="auto-update-time%s">%s</div>',
$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 '<div class="inline notice error hidden"><p></p></div>';
echo '</td>';

View File

@ -549,6 +549,52 @@ if ( ! is_multisite() && $broken_themes ) {
</div><!-- .wrap -->
<?php
/**
* Returns the template for displaying the auto-update setting for a theme.
*
* @since 5.5.0
*
* @return string Template
*/
function wp_theme_auto_update_setting_template() {
$template = '
<p class="theme-autoupdate">
<# if ( data.autoupdate ) { #>
<a href="{{{ data.actions.autoupdate }}}" class="toggle-auto-update" data-slug="{{ data.id }}" data-wp-action="disable">
<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>
<span class="label">' . __( 'Disable auto-updates' ) . '</span>
</a>
<# } else { #>
<a href="{{{ data.actions.autoupdate }}}" class="toggle-auto-update" data-slug="{{ data.id }}" data-wp-action="enable">
<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>
<span class="label">' . __( 'Enable auto-updates' ) . '</span>
</a>
<# } #>
<# if ( data.hasUpdate ) { #>
<# if ( data.autoupdate ) { #>
<span class="auto-update-time">
<# } else { #>
<span class="auto-update-time hidden">
<# } #>
<br />' . wp_get_auto_update_message() . '</span>
<# } #>
<span class="auto-updates-error hidden"><p></p></span>
</p>
';
/**
* 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 ) {
</p>
<# if ( data.actions.autoupdate ) { #>
<p class="theme-autoupdate">
<# if ( data.autoupdate ) { #>
<a href="{{{ data.actions.autoupdate }}}" class="toggle-auto-update" data-slug="{{ data.id }}" data-wp-action="disable">
<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>
<span class="label"><?php _e( 'Disable auto-updates' ); ?></span>
</a>
<# } else { #>
<a href="{{{ data.actions.autoupdate }}}" class="toggle-auto-update" data-slug="{{ data.id }}" data-wp-action="enable">
<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>
<span class="label"><?php _e( 'Enable auto-updates' ); ?></span>
</a>
<# } #>
<# if ( data.hasUpdate ) { #>
<# if ( data.autoupdate) { #>
<span class="auto-update-time"><br /><?php echo wp_get_auto_update_message(); ?></span>
<# } else { #>
<span class="auto-update-time hidden"><br /><?php echo wp_get_auto_update_message(); ?></span>
<# } #>
<# } #>
<span class="auto-updates-error hidden"><p></p></span>
</p>
<?php echo wp_theme_auto_update_setting_template(); ?>
<# } #>
<# if ( data.hasUpdate ) { #>