MyBB Community Forums

Full Version: How to make mods make a profile feild
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I make my mod add a profile field? Also how would it get removed upon deactivation.

Would something like this work or am i FAAAAAAAAAAR off?
$profilefieldresult = $db->simple_select('profile field', 'fid', "title = 'custom status'", array('limit' => 1));
	$profilefield = $db->fetch_array($profilefieldresult);
if(empty($profilefield['fid']))
{
$new_profilefield = array(
                'title'	=> ('Custom Status)'),
				'description' => ('Allows users to make their own status!'),
				'field type' => textbox,
				'maximum_lenth' => 300,
				'field_lenth' => 0,
				'display_order' => 1212,
				'required' => 2
				'edit_by_user' => 1,
				'hide_on_profile' => 2
			);
Look on this plugin: http://mods.mybb.com/view/country-flag-in-postbit-2.0

Though its old but its still gives you an idea on how to use Custom Fields.
Try this:
function yourmod_install ()
{
global $db;
$new_profilefield = array(
                "title"    => "Custom Status",
                "description" => "Allows users to make their own status!",
                "field type" => "textbox",
                "maximum_lenth" => 300,
                "field_lenth" => 0,
                "display_order" => 1212,
                "required" => 2,
                "edit_by_user" => 1,
                "hide_on_profile" => 2
            );
$query = $db->insert_query("profilefields", $new_profilefield);
$fid = $db->insert_id($query);
$db->query("ALTER TABLE ".TABLE_PREFIX."userfields
ADD fid".$fid);
}

function yourmod_uninstall ()
{
global $db;
$query = $db->query("SELECT fid, title FROM ".TABLE_PREFIX."profilefields WHERE title='Custom Status'");
$fid = $db->fetch_field($query, "fid");
$db->query("DELETE FROM ".TABLE_PREFIX."profilefields WHERE fid='$fid'");
$db->query("ALTER TABLE ".TABLE_PREFIX."userfields DROP fid".$fid);
}