Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

set_resource_defaults()

Description

Set resource defaults. Optional, a list of field IDs can be passed on to only update certain fields.
IMPORTANT: this function will always set the resource defaults if any are found. The "client code"
is where developers decide whether this should happen

@global string $userresourcedefaults Resource defaults rules value based on user group a user belongs to

Parameters

ColumnTypeDefaultDescription
$ref integer Resource ID
$specific_fields array array Specific field ID(s) to update

Return

boolean

Location

include/resource_functions.php lines 1198 to 1234

Definition

 
function set_resource_defaults($ref, array $specific_fields = array())
    {
    global 
$userresourcedefaults;

    if(
'' == $userresourcedefaults)
        {
        return 
false;
        }

    foreach(
explode(';'$userresourcedefaults) as $rule)
        {
        
$rule_detail         explode('='$rule);
        
$field_shortname     escape_check($rule_detail[0]);
        
$field_default_value $rule_detail[1];

        
// Find field(s) - multiple fields can be returned to support several fields with the same name
        
$fields sql_array("SELECT ref AS `value` FROM resource_type_field WHERE name = '{$field_shortname}'""schema");

        if(
=== count($fields))
            {
            continue;
            }

        
// Sometimes we may want to set resource defaults only to specific fields so we ignore anything else
        
if(count($specific_fields))
            {
            
$fields array_intersect($fields$specific_fields);
            }

        foreach(
$fields as $field_ref)
            {
            
update_field($ref$field_ref$field_default_value);
            }
        }

    return 
true;
    }

This article was last updated 3rd December 2020 12:35 Europe/London time based on the source file dated 30th November 2020 11:55 Europe/London time.