MyBB Community Forums

Full Version: Add an option in custom profilefield
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

i'm wirting a plugin that will display custom profilefields (if not empty) on postbit.

But right now i'm stuggeling with adding an option to the "add custom profilefield" menu.

I tried this with no success.

Hook (profile_fields.php):
$plugins->add_hook("admin_config_profile_fields_add", "fieldsonpostbit_add"); 

function:
function fieldsonpostbit_add()
{
    global $mybb, $lang, $form, $form_container;
    
    $lang->load("fieldsonpostbit");
    
    if($form_container->_title == $lang->add_new_profile_field)
    {
        $form_container->output_row($lang->show_on_postbit." <em>*</em>", $lang->show_on_postbit_desc, $form->generate_yes_no_radio('showonpostbit', $mybb->input['showonpostbit']));
    }
} 

Any idea how i could achieve this?
$plugins->add_hook("admin_config_profile_fields_add", "fieldsonpostbit_add");

function fieldsonpostbit_add()
{
global $plugins;
$plugins->add_hook("admin_formcontainer_output_row", "fieldsonpostbit_row");
}

function fieldsonpostbit_row($args)
{
    global $mybb, $lang, $form, $form_container;
    
    $lang->load("fieldsonpostbit");
    
    if($args['title'] == $lang->add_new_profile_field)
    {
        $form_container->output_row($lang->show_on_postbit." <em>*</em>", $lang->show_on_postbit_desc, $form->generate_yes_no_radio('showonpostbit', $mybb->input['showonpostbit']));
    }
return $args;
}

Haven't tested, but something like that should work.
Thanks for the try, but it doesn't. Sad
I didn't bother to check what $lang you had before, replace $lang->add_new_profile_field with $lang->min_posts_enabled. That works, just checked.
That didn' work either, but i found the solution here.

Hooks:
$plugins->add_hook("admin_config_profile_fields_begin", "fieldsonpostbit_hook");
$plugins->add_hook("admin_config_profile_fields_add", "fieldsonpostbit_add");
$plugins->add_hook("admin_config_profile_fields_add_commit", "fieldsonpostbit_add_commit");
$plugins->add_hook("admin_config_profile_fields_edit", "fieldsonpostbit_edit");
$plugins->add_hook("admin_config_profile_fields_edit_commit", "fieldsonpostbit_edit_commit");

Functions:
function fieldsonpostbit_hook()
{
	global $plugins;
	
	$plugins->add_hook("admin_formcontainer_end", "fieldsonpostbit_form");
}
function fieldsonpostbit_form()
{
    global $mybb, $lang, $form, $form_container;
    
    $lang->load("fieldsonpostbit");
    
    if($args['title'] == $lang->min_posts_enabled)
	{
		$show_profilefield = array(
			$form_container->output_row($lang->show_on_postbit." <em>*</em>", $lang->show_on_postbit_desc, $form->generate_yes_no_radio('showonpostbit', $mybb->input['showonpostbit']))
		);
		$form_container->output_row($lang->showonpostbit, "", "<div class=\"user_settings_bit\">".implode("</div><div class=\"user_settings_bit\">", $show_profilefield)."</div>");
	}
}
function fieldsonpostbit_add()
{
	global $forum_data;
	
	$forum_data['showonpostbit'] = 1;
}
function fieldsonpostbit_add_commit()
{
global $db, $mybb, $fid;

	$update_array = array(
		"showonpostbit" => $db->escape_string($mybb->input['showonpostbit']),
	);
	$db->update_query("profilefields", $update_array, "fid = '".$fid."'");
}
function fieldsonpostbit_edit()
{
	global $forum_data;
	
	$forum_data['showonpostbit'] = 1;
}
function fieldsonpostbit_edit_commit()
{
global $db, $mybb;

	$update_array = array(
		"showonpostbit" => $db->escape_string($mybb->input['showonpostbit']),
	);
	$db->update_query("profilefields", $update_array, "fid = '".intval($mybb->input['fid'])."'");
}

Still i got one question.
Why do i need to add an extra hook, and what does it exactly do?
What do you mean an extra hook? And my solution worked, fine, I tested it out.
I really don't know what the problem was. The options just didn't show up.
I'm using version 1.6.4 btw.

By adding an hook i mean this part:
$plugins->add_hook("admin_config_profile_fields_add", "fieldsonpostbit_add");

function fieldsonpostbit_add()
{
global $plugins;
$plugins->add_hook("admin_formcontainer_output_row", "fieldsonpostbit_row");
}

What does this do? And why not do it like this directly:
$plugins->add_hook("admin_formcontainer_output_row", "fieldsonpostbit_row");

function fieldsonpostbit_row($args)
{
    global $mybb, $lang, $form, $form_container;
    
    $lang->load("fieldsonpostbit");
    
    if($args['title'] == $lang->add_new_profile_field)
    {
        $form_container->output_row($lang->show_on_postbit." <em>*</em>", $lang->show_on_postbit_desc, $form->generate_yes_no_radio('showonpostbit', $mybb->input['showonpostbit']));
    }
return $args;
} 
It adds the hook only when accessing the add profile fields page, so it doesn't run on every nearly every admin cp page. Since you're using 1.6.4 try $lang->hide_on_profile and it should work.
Thanks for the support. But i updated my Forum to version 1.6.5 and the plugin is working nicely.
It will appear soon at mods.mybb.com