Changeset 13103 for trunk/src/bp-groups/classes/class-bp-groups-group.php
- Timestamp:
- 09/09/2021 02:01:40 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/classes/class-bp-groups-group.php
r13086 r13103 1724 1724 * 1725 1725 * @since 1.6.0 1726 * 1727 * @return int Group count. 1728 */ 1729 public static function get_total_group_count() { 1726 * @since 10.0.0 Added the `$skip_cache` parameter. 1727 * 1728 * @global BuddyPress $bp The one true BuddyPress instance. 1729 * @global wpdb $wpdb WordPress database object. 1730 * 1731 * @param bool $skip_cache Optional. Skip getting count from cache. 1732 * Defaults to false. 1733 * @return int 1734 */ 1735 public static function get_total_group_count( $skip_cache = false ) { 1730 1736 global $wpdb; 1731 1737 1732 $hidden_sql = ''; 1733 if ( !bp_current_user_can( 'bp_moderate' ) ) 1734 $hidden_sql = "WHERE status != 'hidden'"; 1735 1736 $bp = buddypress(); 1737 1738 return $wpdb->get_var( "SELECT COUNT(id) FROM {$bp->groups->table_name} {$hidden_sql}" ); 1738 $cache_key = 'bp_total_group_count'; 1739 $count = wp_cache_get( $cache_key, 'bp' ); 1740 1741 if ( false === $count || true === $skip_cache ) { 1742 $hidden_sql = ''; 1743 if ( ! bp_current_user_can( 'bp_moderate' ) ) { 1744 $hidden_sql = "WHERE status != 'hidden'"; 1745 } 1746 1747 $bp = buddypress(); 1748 $count = $wpdb->get_var( "SELECT COUNT(id) FROM {$bp->groups->table_name} {$hidden_sql}" ); 1749 1750 wp_cache_set( $cache_key, (int) $count, 'bp' ); 1751 } 1752 1753 /** 1754 * Filters the total group count. 1755 * 1756 * @since 10.0.0 1757 * 1758 * @param int $count Total group count. 1759 */ 1760 return (int) apply_filters( 'bp_groups_total_group_count', (int) $count ); 1739 1761 } 1740 1762 … … 1743 1765 * 1744 1766 * @since 1.6.0 1745 * 1746 * @param int $group_id Group ID. 1767 * @since 10.0.0 Updated to use the `groups_get_group_members`. 1768 * 1769 * @param int $group_id Group ID. 1770 * @param bool $skip_cache Optional. Skip getting count from cache. Defaults to false. 1747 1771 * @return int Count of confirmed members for the group. 1748 1772 */ 1749 public static function get_total_member_count( $group_id ) { 1750 global $wpdb; 1751 1752 $bp = buddypress(); 1753 1754 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) ); 1773 public static function get_total_member_count( $group_id, $skip_cache = false ) { 1774 $cache_key = 'total_member_count'; 1775 $count = groups_get_groupmeta( $group_id, $cache_key ); 1776 1777 if ( false === $count || true === $skip_cache ) { 1778 $members = groups_get_group_members( 1779 array( 1780 'group_id' => $group_id, 1781 'exclude_banned' => true, 1782 'exclude_admins_mods' => false, 1783 'type' => 'active', 1784 ) 1785 ); 1786 1787 $count = $members['count'] ? $members['count'] : 0; 1788 1789 groups_update_groupmeta( $group_id, $cache_key, (int) $count ); 1790 } 1791 1792 /** 1793 * Filters the total member count for a group. 1794 * 1795 * @since 10.0.0 1796 * 1797 * @param int $count Total member count for group. 1798 * @param int $group_id The ID of the group. 1799 */ 1800 return (int) apply_filters( 'bp_groups_total_member_count', (int) $count, (int) $group_id ); 1755 1801 } 1756 1802
Note: See TracChangeset
for help on using the changeset viewer.