Skip to:
Content
Pages
Categories
Search
Top
Bottom

Question for SamBauers about the menu generator function

  • @null

    Member

    Heya Sam,

    Since you came up with the following function, I think you can help me answer a question about it.

    The function:

    add_action( 'bb_admin_menu_generator', 'myplugin_add_admin_page' );

    function myplugin_add_admin_page() {
    bb_admin_add_menu(__('My plugin'), 'use_keys', 'myplugin');
    bb_admin_add_submenu(__('My plugin sub menu item one'), 'use_keys', 'myplugin', 'myplugin');
    bb_admin_add_submenu(__('My plugin sub menu item two'), 'use_keys', 'myplugin_two', 'myplugin');
    }

    This works, it will add 2 submenu’s to my new menu, but how to show up things like forms under each tab?

    Let’s say I have submenu tab1 and tab2. Under tab1 I want to show form X and use some functions. Under tab2 I want to show form Z and again have some functions their to use the form etc. But how do I declare where it will show what? How do I get stuff under tab1 and how under tab2?

    Do you understand what I mean? Can you give me an excample too?

    Many thanks

    ps. anyone can answer ofcourse :)

Viewing 6 replies - 1 through 6 (of 6 total)
  • @sambauers

    Participant

    From what you have it is pretty easy.

    Just create two functions that contain the content you want displayed, they need to be named after the third variable in the sub menu function:

    ... your code ...

    function myplugin()
    {
    echo 'hello admin';
    }

    function myplugin_two()
    {
    echo 'hello again admin';
    }

    Intercepting post data is another matter though. Then you need to add an action to “bb_admin_head” I think.

    Check out my existing LDAP authentication plugin for some decent example code.

    @null

    Member

    Hi,

    Thanks, so the LDAP also uses more subtabs with different functions/forms in it?

    I’ll take a look at it then. If I have more questions about it, I’ll post them here

    Thanks for your time

    Greetings

    ps: is it also possible to name all the functions you want on tab1 to put them in the menu generator function?

    Like:

    bb_admin_add_submenu(__('My plugin sub menu item one'), 'use_keys', 'myfunctionname1', 'myfunctionname2','myfunctionname3','myplugin');

    Or put all functions in 1 parent function like:

    bb_admin_add_submenu(__('My plugin sub menu item one'), 'use_keys', 'myplugin1', 'myplugin');

    Function name: myplugin1

    this function contains 3 other functions

    end function: myplugin1

    @sambauers

    Participant

    I think the answer to all your questions is no. : )

    I only pointed to the LDAP plugin for an example of processing a form in the admin area.

    If you want to re-use the same function for all admin pages then you have to create functions that call the main function. E.g.

    add_action( 'bb_admin_menu_generator', 'myplugin_add_admin_page' );

    function myplugin_add_admin_page() {
    bb_admin_add_menu(__('My plugin'), 'use_keys', 'myplugin');
    bb_admin_add_submenu(__('My plugin sub menu item one'), 'use_keys', 'myplugin_one', 'myplugin');
    bb_admin_add_submenu(__('My plugin sub menu item two'), 'use_keys', 'myplugin_two', 'myplugin');
    }

    function myplugin_base($number)
    {
    echo 'hello admin ' . $number;
    }

    function myplugin_one()
    {
    myplugin_base('one');
    }

    function myplugin_two()
    {
    myplugin_base('two');
    }

    I think that’s what you are asking anyway.

    @null

    Member

    Okay

    function myplugin_one()
    {
    myplugin_base('one');
    }

    Will appear under tab1

    function myplugin_two()
    {
    myplugin_base('two');
    }

    Will appear under tab2

    Now I have another function (let’s call it function also_tab2() )I want under tab2, how do I get it in tab2? Sorry I just don’t see it :)

    @sambauers

    Participant

    I’m not sure I understand your question exactly…

    Any function you declare in a plugin is callable from anywhere else in that plugin. So…

    function myplugin_two()
    {
    myplugin_base('two');

    echo '<br />Some more text<br />';

    also_tab2();
    }

    etc.. etc..

    @null

    Member

    I think I have figured it out, thanks.

    But 1 more thing. What if I have 2 forms:

    function myplugin_two() {
    plugin_form1();
    }

    and

    function ????_???() {
    plugin_form2();
    }

    myplugin_two is the function that goes under tab 2. It now shows form1, but how can I let it show form2 also under tab 1?.I’ve enterd ???? now cause we can’t have 2 funtions with the same name.

    …………. omg never mind…. I see it now. You can call both forms in the first function and just position them using html and stuff.

    Okay thanks again, this problem is solved!

    _Null

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar