How to customise amember user tab menu

Discussion in 'aMember Pro v.4' started by bennyuk1, Jan 24, 2012.

Thread Status:
Not open for further replies.
  1. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    I notice that in amember account area on this site you have customised usertab buttons, as highlighted in attached image.

    How can we add such button to our own installations?

    Specifically I would like to a but that says "Manage/buy Subscriptions" and another that says "Order books", both of which take the user to various signup forms for purchasing products.

    example2.jpg
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is complete example. Place this code to /amember/application/configs/site.php
    PHP:
    <?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
                
    )
            );
        }
    ?>

    winmacsecurity likes this.
  3. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    Great that works fine.

    The only thing that is strange is that when my custom button is "active" the button next to it highlighted Red.

    The code added was
    $event->getMenu()->addPage(
    array(
    'id' => 'membership',
    'label' => 'Other Membership Fees',
    'uri' => '/amember/signup/index/c/default',
    'order' => 150
    )

    But the default "Add/renew" button is highlighted red when the new custom button is active?
  4. samskirrow

    samskirrow New Member

    Joined:
    Feb 6, 2012
    Messages:
    2
    I also want to achieve a similar thing on my site - I used the code above to successfully create the tab when the user signs in. Now I just need to create the content, however I want it to appear where all the user content appears (i.e. just under the tab menu), how can I acheive this, and where do I place my new file that I'm linking to (so that it is protected).

    Many thanks for this great support forum.
  5. mrhoneyfoot

    mrhoneyfoot New Member

    Joined:
    Feb 2, 2012
    Messages:
    5
    Hi, I tried this code snippet and it works great...with one problem. The CSS that makes currently selected tabs red is not working for the new tab. For the other tabs, it's fine. For the new tab, it's not.

    Does this have something to do with the uri being set in 'site.php'? It's a protected page, so instead of just 'amember/blah', it's like 'amember/content/p/id/1/'

    Anyone know how to fix this?

    Thanks.
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    @mrhoneyfoot

    Unfortunately it is impossible to detect that page is active in case of you used 'uri' parameter instead of 'controller' and 'action' to add new tab.

    So please use the following code in site.php. It should fix your issue:
    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',
                    
    'controller' => 'content',
                    
    'action' => 'p',
                    
    'params' => array('id' => 1)
                    
    'order' => 1000
                
    )
            );
        }
  7. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    @bennyuk1

    Your case is a bit more complex. Your page and default renew page use same controller and same action.
    So I recommend you to use the following workaround in your site.php:

    PHP:
    $menu $event->getMenu();
    $menu->addPage(array(
            
    'id' => 'new-add-renew',
            
    'label' => 'Other Membership Fees',
            
    'uri' => '/amember/signup/index/c/default',
            
    'order' => 150));
    $menu->removePage($menu->findOneBy('id''add-renew'));  //remove MVC page so it was not highlighted automatically
    $menu->addPage(array(
            
    'id' => 'add-renew',
            
    'label' => 'Add/Renew Subscription',
            
    'uri' => '/amember/signup/index',
            
    'order' => 150)); // add it again with uri parameter

    //hack to select needed tab
    if (preg_match('#^/amember/signup/index/c/default*#i'$_SERVER['REQUEST_URI'])) {
            
    $menu->findOneBy('id''new-add-renew')->setActive(true);
    } elseif (
    preg_match('#^/amember/signup/index*#i'$_SERVER['REQUEST_URI'])) {
            
    $menu->findOneBy('id''add-renew')->setActive(true);
    }
  8. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    @samskirrow

    The easiest way to add page with your content for users is use build in page maker.
    Just go to aMember CP -> Products -> Protect Content -> Pages and create new record with your content.
    szabo likes this.
  9. paymonthlywebs

    paymonthlywebs New Member

    Joined:
    Feb 23, 2012
    Messages:
    1
    Hi all,

    If you're like me and all you wanted to do is change the text label inside one of the existing tabs and not create a custom tab or anything... (for example: in my case, all I wanted to do was change 'Main Page' so that it reads 'Dashboard' instead) - then I have the easiest and best solution for you...

    Just go to this URL in your admin area http://yoursite.com/amember/admin-trans-global and then navigate to page 25, you'll see the entry for 'Main Page' which you can translate to 'Dashboard'.

    You can change almost any text displayed to customers from here too so it's very useful for all sorts of simple text changes!
  10. luxman

    luxman Member

    Joined:
    Mar 31, 2011
    Messages:
    70
    Do I place the site.php into /application/default/themes/custom ? or into a different folder? Because nothings appearing when placed in the custom folder
  11. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    @luxman
    Please place this file to folder /application/configs
  12. empiremedia

    empiremedia New Member

    Joined:
    Jan 25, 2012
    Messages:
    2
    I understand you are all trying to add tabs, what about deleting them?
  13. spicyniknaks

    spicyniknaks New Member

    Joined:
    Feb 27, 2012
    Messages:
    20
  14. vinca

    vinca New Member

    Joined:
    Sep 16, 2010
    Messages:
    10
    What would i use to delete the add/renew subscription button? I tried this but it had no effect:
    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, create_function('$event', "
    \$event->getMenu()->removePage(\$event->getMenu()->findOneBy('id', 'signup'));"));
  15. vinca

    vinca New Member

    Joined:
    Sep 16, 2010
    Messages:
    10
  16. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200

    I'm getting blank screen with following error in the logs
    PHP Fatal error: Call to a member function getMenu() on a non-object in /var/www/vhosts/****************/application/configs/site.php on line 6, referer: http://*********/*********/member
  17. raw8888

    raw8888 New Member

    Joined:
    May 29, 2011
    Messages:
    12
    I would like to do the same as samskirrow I can get the tab to appear but nomatter where I put the file that it should open I get: Fatal error: Exception thrown without a stack frame in Unknown on line 0. I have tried a basic html file as well as the php file I really need. the script in the site.php is:

    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, 'onUserMenu');
    function onUserMenu(Am_Event $event)
    {
    $event->getMenu()->addPage(
    array(
    'id' => 'specialties',
    'label' => 'Specialties',
    'controller' => 'content',
    'action' => 'specialties.php',
    'params' => array('id' => 20),
    'order' => 150
    )
    );
    }
    I tried to create the page via the admin but the page treats php code as text.
    thanks
  18. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    ok all working now, I forgot to add the

    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, 'onUserMenu');
    function onUserMenu(Am_Event $event)
    {

    bit at the top
  19. dale_s

    dale_s aMember Pro Customer

    Joined:
    Apr 12, 2013
    Messages:
    96
    I have this, which works great at renaming a tab:

    Code:
    //remove tabs
    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, function (Am_Event $event) {
        $user = $event->getUser();
        $menu = $event->getMenu();
    
        if ($page = $menu->findOneById('helpdesk')) {
            $menu->removePage($page);
        }
    });
    
    //add tabs
    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, 'onUserMenu');
    function onUserMenu(Am_Event $event)
    { 
            $event->getMenu()->addPage(
                array(
                    'id' => 'help',
                    'label' => 'Tickets',
                    'uri' => '/members/helpdesk/',
                    'order' => 3
                )
            );
    }
    It's fairly easy to style the tab background color (including hover) with css. But, I'm struggling on how to alter the background color of tab when the tab is in active state (such as the color #88bc40).

    Any suggestions on how to accomplish this?

    Thanks for any help.
  20. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    I believe you can use this CSS rule:
    HTML:
    ul.am-tabs li.active > a {
        background: green;
    }
Thread Status:
Not open for further replies.

Share This Page