How to customize user tabs in member's area

From aMember Pro Documentation
Revision as of 11:02, 11 May 2016 by Caesar (Talk | contribs)

Jump to: navigation, search

Let's say you want to add a tab to the member's area and remove the Add/Renew tab.

Add this code to site.php file:

Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, function (Am_Event $event) {
      // $user = $event->getUser(); // if required
      $menu = $event->getMenu();
 
      // Add a single tab
      $menu->addPage(array(
              'id' => 'mypage',
              'label' => ___('Do The Thing'),
              'uri' => '/the.thing',
              'order' => 2,
       ));
 
       // Add a tab with subitems
       $menu->addPage(
           array(
               'id' => 'with-subitem',
               'label' => 'With Subitems',
               'uri' => '#',
               'pages' => array(
                    array(
                        'id' => 'subitem1',
                        'label' => 'Subitem 1',
                        'uri' => '/subitem-2'
                    ),
                    array(
                        'id' => 'subitem2',
                        'label' => 'Subitem 2',
                        'uri' => '/subitem-2'
                    )
               )
           )
       );
 
       // Remove a tab
       if ($page = $menu->findOneById('add-renew')) {
           $menu->removePage($page)
       }
 
       // Add sub item to exiting tab
       $page = $menu->findOneById('aff'); // get affiliate page 
       $page->addPage(array(
              'id' => 'my-subitem',
              'label' => ___('Subitem'),
              'uri' => '/sub.item',
              'target' => '_blank', // you can set target attribute if necessary
              'order' => 10,
       ));
 
       //Add a tab based on user access, if user has active subscription to product with # 1
       /* @var $user User */
       $user = $event->getUser();
       if (in_array(1, $user->getActiveProductIds())) {
           $menu->addPage(array(
              'id' => 'mypage',
              'label' => ___('Do The Thing'),
              'uri' => '/the.thing',
              'order' => 2,
           ));
       }
});