Make WordPress Core

Ticket #50870: 50870.4.diff

File 50870.4.diff, 8.4 KB (added by pbiron, 5 years ago)
  • src/js/_enqueues/wp/updates.js

    From c302126dd72676c4212f0996a67fa975e1ca34f1 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Tue, 10 Nov 2020 13:06:25 -0700
    Subject: [PATCH] Adjust the counts of plugins and themes for which
     auto-updates are enabled/disabled (in their respective list table views) when
     a plugin or theme is deleted.
    
    ---
     src/js/_enqueues/wp/updates.js                | 90 ++++++++++++++-----
     .../class-wp-ms-themes-list-table.php         |  8 +-
     2 files changed, 71 insertions(+), 27 deletions(-)
    
    diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js
    index f4d3472f84..e7454c0eab 100644
    a b  
    88/* global pagenow */
    99
    1010/**
    11  * @param {jQuery}  $                                   jQuery object.
    12  * @param {object}  wp                                  WP object.
    13  * @param {object}  settings                            WP Updates settings.
    14  * @param {string}  settings.ajax_nonce                 Ajax nonce.
    15  * @param {object=} settings.plugins                    Base names of plugins in their different states.
    16  * @param {Array}   settings.plugins.all                Base names of all plugins.
    17  * @param {Array}   settings.plugins.active             Base names of active plugins.
    18  * @param {Array}   settings.plugins.inactive           Base names of inactive plugins.
    19  * @param {Array}   settings.plugins.upgrade            Base names of plugins with updates available.
    20  * @param {Array}   settings.plugins.recently_activated Base names of recently activated plugins.
    21  * @param {object=} settings.themes                     Plugin/theme status information or null.
    22  * @param {number}  settings.themes.all                 Amount of all themes.
    23  * @param {number}  settings.themes.upgrade             Amount of themes with updates available.
    24  * @param {number}  settings.themes.disabled            Amount of disabled themes.
    25  * @param {object=} settings.totals                     Combined information for available update counts.
    26  * @param {number}  settings.totals.count               Holds the amount of available updates.
     11 * @param {jQuery}  $                                        jQuery object.
     12 * @param {object}  wp                                       WP object.
     13 * @param {object}  settings                                 WP Updates settings.
     14 * @param {string}  settings.ajax_nonce                      Ajax nonce.
     15 * @param {object=} settings.plugins                         Base names of plugins in their different states.
     16 * @param {Array}   settings.plugins.all                     Base names of all plugins.
     17 * @param {Array}   settings.plugins.active                  Base names of active plugins.
     18 * @param {Array}   settings.plugins.inactive                Base names of inactive plugins.
     19 * @param {Array}   settings.plugins.upgrade                 Base names of plugins with updates available.
     20 * @param {Array}   settings.plugins.recently_activated      Base names of recently activated plugins.
     21 * @param {Array}   settings.plugins['auto-update-enabled']  Base names of plugins set to auto-update.
     22 * @param {Array}   settings.plugins['auto-update-disabled'] Base names of plugins set to not auto-update.
     23 * @param {object=} settings.themes                          Slugs of themes in their different states.
     24 * @param {Array}   settings.themes.all                      Slugs of all themes.
     25 * @param {Array}   settings.themes.upgrade                  Slugs of themes with updates available.
     26 * @param {Arrat}   settings.themes.disabled                 Slugs of disabled themes.
     27 * @param {Array}   settings.themes['auto-update-enabled']   Slugs of themes set to auto-update.
     28 * @param {Array}   settings.themes['auto-update-disabled']  Slugs of themes set to not auto-update.
     29 * @param {object=} settings.totals                          Combined information for available update counts.
     30 * @param {number}  settings.totals.count                    Holds the amount of available updates.
    2731 */
    2832(function( $, wp, settings ) {
    2933        var $document = $( document ),
     
    10071011                                }
    10081012                        }
    10091013
     1014                        if ( -1 !== _.indexOf( plugins['auto-update-enabled'], response.plugin ) ) {
     1015                                plugins['auto-update-enabled'] = _.without( plugins['auto-update-enabled'], response.plugin );
     1016                                if ( plugins['auto-update-enabled'].length ) {
     1017                                        $views.find( '.auto-update-enabled .count' ).text( '(' + plugins['auto-update-enabled'].length + ')' );
     1018                                } else {
     1019                                        $views.find( '.auto-update-enabled' ).remove();
     1020                                }
     1021                        }
     1022
     1023                        if ( -1 !== _.indexOf( plugins['auto-update-disabled'], response.plugin ) ) {
     1024                                plugins['auto-update-disabled'] = _.without( plugins['auto-update-disabled'], response.plugin );
     1025                                if ( plugins['auto-update-disabled'].length ) {
     1026                                        $views.find( '.auto-update-disabled .count' ).text( '(' + plugins['auto-update-disabled'].length + ')' );
     1027                                } else {
     1028                                        $views.find( '.auto-update-disabled' ).remove();
     1029                                }
     1030                        }
     1031
    10101032                        plugins.all = _.without( plugins.all, response.plugin );
    10111033
    10121034                        if ( plugins.all.length ) {
     
    15051527                        $themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() {
    15061528                                var $views     = $( '.subsubsub' ),
    15071529                                        $themeRow  = $( this ),
    1508                                         totals     = settings.themes,
     1530                                        themes     = settings.themes,
    15091531                                        deletedRow = wp.template( 'item-deleted-row' );
    15101532
    15111533                                if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) {
     
    15211543                                $themeRow.remove();
    15221544
    15231545                                // Remove theme from update count.
    1524                                 if ( $themeRow.hasClass( 'update' ) ) {
    1525                                         totals.upgrade--;
     1546                                if ( -1 !== _.indexOf( themes.upgrade, response.slug ) ) {
     1547                                        themes.upgrade = _.without( themes.upgrade, response.slug );
    15261548                                        wp.updates.decrementCount( 'theme' );
    15271549                                }
    15281550
    15291551                                // Remove from views.
    1530                                 if ( $themeRow.hasClass( 'inactive' ) ) {
    1531                                         totals.disabled--;
    1532                                         if ( totals.disabled ) {
    1533                                                 $views.find( '.disabled .count' ).text( '(' + totals.disabled + ')' );
     1552                                if ( -1 !== _.indexOf( themes.disabled, response.slug ) ) {
     1553                                        themes.disabled = _.without( themes.disabled, response.slug );
     1554                                        if ( themes.disabled.length ) {
     1555                                                $views.find( '.disabled .count' ).text( '(' + themes.disabled.length + ')' );                                           
    15341556                                        } else {
    15351557                                                $views.find( '.disabled' ).remove();
    15361558                                        }
    15371559                                }
    15381560
     1561                                if ( -1 !== _.indexOf( themes['auto-update-enabled'], response.slug ) ) {
     1562                                        themes['auto-update-enabled'] = _.without( themes['auto-update-enabled'], response.slug );
     1563                                        if ( themes['auto-update-enabled'].length ) {
     1564                                                $views.find( '.auto-update-enabled .count' ).text( '(' + themes['auto-update-enabled'].length + ')' );
     1565                                        } else {
     1566                                                $views.find( '.auto-update-enabled' ).remove();
     1567                                        }
     1568                                }
     1569       
     1570                                if ( -1 !== _.indexOf( themes['auto-update-disabled'], response.slug ) ) {
     1571                                        themes['auto-update-disabled'] = _.without( themes['auto-update-disabled'], response.slug );
     1572                                        if ( themes['auto-update-disabled'].length ) {
     1573                                                $views.find( '.auto-update-disabled .count' ).text( '(' + themes['auto-update-disabled'].length + ')' );
     1574                                        } else {
     1575                                                $views.find( '.auto-update-disabled' ).remove();
     1576                                        }
     1577                                }
     1578
     1579                                themes.all = _.without( themes.all, response.slug );
     1580
    15391581                                // There is always at least one theme available.
    1540                                 $views.find( '.all .count' ).text( '(' + --totals.all + ')' );
     1582                                $views.find( '.all .count' ).text( '(' + themes.all.length + ')' );
    15411583                        } );
    15421584                }
    15431585
  • src/wp-admin/includes/class-wp-ms-themes-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-ms-themes-list-table.php b/src/wp-admin/includes/class-wp-ms-themes-list-table.php
    index a22fcb80bb..2091603cf0 100644
    a b class WP_MS_Themes_List_Table extends WP_List_Table { 
    206206                        $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
    207207                }
    208208
    209                 $totals = array();
     209                $totals    = array();
     210                $js_themes = array();
    210211                foreach ( $themes as $type => $list ) {
    211                         $totals[ $type ] = count( $list );
     212                        $totals[ $type ]    = count( $list );
     213                        $js_themes[ $type ] = array_keys( $list );
    212214                }
    213215
    214216                if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    225227                        'updates',
    226228                        '_wpUpdatesItemCounts',
    227229                        array(
    228                                 'themes' => $totals,
     230                                'themes' => $js_themes,
    229231                                'totals' => wp_get_update_data(),
    230232                        )
    231233                );