|
409 | 409 | * |
410 | 410 | * @since 4.2.0 |
411 | 411 | * @since 4.6.0 More accurately named `updatePluginSuccess`. |
| 412 | + * @since 5.5.0 Auto-update "time to next update" text cleared. |
412 | 413 | * |
413 | 414 | * @param {object} response Response from the server. |
414 | 415 | * @param {string} response.slug Slug of the plugin to be updated. |
|
431 | 432 | // Update the version number in the row. |
432 | 433 | newText = $pluginRow.find( '.plugin-version-author-uri' ).html().replace( response.oldVersion, response.newVersion ); |
433 | 434 | $pluginRow.find( '.plugin-version-author-uri' ).html( newText ); |
| 435 | + |
| 436 | + // Clear the "time to next auto-update" text. |
| 437 | + $pluginRow.find( '.auto-update-time' ).empty(); |
434 | 438 | } else if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) { |
435 | 439 | $updateMessage = $( '.plugin-card-' + response.slug ).find( '.update-now' ) |
436 | 440 | .removeClass( 'updating-message' ) |
|
969 | 973 | * Updates the UI appropriately after a successful theme update. |
970 | 974 | * |
971 | 975 | * @since 4.6.0 |
| 976 | + * @since 5.5.0 Auto-update "time to next update" text cleared. |
972 | 977 | * |
973 | 978 | * @param {object} response |
974 | 979 | * @param {string} response.slug Slug of the theme to be updated. |
|
1002 | 1007 | // Update the version number in the row. |
1003 | 1008 | newText = $theme.find( '.theme-version-author-uri' ).html().replace( response.oldVersion, response.newVersion ); |
1004 | 1009 | $theme.find( '.theme-version-author-uri' ).html( newText ); |
| 1010 | + |
| 1011 | + // Clear the "time to next auto-update" text. |
| 1012 | + $theme.find( '.auto-update-time' ).empty(); |
1005 | 1013 | } else { |
1006 | 1014 | $notice = $( '.theme-info .notice' ).add( $theme.find( '.update-message' ) ); |
1007 | 1015 |
|
1008 | 1016 | // Focus on Customize button after updating. |
1009 | 1017 | if ( isModalOpen ) { |
1010 | 1018 | $( '.load-customize:visible' ).focus(); |
| 1019 | + $( '.theme-info .theme-autoupdate' ).find( '.auto-update-time' ).empty(); |
1011 | 1020 | } else { |
1012 | 1021 | $theme.find( '.load-customize' ).focus(); |
1013 | 1022 | } |
|
2461 | 2470 | * @since 4.2.0 |
2462 | 2471 | */ |
2463 | 2472 | $( window ).on( 'beforeunload', wp.updates.beforeunload ); |
| 2473 | + |
| 2474 | + /** |
| 2475 | + * Click handler for enabling and disabling plugin and theme auto-updates. |
| 2476 | + * |
| 2477 | + * @since 5.5.0 |
| 2478 | + */ |
| 2479 | + $document.on( 'click', '.column-auto-updates a.toggle-auto-update, .theme-overlay a.toggle-auto-update', function( event ) { |
| 2480 | + var data, asset, type, $parent; |
| 2481 | + var $anchor = $( this ), |
| 2482 | + action = $anchor.attr( 'data-wp-action' ), |
| 2483 | + $label = $anchor.find( '.label' ); |
| 2484 | + |
| 2485 | + if ( 'themes' !== pagenow ) { |
| 2486 | + $parent = $anchor.closest( '.column-auto-updates' ); |
| 2487 | + } else { |
| 2488 | + $parent = $anchor.closest( '.theme-autoupdate' ); |
| 2489 | + } |
| 2490 | + |
| 2491 | + event.preventDefault(); |
| 2492 | + |
| 2493 | + // Prevent multiple simultaneous requests. |
| 2494 | + if ( $anchor.attr( 'data-doing-ajax' ) === 'yes' ) { |
| 2495 | + return; |
| 2496 | + } |
| 2497 | + |
| 2498 | + $anchor.attr( 'data-doing-ajax', 'yes' ); |
| 2499 | + |
| 2500 | + switch ( pagenow ) { |
| 2501 | + case 'plugins': |
| 2502 | + case 'plugins-network': |
| 2503 | + type = 'plugin'; |
| 2504 | + asset = $anchor.closest( 'tr' ).attr( 'data-plugin' ); |
| 2505 | + break; |
| 2506 | + case 'themes-network': |
| 2507 | + type = 'theme'; |
| 2508 | + asset = $anchor.closest( 'tr' ).attr( 'data-slug' ); |
| 2509 | + break; |
| 2510 | + case 'themes': |
| 2511 | + type = 'theme'; |
| 2512 | + asset = $anchor.attr( 'data-slug' ); |
| 2513 | + break; |
| 2514 | + } |
| 2515 | + |
| 2516 | + // Clear any previous errors. |
| 2517 | + $parent.find( '.notice.error' ).addClass( 'hidden' ); |
| 2518 | + |
| 2519 | + // Show loading status. |
| 2520 | + if ( 'enable' === action ) { |
| 2521 | + $label.text( wp.updates.l10n.autoUpdatesEnabling ); |
| 2522 | + } else { |
| 2523 | + $label.text( wp.updates.l10n.autoUpdatesDisabling ); |
| 2524 | + } |
| 2525 | + |
| 2526 | + $anchor.find( '.dashicons-update' ).removeClass( 'hidden' ); |
| 2527 | + |
| 2528 | + data = { |
| 2529 | + action: 'toggle-auto-updates', |
| 2530 | + _ajax_nonce: settings.ajax_nonce, |
| 2531 | + state: action, |
| 2532 | + type: type, |
| 2533 | + asset: asset |
| 2534 | + }; |
| 2535 | + |
| 2536 | + $.post( window.ajaxurl, data ) |
| 2537 | + .done( function( response ) { |
| 2538 | + var $enabled, $disabled, enabledNumber, disabledNumber, errorMessage; |
| 2539 | + var href = $anchor.attr( 'href' ); |
| 2540 | + |
| 2541 | + if ( ! response.success ) { |
| 2542 | + // if WP returns 0 for response (which can happen in a few cases), |
| 2543 | + // output the general error message since we won't have response.data.error. |
| 2544 | + if ( response.data && response.data.error ) { |
| 2545 | + errorMessage = response.data.error; |
| 2546 | + } else { |
| 2547 | + errorMessage = wp.updates.l10n.autoUpdatesError; |
| 2548 | + } |
| 2549 | + |
| 2550 | + $parent.find( '.notice.error' ).removeClass( 'hidden' ).find( 'p' ).text( errorMessage ); |
| 2551 | + wp.a11y.speak( errorMessage, 'polite' ); |
| 2552 | + return; |
| 2553 | + } |
| 2554 | + |
| 2555 | + // Update the counts in the enabled/disabled views if on a screen |
| 2556 | + // with a list table. |
| 2557 | + if ( 'themes' !== pagenow ) { |
| 2558 | + $enabled = $( '.auto-update-enabled span' ); |
| 2559 | + $disabled = $( '.auto-update-disabled span' ); |
| 2560 | + enabledNumber = parseInt( $enabled.text().replace( /[^\d]+/g, '' ), 10 ) || 0; |
| 2561 | + disabledNumber = parseInt( $disabled.text().replace( /[^\d]+/g, '' ), 10 ) || 0; |
| 2562 | + |
| 2563 | + switch ( action ) { |
| 2564 | + case 'enable': |
| 2565 | + ++enabledNumber; |
| 2566 | + --disabledNumber; |
| 2567 | + break; |
| 2568 | + case 'disable': |
| 2569 | + --enabledNumber; |
| 2570 | + ++disabledNumber; |
| 2571 | + break; |
| 2572 | + } |
| 2573 | + |
| 2574 | + enabledNumber = Math.max( 0, enabledNumber ); |
| 2575 | + disabledNumber = Math.max( 0, disabledNumber ); |
| 2576 | + |
| 2577 | + $enabled.text( '(' + enabledNumber + ')' ); |
| 2578 | + $disabled.text( '(' + disabledNumber + ')' ); |
| 2579 | + } |
| 2580 | + |
| 2581 | + if ( 'enable' === action ) { |
| 2582 | + href = href.replace( 'action=enable-auto-update', 'action=disable-auto-update' ); |
| 2583 | + $anchor.attr( { |
| 2584 | + 'data-wp-action': 'disable', |
| 2585 | + href: href |
| 2586 | + } ); |
| 2587 | + |
| 2588 | + $label.text( wp.updates.l10n.autoUpdatesDisable ); |
| 2589 | + $parent.find( '.auto-update-time' ).removeClass( 'hidden' ); |
| 2590 | + wp.a11y.speak( wp.updates.l10n.autoUpdatesEnabled, 'polite' ); |
| 2591 | + } else { |
| 2592 | + href = href.replace( 'action=disable-auto-update', 'action=enable-auto-update' ); |
| 2593 | + $anchor.attr( { |
| 2594 | + 'data-wp-action': 'enable', |
| 2595 | + href: href |
| 2596 | + } ); |
| 2597 | + |
| 2598 | + $label.text( wp.updates.l10n.autoUpdatesEnable ); |
| 2599 | + $parent.find( '.auto-update-time' ).addClass( 'hidden' ); |
| 2600 | + wp.a11y.speak( wp.updates.l10n.autoUpdatesDisabled, 'polite' ); |
| 2601 | + } |
| 2602 | + } ) |
| 2603 | + .fail( function() { |
| 2604 | + $parent.find( '.notice.error' ).removeClass( 'hidden' ).find( 'p' ).text( wp.updates.l10n.autoUpdatesError ); |
| 2605 | + wp.a11y.speak( wp.updates.l10n.autoUpdatesError, 'polite' ); |
| 2606 | + } ) |
| 2607 | + .always( function() { |
| 2608 | + $anchor.removeAttr( 'data-doing-ajax' ).find( '.dashicons-update' ).addClass( 'hidden' ); |
| 2609 | + } ); |
| 2610 | + } |
| 2611 | + ); |
2464 | 2612 | } ); |
2465 | 2613 | })( jQuery, window.wp, window._wpUpdatesSettings ); |
0 commit comments