Jump to content
vBWarez - Rest In Peace

[VB] Adding user options in usercp for mod's


Recommended Posts

in Vb3.x you are used to adding changes in the user cp by adding more options to one of the Login, Messaging, Thread View, Date/Time or the "Other" Section of the $customfields array. For example adding a textbox option to the "other" section in the usercp was as simple as adding the following plugin to the "profile_complete" hook


[CODE]//build our customfield
$profilefieldname = 'my_profilefieldname';
$profilefield['description'] = 'This is a description of my_profilefieldname';
$profilefield['size'] = 5;
$profilefield['maxlength'] = 5;
eval('$tempcustom = "' . fetch_template('userfield_textbox') . '";');

//add our customfield
$customfields['other'] .= $tempcustom; [/CODE]

To explain the above code: First we are setting our profilefield variable like name, textbox size, description etc. We write the system 'userfield_textbox' in our variable tempcustom. Then we add that variable to the other section of the customfields array. Well that is a straightforward coding and maybe that is because we are used to it. In vb4 it is little bit more extra coding. First off all the customfields array is not there, so we have to insert our changes by replacing the "other" section of the "modifyoptions" template with the "other"section plus our custom code. Plus some other minor changes and here is same code but for vb4

[CODE]//build our customfield
$profilefieldname = 'my_profilefieldname';
$profilefield['description'] = 'This is a description of my_profilefieldname';
$profilefield['profilefieldid']=$profilefieldname;
$profilefield['currentvalue'] = $vbulletin->userinfo['my_profilefieldname'];
$profilefield['maxlength'] = 5;
$templater = vB_Template::create('userfield_textbox');
$templater->register('profilefieldname', $profilefieldname);
$templater->register('profilefield', $profilefield);
$tempcustom=$templater->render();

//add our customfield
$tempcustom = "\n" .' '.$tempcustom.' ';
$other_search = '\' ' . '. $customfields['.'\''.'other'.'\''.'] . \'';
$other_replace = '\' ' . '. $customfields['.'\''.'other'.'\''.'] . \''.$tempcustom;
$vbulletin->templatecache['modifyoptions'] = str_replace($other_search, $other_replace, $vbulletin->templatecache['modifyoptions']); [/CODE]

The first part of the code is setting our profilefield variables then saving the 'userfield_textbox' template to our $tempcustom using vb4 way. That is by using vB_Template class and registering 'profilefieldname' and 'profilefield' then rendering it. The second part we search for $customfields['other'] and replace by $customfields['other'] itself plus the $tempcustom. Don't get confused by the too many commas in the code I made it like this to make it easier [I think] to read. Actualy here how the other section part looks in the 'modifyoptions' template ' . $customfields['other'] . ' In case you want to add Dropdownlist see the following example

[CODE]:

$profilefieldname = 'my_profilefieldname';
$profilefield['title'] = $vbphrase['my_profilefield_title'];
$profilefield['description'] = $vbphrase['my_profilefield_description'];
$profilefield['profilefieldid']=$profilefieldname;
$profilefield['currentvalue'] = $vbulletin->userinfo['my_profilefieldname'];

$selectbits = '';
$options = array(
'option1' => $vbphrase['option_1'],
'option2' => $vbphrase['option_2'],
);

$templater = vB_Template::create('userfield_select_option');
foreach($options AS $key=>$val) {
$selected = $vbulletin->userinfo['my_profilefieldname'] == $key ? 'selected="selected"' : '';
$templater->register('selected', $selected);
$templater->register('key', $key);
$templater->register('val', $val);
$selectbits.=$templater->render();
}

$templater = vB_Template::create('userfield_select');
$templater->register('profilefieldname', $profilefieldname);
$templater->register('profilefield', $profilefield);
$templater->register('selectbits', $selectbits);
$tempcustom.=$templater->render(); [/CODE]
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...