Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request audrasjb#32 from bookdude13/reorder_theme_update_text
Browse files Browse the repository at this point in the history
Avoid duplicate Updating... dialog
  • Loading branch information
audrasjb committed Mar 30, 2020
2 parents 742eade + 4269a19 commit de94a1b
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions wp-autoupdates.php
Original file line number Diff line number Diff line change
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

0 comments on commit de94a1b

Please sign in to comment.