Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/25/2020 11:51:13 PM (5 years ago)
Author:
imath
Message:

Add the total items amount in Activity and Groups Admin List Tables

The "All" view of the corresponding administration screens is now including the total amount of items between parenthesis.

Props bhargavbhandari90, DJPaul, Hnla

Fixes #7526

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-list-table.php

    r12331 r12551  
    9696        // Sort order.
    9797        $order = 'DESC';
    98         if ( !empty( $_REQUEST['order'] ) ) {
     98        if ( ! empty( $_REQUEST['order'] ) ) {
    9999            $order = ( 'desc' == strtolower( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
    100100        }
     
    120120
    121121        // Are we doing a search?
    122         if ( !empty( $_REQUEST['s'] ) )
     122        if ( ! empty( $_REQUEST['s'] ) ) {
    123123            $search_terms = $_REQUEST['s'];
    124124
     125            // Set the view as a search request.
     126            $this->view = 'search';
     127        }
     128
    125129        // Check if user has clicked on a specific group (if so, fetch only that group).
    126         if ( !empty( $_REQUEST['gid'] ) )
     130        if ( ! empty( $_REQUEST['gid'] ) ) {
    127131            $include_id = (int) $_REQUEST['gid'];
    128132
    129         // Set the current view.
     133            // Set the view as a single activity.
     134            $this->view = 'single';
     135        }
     136
     137        // Use the status request to set the current view.
    130138        if ( isset( $_GET['group_status'] ) && in_array( $_GET['group_status'], array( 'public', 'private', 'hidden' ) ) ) {
    131139            $this->view = $_GET['group_status'];
     
    187195            'total_pages' => ceil( $groups_template->total_group_count / $per_page )
    188196        ) );
     197
     198        // Set the Total number of groups.
     199        if ( 'all' === $this->view ) {
     200            $this->group_counts['all'] = (int) $groups_template->total_group_count;
     201
     202        // Only perform a query if not on the main list view.
     203        } elseif ( 'single' !== $this->view ) {
     204            $count_groups = groups_get_groups(
     205                array(
     206                    'fields'      => 'ids',
     207                    'show_hidden' => true,
     208                )
     209            );
     210
     211            if ( $count_groups['total'] ) {
     212                $this->group_counts['all'] = (int) $count_groups['total'];
     213            }
     214        }
    189215    }
    190216
     
    332358
    333359        <ul class="subsubsub">
    334             <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' == $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
    335             <li class="public"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'public', $url_base ) ); ?>" class="<?php if ( 'public' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Public <span class="count">(%s)</span>', 'Public <span class="count">(%s)</span>', $this->group_counts['public'], 'buddypress' ), number_format_i18n( $this->group_counts['public'] ) ); ?></a> |</li>
    336             <li class="private"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'private', $url_base ) ); ?>" class="<?php if ( 'private' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', $this->group_counts['private'], 'buddypress' ), number_format_i18n( $this->group_counts['private'] ) ); ?></a> |</li>
    337             <li class="hidden"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'hidden', $url_base ) ); ?>" class="<?php if ( 'hidden' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', $this->group_counts['hidden'], 'buddypress' ), number_format_i18n( $this->group_counts['hidden'] ) ); ?></a></li>
     360            <li class="all">
     361                <a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' === $this->view ) echo 'current'; ?>">
     362                    <?php printf(
     363                        /* translators: %s is the placeholder for the count html tag `<span class="count"/>` */
     364                        esc_html__( 'All %s', 'buddypress' ),
     365                        sprintf(
     366                            '<span class="count">(%s)</span>',
     367                            number_format_i18n( $this->group_counts['all'] )
     368                        )
     369                    ); ?>
     370                </a> |
     371            </li>
     372            <li class="public">
     373                <a href="<?php echo esc_url( add_query_arg( 'group_status', 'public', $url_base ) ); ?>" class="<?php if ( 'public' === $this->view ) echo 'current'; ?>">
     374                    <?php printf(
     375                        /* translators: %s is the placeholder for the count html `<span class="count"/>` */
     376                        _n( 'Public %s', 'Public %s', $this->group_counts['public'], 'buddypress' ),
     377                        sprintf(
     378                            '<span class="count">(%s)</span>',
     379                            number_format_i18n( $this->group_counts['public'] )
     380                        )
     381                    ); ?>
     382                </a> |
     383            </li>
     384            <li class="private">
     385                <a href="<?php echo esc_url( add_query_arg( 'group_status', 'private', $url_base ) ); ?>" class="<?php if ( 'private' === $this->view ) echo 'current'; ?>">
     386                    <?php printf(
     387                        /* translators: %s is the placeholder for the count html `<span class="count"/>` */
     388                        _n( 'Private %s', 'Private %s', $this->group_counts['private'], 'buddypress' ),
     389                        sprintf(
     390                            '<span class="count">(%s)</span>',
     391                            number_format_i18n( $this->group_counts['private'] )
     392                        )
     393                    ); ?>
     394                </a> |
     395            </li>
     396            <li class="hidden">
     397                <a href="<?php echo esc_url( add_query_arg( 'group_status', 'hidden', $url_base ) ); ?>" class="<?php if ( 'hidden' === $this->view ) echo 'current'; ?>">
     398                    <?php printf(
     399                        /* translators: %s is the placeholder for the count html tag */
     400                        _n( 'Hidden %s', 'Hidden %s', $this->group_counts['hidden'], 'buddypress' ),
     401                        sprintf(
     402                            '<span class="count">(%s)</span>',
     403                            number_format_i18n( $this->group_counts['hidden'] )
     404                        )
     405                    ); ?>
     406                </a>
     407            </li>
    338408
    339409            <?php
Note: See TracChangeset for help on using the changeset viewer.