Make WordPress Core


Ignore:
Timestamp:
09/23/2019 05:34:20 PM (5 years ago)
Author:
johnjamesjacoby
Message:

Multisite/Sites: Add links to filter websites by status.

This commit brings the Network-Admin Sites list page up-to-speed with other similar list-table powered pages, by adding links to filter the results by Site Status.

Includes a single unit test for the newly introduced wp_count_sites() multisite function, named to match the wp_count_ function pattern from other list tables.

Fixes #37392. Props mnelson4, spacedmonkey, pbiron.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-blogs.php

    r45794 r46251  
    854854    update_posts_count();
    855855}
     856
     857/**
     858 * Count number of sites grouped by site status.
     859 *
     860 * @since 5.3.0
     861 *
     862 * @param int $network_id The network to get counts for.  Default is the current network id.
     863 * @return array Includes a grand total 'all' and an array of counts indexed by
     864 *                status strings: public, archived, mature, spam, deleted.
     865 */
     866function wp_count_sites( $network_id = null ) {
     867    if ( empty( $network_id ) ) {
     868        $network_id = get_current_network_id();
     869    }
     870
     871    $counts = array();
     872    $args   = array(
     873        'network_id'    => $network_id,
     874        'number'        => 1,
     875        'fields'        => 'ids',
     876        'no_found_rows' => false,
     877    );
     878
     879    $q             = new WP_Site_Query( $args );
     880    $counts['all'] = $q->found_sites;
     881
     882    $_args    = $args;
     883    $statuses = array( 'public', 'archived', 'mature', 'spam', 'deleted' );
     884
     885    foreach ( $statuses as $status ) {
     886        $_args            = $args;
     887        $_args[ $status ] = 1;
     888
     889        $q                 = new WP_Site_Query( $_args );
     890        $counts[ $status ] = $q->found_sites;
     891    }
     892
     893    return $counts;
     894}
Note: See TracChangeset for help on using the changeset viewer.