MyBB Community Forums

Full Version: Add a link to usercp (plugin development)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm developing an add-on, and how do I add a link to the bottom of the menu in usercp where I'm stuck?

At the bottom of the Usercp template (new link, find and replace)

I have knowledge about php but I didn't develop any plugin in mybb, I'm going through the documentation but I don't understand. I checked other themes, but I couldn't find a simple version.

[Image: resim.png]

[Image: resim.png]
That's quite simple to do.
In your activate function, you have to modify your usercp_nav_misc template:
function myplugin_activate() {
  global $db;
  // Create your link template
  $template = [
            'title' => 'myplugin_nav_option',
            'template' => '<tr><td class="trow1 smalltext"><a href="{\$mybb->settings[\\\'bburl\\\']}/LINK_YOU_WANT" class="usercp_nav_item" >THE_LABEL</a></td></tr>',
            'sid' => -2,
            'version' => 1.0,
            'dateline' => TIME_NOW
        ];
  $db->insert_query('templates', $template);
  // Now edit the original template
  require_once MYBB_ROOT . '/inc/adminfunctions_templates.php';
  find_replace_templatesets("usercp_nav_misc", "#" . preg_quote('{$lang->ucp_nav_forum_viewprofile}</a></td></tr>') . "#i", '{$lang->ucp_nav_forum_viewprofile}</a></td></tr>{myplugin_nav_option}');
}

And then, you have to get the hook on the usercp menu building:
$plugins->add_hook('usercp_menu_built', 'myplugin_navoption', -10);
function myplugin_navoption() {
  global $mybb, $usercpnav, $templates, $myplugin_nav_option;
  eval("\$myplugin_nav_option =\"".$templates->get('myplugin_nav_option')."\";");
  $usercpnav = str_replace("{myplugin_nav_option }", $myplugin_nav_option , $usercpnav);
}
(2019-08-02, 11:56 AM)Crazycat Wrote: [ -> ]That's quite simple to do.
In your activate function, you have to modify your usercp_nav_misc template:
function myplugin_activate() {
  global $db;
  // Create your link template
  $template = [
            'title' => 'myplugin_nav_option',
            'template' => '<tr><td class="trow1 smalltext"><a href="{\$mybb->settings[\\\'bburl\\\']}/LINK_YOU_WANT" class="usercp_nav_item" >THE_LABEL</a></td></tr>',
            'sid' => -2,
            'version' => 1.0,
            'dateline' => TIME_NOW
        ];
  $db->insert_query('templates', $template);
  // Now edit the original template
  require_once MYBB_ROOT . '/inc/adminfunctions_templates.php';
  find_replace_templatesets("usercp_nav_misc", "#" . preg_quote('{$lang->ucp_nav_forum_viewprofile}</a></td></tr>') . "#i", '{$lang->ucp_nav_forum_viewprofile}</a></td></tr>{myplugin_nav_option}');
}

And then, you have to get the hook on the usercp menu building:
$plugins->add_hook('usercp_menu_built', 'myplugin_navoption', -10);
function myplugin_navoption() {
  global $mybb, $usercpnav, $templates, $myplugin_nav_option;
  eval("\$myplugin_nav_option =\"".$templates->get('myplugin_nav_option')."\";");
  $usercpnav = str_replace("{myplugin_nav_option }", $myplugin_nav_option , $usercpnav);
}

Thank you buddy. I have a question, how do I set the page and template?
I don't understand your question, which page and which template do you want to set ?
Do you mean the new page in usercp ?
If yes:
1. create the template of your page (same way than for the link)
2. add a hook on usercp_start
3. load your new template if the $mybb->input['action'] matches your link.

You can have an example in ABP Usermap
(2019-08-05, 06:50 AM)Crazycat Wrote: [ -> ]I don't understand your question, which page and which template do you want to set ?
Do you mean the new page in usercp ?
If yes:
1. create the template of your page (same way than for the link)
2. add a hook on usercp_start
3. load your new template if the $mybb->input['action'] matches your link.

You can have an example in ABP Usermap

Very well said. @OP: I also suggest to check this documentation
https://docs.mybb.com/1.8/development/plugins/

This doc is actually very well written and is useful for learning.
I know this is an old topic but you can use this Plugin as Reference as well https://community.mybb.com/mods.php?action=view&pid=602