Skip to content

Commit 0f897fc

Browse files
committed
Increment and decremet the term count instead of fetching count
Since we would not having bulk action for adding and for deleting it reloads the page, it is ideal to use current count and update the count by incrementing and decrementing the same
1 parent 5919329 commit 0f897fc

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

src/js/_enqueues/admin/tags.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ jQuery( function($) {
5959
*/
6060
var termCountWrapper = $( '#posts-filter .displaying-num' );
6161
if ( termCountWrapper.length ) {
62-
termCountWrapper.each(function () {
63-
$( this ).text( $( this ).text().replace( /^\d+/, function ( match ) {
64-
return parseInt( match, 10 ) - 1;
65-
} ) );
62+
termCountWrapper.each( function () {
63+
$( this ).text(
64+
$( this )
65+
.text()
66+
.replace( /^\d+/, function ( match ) {
67+
return parseInt( match, 10 ) - 1;
68+
} )
69+
);
6670
} );
6771
}
6872
} else if ( '-1' == r ) {
@@ -170,15 +174,19 @@ jQuery( function($) {
170174
}
171175

172176
termCountWrapper = $( '#posts-filter .displaying-num' );
173-
termCount = res.responses[ 2 ].supplemental.count ? res.responses[ 2 ].supplemental.count : null;
174177

175178
/**
176-
* Updates the term count if we get count and the term count wrapper exists.
179+
* Updates the term count on term add.
177180
*/
178-
if ( termCountWrapper.length && null !== termCount ) {
179-
termCountWrapper.each(function () {
180-
console.log( $( this ).text().match( /^\d+/ ) );
181-
$( this ).text( $( this ).text().replace( /^\d+/, termCount ) );
181+
if ( termCountWrapper.length ) {
182+
termCountWrapper.each( function () {
183+
$( this ).text(
184+
$( this )
185+
.text()
186+
.replace( /^\d+/, function ( match ) {
187+
return parseInt( match, 10 ) + 1;
188+
} )
189+
);
182190
} );
183191
}
184192

src/wp-admin/includes/ajax-actions.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,14 +1152,6 @@ function wp_ajax_add_tag() {
11521152
$message = $messages['_item'][1];
11531153
}
11541154

1155-
// Get the new term count after the new term has been added.
1156-
$term_count = wp_count_terms(
1157-
array(
1158-
'taxonomy' => $taxonomy,
1159-
'hide_empty' => false,
1160-
)
1161-
);
1162-
11631155
$x->add(
11641156
array(
11651157
'what' => 'taxonomy',
@@ -1180,16 +1172,6 @@ function wp_ajax_add_tag() {
11801172
)
11811173
);
11821174

1183-
$x->add(
1184-
array(
1185-
'what' => 'term-count',
1186-
'supplemental' => array(
1187-
'taxonomy' => $taxonomy,
1188-
'count' => $term_count,
1189-
)
1190-
)
1191-
);
1192-
11931175
$x->send();
11941176
}
11951177

0 commit comments

Comments
 (0)