• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Link a preference to an addon?

Jaxel

Well-known member
#1
I would like to add some preference options to /account/preferences...

I know I can do this with account Custom User Fields in the admin CP. But those custom fields are not linked to a specific addon. Is there a way to link preferences to addons?
 

tenants

Well-known member
#2
I might have misunderstood, do you mean you want options to be added to the /account/preference but without using "Custom User Fields" like :


account.png
 

tenants

Well-known member
#3
This can be done with template hooks:

Code:
    public static function templateHook($name, &$contents, array $params, XenForo_Template_Abstract $template)
    {
        $globalParams = $template->getParams();   
        if ($globalParams['visitor']['permissions']['XenLoginSecurity']['canUseLoginSecurity'] == true)
        {
            switch ($name)
            {
                case 'account_wrapper_sidebar_settings':
                    $contents .= $template->create('xlsec_account_sidebar_link', $globalParams);
                break;
                case 'navigation_visitor_tab_links1':
                    $contents .= $template->create('xls_navigation_visitor_tab_links1', $globalParams);
                break;
            }
        }
In my case, the templates look like this:

xls_navigation_visitor_tab_links1
Code:
<li>
    <a class="primaryContent" href="{xen:link login-security/settings}">
        {xen:phrase xlsec_login_security}
    </a>
</li>

xlsec_account_sidebar_link
Code:
<li>
    <a class="primaryContent" href="{xen:link login-security/settings}">
        {xen:phrase xlsec_login_security}
    </a>
</li>
 

James

Well-known member
#4
No, he wants to add a new preference (form field) that links to his add-on.

He can accomplish this with custom user fields, but you cannot assign them to a particular add-on so it's not ideal.
 

Jake Bunce

XenForo moderator
Staff member
#5
Is there a way to link preferences to addons?
You mean similar to templates and phrases? Where the object is assigned to your addon id and is included in the XML file? User prefs don't have an object like that, so the answer is no. You need to manually manage the creation and deletion of the preference in your install / uninstall routines. A custom user field is one existing structure you can use. Or you could extend the user record.