Skip to:
Content

BuddyPress.org

Ticket #8012: 8012.2.diff

File 8012.2.diff, 3.3 KB (added by dcavins, 5 years ago)

Add an is_large_network check that works on single sites and networks.

  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index 09e5c3ee0..0dbbb7e6f 100644
    function bp_get_allowedtags() { 
    39003900function bp_strip_script_and_style_tags( $string ) {
    39013901        return preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
    39023902}
     3903
     3904/**
     3905 * Check if this is a large network or single site.
     3906 * This is a single-site-safe wrapper for the WordPress function that is only available in multisite.
     3907 *
     3908 * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
     3909 *
     3910 * @since 4.1.0
     3911 *
     3912 * @param string   $using      'sites or 'users'. Default is 'sites'.
     3913 * @param int|null $network_id ID of the network. Default is the current network.
     3914 * @return bool True if the network meets the criteria for large. False otherwise.
     3915 */
     3916function bp_is_large_network( $using = 'sites', $network_id = null ) {
     3917        // Fall back to the WordPress native function if available.
     3918        if ( is_multisite() ) {
     3919                return wp_is_large_network( $using, $network_id );
     3920        }
     3921
     3922        if ( 'users' === $using ) {
     3923                $count = bp_core_get_total_member_count();
     3924                /**
     3925                 * Filters whether the BuddyPress site is considered large.
     3926                 *
     3927                 * @since 4.1.0
     3928                 *
     3929                 * @param bool   $is_large_network Whether the network has more than 10000 users or sites.
     3930                 * @param string $component        The component to count. Accepts 'users' or 'sites'.
     3931                 * @param int    $count            The count of items for the component.
     3932                 */
     3933                return apply_filters( 'bp_is_large_network', $count > 10000, 'users', $count );
     3934        }
     3935
     3936        // Else, we're counting sites, and non-multisite means there's only one.
     3937        /** This filter is documented in bp-core/bp-core-functions.php */
     3938        return apply_filters( 'bp_is_large_network', false, 'sites', 1 );
     3939}
  • src/bp-friends/bp-friends-functions.php

    diff --git src/bp-friends/bp-friends-functions.php src/bp-friends/bp-friends-functions.php
    index 2b446e28d..822b6596b 100644
    function bp_friends_prime_mentions_results() { 
    781781        }
    782782
    783783        // Bail out if the site has a ton of users.
    784         if ( is_multisite() && wp_is_large_network( 'users' ) ) {
     784        if ( bp_is_large_network( 'users' ) ) {
    785785                return;
    786786        }
    787787
  • src/bp-groups/bp-groups-admin.php

    diff --git src/bp-groups/bp-groups-admin.php src/bp-groups/bp-groups-admin.php
    index 353b6ead2..51278892c 100644
    function bp_groups_admin_edit_metabox_settings( $item ) { 
    861861 * @param BP_Groups_Group $item The BP_Groups_Group object for the current group.
    862862 */
    863863function bp_groups_admin_edit_metabox_add_new_members( $item ) {
    864         if ( wp_is_large_network( 'users' ) ) {
     864        if ( bp_is_large_network( 'users' ) ) {
    865865                $class  = '';
    866866                $notice = __( 'Enter a comma-separated list of user logins.', 'buddypress' );
    867867        } else {
    function bp_groups_admin_get_usernames_from_ids( $user_ids = array() ) { 
    12521252function bp_groups_admin_autocomplete_handler() {
    12531253
    12541254        // Bail if user user shouldn't be here, or is a large network.
    1255         if ( ! bp_current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) {
     1255        if ( ! bp_current_user_can( 'bp_moderate' ) || bp_is_large_network( 'users' ) ) {
    12561256                wp_die( -1 );
    12571257        }
    12581258