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

create_resource()

Description

create_resource

Parameters

ColumnTypeDefaultDescription
$resource_type integer ID of target resource type
$archive integer 999 ID of target archive state, 999 if archived
$user integer -1 User ID, -1 for current user
$origin string '' Source of resource, should not be blank
$file_extension string '' If specified
$run_macro bool true Run autocomplete macros, can be disabled if they are run later in process

Return

mixed false if invalid inputs given, integer of resource reference if resource is created

Location

include/resource_functions.php lines 551 to 605

Definition

 
function create_resource($resource_type$archive 999$user = -1$origin ''$file_extension ''$run_macro true)
{
    
# Create a new resource.
    
global $k,$terms_upload;

    if (!
is_numeric($archive)) {
        return 
false;
    }

    
$alltypes get_resource_types(""falsefalsefalse);
    if (!
in_array($resource_typearray_column($alltypes"ref"))) {
        return 
false;
    }

    if (
$archive == 999) {
        
# Work out an appropriate default state
        
for ($n = -2$n 3$n++) {
            if (
checkperm("e" $n)) {
                
$archive $n;
                break;
            }
        }
    }

    if (
$user == -1) {
        global 
$userref;
        
$user $userref;
    }

    
ps_query("INSERT INTO resource(resource_type,creation_date,archive,created_by,file_extension) VALUES (?,NOW(),?,?,?)", ["i",$resource_type,"i",$archive,"i",$user,"s",$file_extension]);

    
$insert sql_insert_id();

    
# set defaults for resource here (in case there are edit filters that depend on them)
    
set_resource_defaults($insert);

    
hook('resourcecreate''', array($insert$resource_type));

    
# Autocomplete any blank fields
    
if ($run_macro) {
        
autocomplete_blank_fields($inserttrue);
    }

    
# Log this
    
daily_stat("Create resource"$insert);

    
resource_log($insertLOG_CODE_CREATED0$origin);
    if (
upload_share_active() !== false) {
        
# Terms needed to be accepted to complete upload
        
$notes = ($terms_upload "Terms accepted" "");
        
resource_log($insertLOG_CODE_EXTERNAL_UPLOAD0$notes''$k ' ('  get_ip() . ')');
    }

    return 
$insert;
}

This article was last updated 4th September 2025 10:35 Europe/London time based on the source file dated 2nd September 2025 11:15 Europe/London time.