Skip to:
Content
Pages
Categories
Search
Top
Bottom

WordPress Multisite: Update Dashboard Users Count to Reflect Individual Site


  • matthewdhuntley
    Participant

    @matthewdhuntley

    Hi bbPress Folks,

    I currently have a WordPress multisite installation with several individual sites. My WordPress version is 5.9.1 and the bbPress version is 2.6.9.

    On any given individual site’s WP Dashboard, in the “dashboard_right_now”/”At a Glance” section, the number of users shown is reflective of the total number of users on the entire multisite network, as opposed to the total number of User on the individual site.

    When it comes to multisite installations, can the output logic for this Users number be updated to reflect the number of Users for an individual site instead of the entire multisite network?

    Thanks very much,
    Matthew Huntley

Viewing 5 replies - 1 through 5 (of 5 total)

  • Robin W
    Moderator

    @robin-w

    this is WordPress related not bbpress, suggest you post to WordPress support


    matthewdhuntley
    Participant

    @matthewdhuntley

    Thanks for the feedback, @robin-w.

    I noticed the anchor element with the class “bbp-glance-users” (from bbpress/includes/admin/metaboxes.php), which appears in the dashboard_right_now/”At a Glance” widget, is exclusively created by the bbPress plugin through the ‘dashboard_glance_items’ WordPress hook. For a multisite, the Users count is coming from the entire network.

    I’ve traced the Users count number back to this function (from bbpress/includes/core/abstraction.php):
    function bbp_get_total_users() {
    $bbp_db = bbp_db();
    $count = $bbp_db->get_var( “SELECT COUNT(ID) as c FROM {$bbp_db->users} WHERE user_status = ‘0’” );

    // Filter & return
    return (int) apply_filters( ‘bbp_get_total_users’, (int) $count );
    }

    And I was wondering if this could be updated to check if the site is a multisite and then select the Users based on the individual site ID.

    Thanks,
    Matthew Huntley


    webcreations907
    Participant

    @webcreations907

    Seems you should be able to add a filter and return that instead which would override the function you listed above.


    webcreations907
    Participant

    @webcreations907

    I don’t have a multi site set up with bbpress, but try the below and see if that works for you. Would have to add to the code snippets plugin or your theme’s functions.php file

    
    
    if( !function_exists('mh_bbp_get_multi_site_total_users') ){
    	function mh_bbp_get_multi_site_total_users( $count ) {
    		if ( is_multisite() ) {
    			$args = array(
    				'blog_id'     => get_current_blog_id(),
    				'fields'      => 'ID'
    			);
    			$count = count( (array) get_users( $args ) );
    		}
    
    		return (int) $count;
    	}
    
    	add_filter( 'bbp_get_total_users' , 'mh_bbp_get_multi_site_total_users', 100 );
    }
    
    

    matthewdhuntley
    Participant

    @matthewdhuntley

    Thank you very much, @webcreations907. Your solution is working well so far. I appreciate the expedited response.

    Best regards,
    Matthew Huntley

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar