Skip to content

Commit 0733201

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 52d70f6 + 5830b7c commit 0733201

3 files changed

Lines changed: 77 additions & 10 deletions

File tree

src/js/_enqueues/admin/tags.js

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ jQuery( function($) {
5959
nextFocus = prevFocus;
6060
}
6161
}
62-
63-
tr.fadeOut('normal', function(){ tr.remove(); });
62+
tr.fadeOut('normal', function() {
63+
tr.remove();
64+
updateTableNavCount();
65+
});
6466

6567
/**
6668
* Removes the term from the parent box and the tag cloud.
@@ -73,7 +75,7 @@ jQuery( function($) {
7375
$('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove();
7476
nextFocus.trigger( 'focus' );
7577
message = wp.i18n.__( 'The selected tag has been deleted.' );
76-
78+
7779
} else if ( '-1' == r ) {
7880
message = wp.i18n.__( 'Sorry, you are not allowed to do that.' );
7981
$('#ajax-response').empty().append('<div class="notice notice-error"><p>' + message + '</p></div>');
@@ -103,6 +105,53 @@ jQuery( function($) {
103105
tr.find( ':input, a' ).prop( 'disabled', false ).removeAttr( 'tabindex' );
104106
}
105107

108+
/**
109+
* Updates the item count and table navigation after a tag is added or removed.
110+
*
111+
* Tags are added and removed client-side, but the item count, the `.tablenav`
112+
* regions, the search box, and the empty-state row are otherwise only
113+
* reconciled by PHP on a full page reload. This keeps them in sync.
114+
*
115+
* @param {string} [action] Pass 'add' when a tag was added. Any other value,
116+
* including none, is treated as a removal.
117+
*
118+
* @return {void}
119+
*/
120+
function updateTableNavCount( action ) {
121+
var $displayingNum = $( '.tablenav-pages .displaying-num' ),
122+
currentCount = parseInt( $displayingNum.first().text().replace( /[^0-9]/g, '' ), 10 ) || 0,
123+
itemCount = ( 'add' === action ) ? currentCount + 1 : Math.max( currentCount - 1, 0 ),
124+
formattedCount = itemCount.toLocaleString();
125+
126+
$displayingNum.text(
127+
wp.i18n.sprintf(
128+
/* translators: %s: Number of items. */
129+
wp.i18n._n( '%s item', '%s items', itemCount ),
130+
formattedCount
131+
)
132+
);
133+
134+
if ( itemCount < 1 ) {
135+
// No tags remain: show the empty-state row and hide the navigation.
136+
var $list = $( '#the-list' );
137+
138+
if ( ! $list.find( 'tr.no-items' ).length ) {
139+
var colspan = $list.closest( 'table' ).find( 'thead > tr' ).first().children( ':not(.hidden)' ).length;
140+
$list.append(
141+
'<tr class="no-items"><td class="colspanchange" colspan="' + colspan + '">' +
142+
wp.i18n.__( 'No tags found.' ) +
143+
'</td></tr>'
144+
);
145+
}
146+
$( '.tablenav > *' ).hide();
147+
$( 'p.search-box' ).hide();
148+
} else {
149+
$( '#the-list' ).find( 'tr.no-items' ).remove();
150+
$( '.tablenav > *' ).show();
151+
$( 'p.search-box' ).show();
152+
}
153+
}
154+
106155
/**
107156
* Adds a deletion confirmation when removing a tag.
108157
*
@@ -192,6 +241,8 @@ jQuery( function($) {
192241
}
193242

194243
$('input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):visible, textarea:visible', form).val('');
244+
245+
updateTableNavCount( 'add' );
195246
});
196247

197248
return false;

src/wp-admin/includes/class-wp-list-table.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,8 @@ protected function get_items_per_page( $option, $default_value = 20 ) {
10291029
*/
10301030
protected function pagination( $which ) {
10311031
if ( empty( $this->_pagination_args['total_items'] ) ) {
1032+
// translators: Number is a fixed value. This is default text when no items are found.
1033+
echo '<div class="tablenav-pages no-pages"><span class="displaying-num">' . __( '0 items' ) . '</span></div>';
10321034
return;
10331035
}
10341036

@@ -1685,12 +1687,16 @@ protected function display_tablenav( $which ) {
16851687
?>
16861688
<div class="tablenav <?php echo esc_attr( $which ); ?>">
16871689

1688-
<?php if ( $this->has_items() ) : ?>
1689-
<div class="alignleft actions bulkactions">
1690+
<?php
1691+
$visibility = ' hidden';
1692+
if ( $this->has_items() ) {
1693+
$visibility = '';
1694+
}
1695+
?>
1696+
<div class="alignleft actions bulkactions<?php echo $visibility; ?>">
16901697
<?php $this->bulk_actions( $which ); ?>
16911698
</div>
1692-
<?php
1693-
endif;
1699+
<?php
16941700
$this->extra_tablenav( $which );
16951701
$this->pagination( $which );
16961702
?>

src/wp-admin/options-privacy.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ static function ( $body_class ) {
5151
check_admin_referer( $action );
5252

5353
if ( 'set-privacy-page' === $action ) {
54-
$privacy_policy_page_id = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0;
54+
$previous_privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
55+
$privacy_policy_page_id = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0;
5556
update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id );
5657

57-
$privacy_page_updated_message = __( 'Privacy Policy page updated successfully.' );
58+
$privacy_page_message_type = 'success';
5859

5960
if ( $privacy_policy_page_id ) {
61+
$privacy_page_updated_message = __( 'Privacy Policy page updated successfully.' );
62+
6063
/*
6164
* Don't always link to the menu customizer:
6265
*
@@ -75,9 +78,16 @@ static function ( $body_class ) {
7578
esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) )
7679
);
7780
}
81+
} elseif ( $previous_privacy_policy_page_id ) {
82+
// A previously set Privacy Policy page was cleared.
83+
$privacy_page_updated_message = __( 'Privacy Policy page removed.' );
84+
} else {
85+
// No Privacy Policy page was set before, and none is set now.
86+
$privacy_page_updated_message = __( 'No Privacy Policy page is currently set.' );
87+
$privacy_page_message_type = 'info';
7888
}
7989

80-
add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'success' );
90+
add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, $privacy_page_message_type );
8191
} elseif ( 'create-privacy-page' === $action ) {
8292

8393
if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {

0 commit comments

Comments
 (0)