Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Avoid duplicate Updating... dialog #32

Merged
merged 1 commit into from Mar 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 10 additions & 15 deletions wp-autoupdates.php
Expand Up @@ -84,18 +84,24 @@ function wp_autoupdates_enqueues( $hook ) {
$aria_label_disable = sprintf( _x( 'Disable automatic update for %s', 'theme' ), '{{ data.name }}' );

// Put the enable/disable link below the author and before the update box.
$autoupdate_text = '<p class="theme-autoupdate"> <# if ( data.autoupdate ) { #>';
$autoupdate_text = '<p class="theme-autoupdate">';
$autoupdate_text .= '<# if ( data.autoupdate ) { #>';
$autoupdate_text .= '<span class="theme-autoupdate-disabled">';
$autoupdate_text .= '<a href="{{{ data.actions.autoupdate }}}" aria-label="' . $aria_label_disable . '"><span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Disable automatic updates' ) . '</a>';
$autoupdate_text .= '</span>';
$autoupdate_text .= '<# } else { #>';
$autoupdate_text .= '<span class="theme-autoupdate-enabled">';
$autoupdate_text .= '<a href="{{{ data.actions.autoupdate }}}" aria-label="' . $aria_label_enable . '"><span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Enable automatic updates' ) . '</a>';
$autoupdate_text .= '</span>';
$autoupdate_text .= '<# } #> </p>';
$autoupdate_text .= '<# } #>';

$script .= ' const theme_template_single = jQuery( "#tmpl-theme-single" );
$update_message = wp_autoupdates_get_update_message();
$autoupdate_text .= '<# if ( data.hasUpdate && data.autoupdate ) { #>';
$autoupdate_text .= '<br /><span class="theme-autoupdate-enabled">' . $update_message . '</span>';
$autoupdate_text .= '<# } #>';
$autoupdate_text .= '</p>';

$script .= ' const theme_template_single = jQuery( "#tmpl-theme-single" );
// Pull template into new html element, manipulate, then put back.
// Props https://stackoverflow.com/a/42248980.
function insert_into_template(positioning_text, added_text, insert_before) {
Expand All @@ -111,21 +117,10 @@ function insert_into_template(positioning_text, added_text, insert_before) {
}
}

const position_beginning_of_update_box = "<# if \\\\( data.hasUpdate \\\\) { #>";
const position_beginning_of_update_box = \'<p class="theme-description">\';
insert_into_template(position_beginning_of_update_box, "' . str_replace('"', '\"', $autoupdate_text) . '", true);
';

// Put the time until next update within the data.hasUpdate block.
$update_message = wp_autoupdates_get_update_message();
$autoupdate_time_text = '<# if ( data.autoupdate ) { #>';
$autoupdate_time_text .= '<p class="theme-autoupdate-enabled">' . $update_message . '</p>';
$autoupdate_time_text .= '<# } #>';

$script .= '
const position_data_update = "{{{ data.update }}}";
insert_into_template(position_data_update, "' . str_replace('"', '\"', $autoupdate_time_text) . '", false);
';

$script .= '});';
wp_add_inline_script( 'jquery', $script );
}
Expand Down