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

Lack of interest Number of user states is hard coded, making it difficult to extend

Jon W

Well-known member
#1
In XenForo_ControllerHelper_UserCriteria, there is a filter that checks whether all user states are ticked and, if so, unsets the criteria. This is done by checking whether there are EXACTLY 4 that are ticked, as follows:
PHP:
        if (isset($criteria['user_state']) && is_array($criteria['user_state']) && count($criteria['user_state']) == 4)
        {
            // all types selected, no filtering
            unset($criteria['user_state']);
        }
This makes it difficult for a developer to add new user criteria, because it means that we have to add some sort of hack to any controller that calls that helper and add back the criteria (or something similar).

It would be much nicer if that number 4 was calculated by counting a static array of all the user states inside that helper (or something similar).

In other words, you would change to:
PHP:
        if (isset($criteria['user_state']) && is_array($criteria['user_state']) && count($criteria['user_state']) == count(self::$userStates))
        {
            // all types selected, no filtering
            unset($criteria['user_state']);
        }
and then add:
PHP:
public static $userStates = array('email_confirm','email_confirm_edit','moderated','valid');
to the top of the class.

The array of $userStates could then be easily added to by any add-on to get a correct count.
 
Last edited:

Jon W

Well-known member
#3