Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

set_config_option()

Description

Save/ Update config option for user preference or system config. For user group config see set_usergroup_config_option().

Helpful to record the origin of the configuration change.

Parameters

ColumnTypeDefaultDescription
$user_id integer Current user ID. Use NULL for system wide config options
$param_name string Parameter name
$param_value string Parameter value
$activity_log_note string null Optional. Allows a note to be recorded in the activity log entry.

Return

boolean

Location

include/config_functions.php lines 124 to 171

Definition

 
function set_config_option($user_id$param_name$param_value, ?string $activity_log_note null)
{
    
// We do allow for param values to be empty strings or 0 (zero)
    
if (empty($param_name) || is_null($param_value)) {
        return 
false;
    }

    
// Prepare the value before inserting it
    
$param_value config_clean($param_value);
    
$query "INSERT INTO user_preferences (user,parameter,`value`) VALUES (?,?,?)";
    
$current_param_value null;

    if (
is_null($user_id)) {
        
$config_type = array(); # System config.
    
} else {
        
$config_type = array('user' => $user_id); # User config.
    
}

    if (
get_config_option($config_type$param_name$current_param_valuenull)) {
        if (
$current_param_value == $param_value) {
            return 
true;
        }
        
$params[] = 's';
        
$params[] = $param_value;
        if (
is_null($user_id)) {
            
$user_query 'user IS NULL AND usergroup IS NULL';
        } else {
            
$user_query 'user = ?';
            
$params[] = 'i';
            
$params[] = $user_id;
        }

        
$query "UPDATE user_preferences SET `value` = ? WHERE " $user_query " AND parameter = ?";
        
$params[] = "s";
        
$params[] = $param_name;
    } else {
        
$params  = ["i",$user_id,"s",$param_name,"s",$param_value,];
    }

    
log_activity($activity_log_noteLOG_CODE_EDITED$param_value'user_preferences''value'"parameter='" $param_name "'"null$current_param_value);

    
ps_query($query$params);

    
// Clear disk cache
    
clear_query_cache("preferences");

    return 
true;
}

This article was last updated 24th February 2026 11:35 Europe/London time based on the source file dated 19th February 2026 15:50 Europe/London time.