• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How does XenForo count registered members?

Grover

Well-known member
#1
I am investigating switching my platform from vBulletin to XenForo in the future and I wondered this:

On vBulletin my statistics (on the frontpage) show this:

Forum statistics
Discussions: 15.281, Postings: 262.143, Members: 21.452
However, when you go to the memberlist http://www.mysite.com/forum/memberlist.php then the amount of members is much less (in my case... about 4.000 members less!). I assume because in the memberlist only members who have clicked on the link in their registration-confirmation email are listed. So members who missed this email (in 99% of the cases due to #@#$% spam filters) are not listed and are in fact not a 'real' member, since they are not able to post and are basically still just 'guests'.

First it is strange that vBulletin shows 2 different amounts, but this is not a vBulletin support forum is it? ;). What I would like to know is: what happens if I transfer my vBulletin site to XenForo? Will XenForo still list the same amount of members on the XF frontpage as it is listed on my current vB frontpage? Or will XF list the amount of members on the frontpage that vBulletin lists in the Memberlist?

It's a small thing ofcourse, but our celebrating member-milestone announcements :) are based upon the number on the frontpage, so if XF would switch that number to the 'Memberlist' number, we will suddenly be going down in the our 'official' member count.
 

Mike

XenForo developer
Staff member
#2
XF only counts users that have validated their accounts. It also doesn't count banned users either. So your total user count will likely go down.
 
R

ragtek

Guest
#3
XF counts AFAIK only the users which have validated there account.

Edit: grr, mike was faster^^
 

James

Well-known member
#5
XF only counts users that have validated their accounts. It also doesn't count banned users either. So your total user count will likely go down.
Presumably it only omits permanently banned users? I'd still class my temporarily banned users as members, just ones who went astray a little.
 

Dean

Well-known member
#6
Presumably it only omits permanently banned users? I'd still class my temporarily banned users as members, just ones who went astray a little.
I've not tested it, but I would assume that while they are banned they are not counted, but when they become unbanned they are counted.
 

Jake Bunce

XenForo moderator
Staff member
#7
Presumably it only omits permanently banned users? I'd still class my temporarily banned users as members, just ones who went astray a little.
It doesn't count any bans, permanent or temporary. I just tested it.

If you are curious:

library/XenForo/Model/User.php

Code:
	/**
	 * Gets the count of total users.
	 *
	 * @return integer
	 */
	public function countTotalUsers()
	{
		return $this->_getDb()->fetchOne('
			SELECT COUNT(*)
			FROM xf_user
			WHERE user_state = \'valid\'
				 AND is_banned = 0
		');
	}
 

James

Well-known member
#10
Ahh, thanks Jake. I would've checked but I don't have access to my install on my current laptop. I wonder if it'd make more sense to run the cron job when a new user is registered/banned? It'd be more efficient than every 10 minutes, I'm sure.

Then again if I remember rightly excess queries aren't something Kier is prone to, so I'm probably overlooking something!
 

Jake Bunce

XenForo moderator
Staff member
#12
I wonder if it'd make more sense to run the cron job when a new user is registered/banned? It'd be more efficient than every 10 minutes, I'm sure.
The server overhead of that cron is negligible. It's not worth worrying about.

Note that the other forum stats are also updated by that cron including the total number of posts and the latest registered user.

Right. So while they are banned they are not counted, and when they become unbanned they are then counted.

Correct?
Yep.
 

Veer

Well-known member
#13
It doesn't count any bans, permanent or temporary. I just tested it.

If you are curious:

library/XenForo/Model/User.php

Code:
	/**
	 * Gets the count of total users.
	 *
	 * @return integer
	 */
	public function countTotalUsers()
	{
		return $this->_getDb()->fetchOne('
			SELECT COUNT(*)
			FROM xf_user
			WHERE user_state = \'valid\'
				 AND is_banned = 0
		');
	}
Jake, I tried this line:
WHERE user_state = \'valid\', \'email_confirm\', \'email_confirm_edit\', \'moderated\'

but getting error when run the cron

Mysqli prepare error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'email_confirm', 'email_confirm_edit', 'moderated' AND is_banned = 0' at line 3
 
R

ragtek

Guest
#14
Your query isn't ok!
If you want to get ALL members you need to remove the "WHERE " part

But instead of changing the original XF file, you should create your own class & method for this and overwrite the orignal one with the xenforo plugin system;)
 

Jake Bunce

XenForo moderator
Staff member
#15
ragtek is correct. Your query isn't syntactically valid. The correct query to count all users (for use in an addon ideally) is:

Code:
SELECT COUNT(*)
FROM xf_user
Or to exclude invalid accounts (awaiting email confirmation or moderation by the admin):

Code:
SELECT COUNT(*)
FROM xf_user
WHERE user_state = \'valid\'
If you are a programmer then you can post in the Development Questions forum for help writing an addon. Or post an Add-on Request and some one may be able to write this for you.
 
#18
It doesn't count any bans, permanent or temporary. I just tested it.

If you are curious:

library/XenForo/Model/User.php

Code:
    /**
     * Gets the count of total users.
     *
     * @return integer
     */
    public function countTotalUsers()
    {
        return $this->_getDb()->fetchOne('
            SELECT COUNT(*)
            FROM xf_user
            WHERE user_state = \'valid\'
                 AND is_banned = 0
        ');
    }
I was looking for this

Thanks Jake