The _init() Function

Applies to: Jamroom 7.0+ Last verified: 2026-10-24
  • What it's for

    Every module's include.php has an _init() function. It runs on every request, for every active module, and is where a module tells the core what it does. Keep it fast: only register things here.

    function xxFoo_init()
    {
        return true;
    }
  • Common registrations

    // CSS and JavaScript
    jrCore_register_module_feature('jrCore', 'css', 'xxFoo', 'xxFoo.css');
    jrCore_register_module_feature('jrCore', 'javascript', 'xxFoo', 'xxFoo.js');
    
    // "Allowed on Profile" in Quota Config
    jrCore_register_module_feature('jrCore', 'quota_support', 'xxFoo', 'on');
    
    // Let admins change the create and update forms with the Form Designer
    jrCore_register_module_feature('jrCore', 'designer_form', 'xxFoo', 'create');
    jrCore_register_module_feature('jrCore', 'designer_form', 'xxFoo', 'update');
    
    // An entry on the module's Tools tab
    jrCore_register_module_feature('jrCore', 'tool_view', 'xxFoo', 'cleanup', array('Clean Up', 'Remove old entries'));
    
    // An extra tab in the module's ACP section
    jrCore_register_module_feature('jrCore', 'admin_tab', 'xxFoo', 'browse', 'Browse');
    
    // Events this module fires, and events it listens for
    jrCore_register_event_trigger('xxFoo', 'foo_created', 'Fired when a foo is created');
    jrCore_register_event_listener('jrCore', 'daily_maintenance', 'xxFoo_daily_maintenance_listener');
    
    // A background queue worker
    jrCore_register_queue_worker('xxFoo', 'process_foo', 'xxFoo_process_foo_worker', 0, 1);
  • Finding more features

    jrCore_register_module_feature($module, $feature, $your_module, $name, $value) registers a feature that another module provides. Modules offer many: Site Builder widgets, text formatters, item action buttons, Dashboard panels, media players and more.

    To find them, search the bundled modules' _init() functions for jrCore_register_module_feature(, and their code for jrCore_get_registered_module_features(, which reads them. With Developer Mode on, a module's Info tab also lists its events.

    See Events and Listeners, The Queue System, Adding to a Module's Tools Tab and Adding a Tab to a Module's ACP.

Tags