User Profile Field Select Options


If you need to get the list of user profile field select options for your plugin, you can query the data from the mdl_user_info_field table, looking for the matching shortname of the field. The select options are stored in the column param1.

Once you have queried these out e.g.

global $DB;

$query = '
    select param1
    from {user_info_field}
    where shortname = :shortname
';

$parameters = ['shortname' => '<profile_field_shortname>'];

$result = $DB->get_record_sql($query, $parameters);

You can then use the PHP explode command to explode the values in param1 into an array as they are stored in the database as separate lines with a line feed (\n) character.

$options = explode("\n", $result->param1);

Revision #1
Created Mon, Feb 10, 2020 2:24 AM by Moodle Wiki
Updated Mon, Feb 10, 2020 2:28 AM by Moodle Wiki