get_config_option()

Description

Get config option value from the database. This maybe a system wide config, a user group preference, a user preference, or the result of
overriding a user group preference with a user preference if any are present.

array() - Supply an empty array to return a system config value.
array('usergroup' => 2) - Supply 'usergroup' with the integer user group reference to return a user group config value.
array('user' => 1) - Supply 'user' with the integer user reference to return a user config value.
array('user' => 1, 'usergroup' => 2) - Supply 'user' with the integer user reference and 'usergroup' with the integer
user group reference to return the result of user group config overridden with user preference. Usergroup should always be
that of the supplied user. Don't supply parent group as this will be checked.
IMPORTANT: it falls back (defaults) to the globally scoped config option value if
there's nothing in the database.
global setting e.g. for checking admin resource preferences

Parameters

ColumnTypeDefaultDescription
$config_type array The type of config to retrieve supplied as an array. The following combinations are possible:
$name string Parameter name
&$returned_value
$default mixed null Optionally used to set a default that may not be the current
$returned_value string The config value will be returned through this parameter which is passed by reference.

Return

boolean Indicates if the config option was found in the database or not.

Location

include/config_functions.php lines 326 to 379

Definition

 
function get_config_option(array $config_type$name, &$returned_value$default null)
{
    if (
trim($name) === '') {
        return 
false;
    }

    foreach (
$config_type as $type_value) {
        if (!
is_int_loose($type_value)) {
            return 
false;
        }
    }

    
$params[] = "s";
    
$params[] = $name;

    if (
count($config_type) === 0) {
        
# Return system config.
        
$user_query 'user IS NULL AND usergroup IS NULL';
    } elseif (isset(
$config_type['usergroup']) && !isset($config_type['user'])) {
        
# Return user group preference if present (without considering current user).
        # Also don't consider parent user group.
        
$user_query 'usergroup = ? AND user IS NULL';
        
$params[] = 'i';
        
$params[] = $config_type['usergroup'];
    } elseif (isset(
$config_type['user']) && !isset($config_type['usergroup'])) {
        
# Special case when we want to check only user preference, not considering any user group values.
        
$user_query 'user = ?';
        
$params[] = 'i';
        
$params[] = $config_type['user'];
    } else {
        
# Return user preference if present else user group preference if present.
        
$config_type['usergroup'] = get_usergroup_parent_for_inherit_flag($config_type['usergroup'], 'preferences');
        
$user_query '(user = ? OR usergroup = ?) ORDER BY usergroup LIMIT 1';
        
$params[] = 'i';
        
$params[] = $config_type['user'];
        
$params[] = 'i';
        
$params[] = $config_type['usergroup'];
    }

    
$query "SELECT `value` FROM user_preferences WHERE parameter = ? AND " $user_query;
    
$config_option ps_value($query$paramsnull"preferences");

    if (
is_null($default) && isset($GLOBALS[$name])) {
        
$default $GLOBALS[$name];
    }

    if (
is_null($config_option)) {
        
$returned_value $default;
        return 
false;
    }

    
$returned_value unescape($config_option);
    return 
true;
}

This article was last updated 21st April 2025 18:05 Europe/London time based on the source file dated 17th April 2025 16:15 Europe/London time.