Skip to content

Commit 0c78005

Browse files
committed
Plugins: Add a new plugins_list_status_text filter in get_views() to allow custom filtering.
This changeset does the following: - Custom statuses added via `plugins_list` now appear as tabs, to filter the related plugins - The tab label is customizable via the new `plugins_list_status_text` hook Follow-up to [56068]. Props juliobox, audrasjb, hellofromTonya, khokansardar, sajjad67, davidbaumwald, sukhendu2002, SirLouen, mindctrl, shailu25, huzaifaalmesbah, westonruter. See #60495. git-svn-id: https://develop.svn.wordpress.org/trunk@61695 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 70e25cf commit 0c78005

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ public function __construct( $args = array() ) {
4646
)
4747
);
4848

49-
$allowed_statuses = array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled' );
50-
5149
$status = 'all';
52-
if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], $allowed_statuses, true ) ) {
53-
$status = $_REQUEST['plugin_status'];
50+
if ( isset( $_REQUEST['plugin_status'] ) ) {
51+
$status = sanitize_key( $_REQUEST['plugin_status'] );
5452
}
5553

5654
if ( isset( $_REQUEST['s'] ) ) {
@@ -584,6 +582,25 @@ protected function get_views() {
584582
$count
585583
);
586584
break;
585+
default:
586+
/**
587+
* Filters the status text of default switch case in the plugins list table.
588+
*
589+
* @since 7.0.0
590+
*
591+
* @param string $text Plugins list status text. Default empty string.
592+
* @param int $count Count of the number of plugins.
593+
* @param string $type The status slug being filtered.
594+
*/
595+
$text = apply_filters( 'plugins_list_status_text', '', $count, $type );
596+
if ( empty( $text ) || ! is_string( $text ) ) {
597+
$text = $type;
598+
}
599+
$text = esc_html( $text ) . ' ' . sprintf(
600+
'<span class="count">(%s)</span>',
601+
number_format_i18n( $count )
602+
);
603+
break;
587604
}
588605

589606
if ( 'search' !== $type ) {

0 commit comments

Comments
 (0)