Add metadata to all users

Hi,

 

I want to add a metadata field to all users in my page. I want it for all registered users and for the new registers too.

 

I tried to add a plugin for the new registers:

 

elgg_register_event_handler('init', 'system', 'registro_nuevo_init');


function registro_nuevo_init() {

elgg_register_event_handler('init', 'system', 'registro_nuevo_inicializa');

}


function registro_nuevo_inicializa() {

elgg_register_event_handler('create', 'user', 'inicializa_datos');

}


function inicializa_datos($event, $type, $user) {

$user->puntuacion = '0';

}

​

 

 

But I don't get what I want. (To change registered users I have no idea how to do).

 

  • For new users:

    <?php
    
    elgg_register_event_handler('init', 'system', 'registro_nuevo_init');
    
    function registro_nuevo_init() {
        elgg_register_event_handler('create', 'user', 'inicializa_datos');
    }
    
    function inicializa_datos($event, $type, $user) {
        $user->puntuacion = '0';
    }

    For existing users you could create a script you directly call/execute once (e.g. named it user_update.php and save it in the Elgg install root folder and then call it in your browser with site.url/user_update.php). The following is for Elgg 2.x versions:

    <?php
    
    require_once __DIR__ . '/vendor/autoload.php';
    \Elgg\Application::start();
    
    $ia = elgg_set_ignore_access(true);
    $access_status = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    
    $entities = new ElggBatch('elgg_get_entities', array(
        'type' => 'user',
        'limit' => false,
    ));
    
    foreach ($users as $user) {
        $user->puntuacion = '0';
    }
    
    access_show_hidden_entities($access_status);
    elgg_set_ignore_access($ia);

     

Performance and Scalability

Performance and Scalability

If you've got a need for speed, this group is for you.