Adding More Than 1 New Tab in Members Area

Discussion in 'aMember Pro v.4' started by rsl101, Nov 16, 2013.

  1. rsl101

    rsl101 Guest

    Hello,

    Could someone please tell me how to add multiple new tabs to the members and assign pages to them?

    I can use this in the site.php file to create 1 new tab correctly:
    <?php
    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, 'onUserMenu');
    function onUserMenu(Am_Event $event)
    {
    $event->getMenu()->addPage(
    array(
    'id' => 'pageid',
    'label' => 'Button label',
    'uri' => '/test/url',
    'order' => 1000
    )
    );
    }
    ?>

    But the question is, how do I create more tabs?

    How can I also create dropdowns from tabs in the members area?

    Thank you!
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hey,

    You can add as many tabs as you want same way. In order to set up sub tabs you need to use additional array with key pages. Here example of code for you:

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU'onUserMenu');
     
    function 
    onUserMenu(Am_Event $event)
    {
        
    $event->getMenu()->addPage(
            array(
                
    'id' => 'pageid',
                
    'label' => 'Button label',
                
    'uri' => '/test/url',
                
    'order' => 1000
            
    )
        );
     
        
    $event->getMenu()->addPage(
            array(
                
    'id' => 'otherpageid',
                
    'label' => 'Other Button label',
                
    'uri' => '/other/test/url'
            
    )
        );
     
        
    $event->getMenu()->addPage(
            array(
                
    'id' => 'subitemspageid',
                
    'label' => 'With Subitems',
                
    'uri' => '#',
                
    'pages' => array(
                    array(
                        
    'id' => 'subitem1',
                        
    'label' => 'Subitem 1',
                        
    'uri' => '/subitem-2'
                    
    ),
                    array(
                        
    'id' => 'subitem2',
                        
    'label' => 'Subitem 2',
                        
    'uri' => '/subitem-2'
                    
    )
                )
            )
        );
    }
    rsl101 likes this.
  3. rsl101

    rsl101 Guest

    Thank you very much...This is just what I was looking for. Thanks again!
  4. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Just to hijack this thread for a bit is it possible to remove a Tab and replace it with another but just for a specific product?
  5. rsl101

    rsl101 Guest

    Hey Ceasar,

    Thanks again, one last thing if you could. In regards to the code you sent above, which does work perfectly. What would I need to add to that code, to add a submenu item to an existing tab.

    Such as adding a dropdown menu option to the existing Payments History Tab?

    Thank you!
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
  7. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Thanks for that caesar but how do you remove a tab based on 1 user product please?
  8. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can find example in link that I gave before. Anyway here is example of code to remove add/renew tab if user has active subscription to product with #1.

    Code:
    Am_Di::getInstance()->hook->add('userMenu', 'siteUserMenu');
    function siteUserMenu(Am_Event $event)
    {
        $menu = $event->getMenu();
        $user = $event->getUser();
    
        if (in_array(1, $user->getActiveProductIds())) {
            $page = $menu->findOneBy('id', 'add-renew');
            $menu->removePage($page);
        }
    }
    

Share This Page