MyBB Community Forums

Full Version: Create custom profile field on Plugin install?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been searching and haven't found anything on this yet. Is the correct way to create a custom profile field through a plugin using the $db->insert_query command? So it would look something like this.. I'm guessing the fields I don't have listed here will have a default value which I don't care about.

$customfield = array(
     array("name", "Twitch Channel",
              "description", "Twitch Channel Name",
              "disporder", 0,
              "type", "text",

$db->insert("profilefields", $customfield)
Here is a simple way to do that:
  • Query the last display order of the current custom profile fields
  • Specify the value of these columns:
    $newpf = array(
    	'name' => 'Twitch Username',
    	'description' => 'Please input with your Twitch Username',
    	'type' => 'textbox',
    	'disporder' => $disporder+1,
    	'viewableby' => '-1',
    	'editableby' => '-1',
    	'maxlength' => 40,
    	'regex' => '^[a-zA-Z0-9][\\\w]{2,40}$'
  • Insert it into profilefields table. It will returns the newest inserted ID.
  • Update profile fields cache.
  • Add fidX column to userfields table, where X is the newest inserted ID.
    Note that by default, MyBB always uses an un-index-ed TEXT type of column. For performance wise, you may use other type of column and adds index to the column if you want to filter users based on it in a query.
  • Optionally, you may want to insert the newest inserted ID to a setting or somewhere else. You can use it for uninstall routine later to remove the profile field.