Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem adding custom nav-tab
#1
I was trying to write a plugin which creates a top level nav-tab in the top navigation, but it's a pain in the ass. (Tried with 3.1 beta and 3.0)
I tried
Code:
add_action("nav-tab", 'createNavTab', array($thisfile, 'FooBar'));
but it doesn't seem to work right, cause when selecting the new tag, the plugin tag is highlighted too. (Cause the class of the new tab is "plugins", same as plugins tab's class)
In addition it is not possible to create a sidebar for this nav-tab.

One can inject html to show the custom nav-tab right, like
Code:
add_action("nav-tab",'MyCustomNavTab',array($thisfile,"My Tab"));
function SimpleBlogNavTab($name, $title){
    ?>
    <li><a class="<?php echo($name); ?>" <?php if (@$_GET['id'] == @$name): ?>style="/* highlight css */"<?php endif; ?> href="load.php?id=<?php echo($name); ?>"><?php echo($title); ?></a></li>
    <?php
}
but this is a very dirty way and there's still the problem that you can't add a sidebar.
It would be great if you could fix this in a 3.0.1 version or so, cause it is really very upsetting...
Reply
#2
I've updated the documentation in the Wiki regarding tab and sidebar menu items.

Regarding the class to highlight the tab: this seems to be a bug.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#3
mvlcek Wrote:Regarding the class to highlight the tab: this seems to be a bug.
I was struggling with this to, but I've figured it out. For the highlighting to work, set page type in register_plugin() to $thisfile. This works because the following is used to determine the active tab (in createNavTab): (since 3.1 beta)
Code:
if ($plugin_info[$plugin_id]['page_type'] == $tabname) $current = true;

Also added this to the wiki.
Reply
#4
This documentation is not entirely accurate.

This is how tabs work.
These are the requirements I have found, I do not know if this is as per design.

// Syntax
// add_action('nav-tab','createNavTab',array(TABNAME, PLUGINID, 'Tab Title', 'optionalarg'));

// TABNAME is a unique name for the tabs page, it is used to reference the page, eg. adding sidebars. The Tabname must be also be set as your plugins pagetype in register_plugin. It is not necessary for it to match the plugin_id but can for convenience.

// TABID is actually PLUGIN_ID and is used to identify tab selection in querystrings and ties it to the plugin itself, tab ID is the same as your Plugin_id and must match as such, or must match some other valid plugin_id.

// Tab Title is the text title on the tab.


Code:
# get plugin_id from plugin filename
$thisfile=basename(__FILE__, ".php");

$plugin_id = $thisfile;
$tab_name = $plugin_id; // can be unique if you so choose

# register plugin
register_plugin(
    $plugin_id,             //Plugin id
    'pluginname',         //Plugin name
    '0.1',            //Plugin version
    'author',              //Plugin author
    'url',                    //author website
    'desc',                //Plugin description
    $tab_name,        //page type - on which admin tab to display
    'tabcalloutfunc'  //main function (administration)
);

add_action('nav-tab','createNavTab',array($tab_name,$plugin_id,'Plugin Tab','tabargument'));
add_action($tab_name.'-sidebar','createSideMenu',array($plugin_id,'Setup Hello World','sidebarargument'));

function tabcalloutfunc(){
  echo "Hello World";
}

Hope it helps someone.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
shawn_a Wrote:This documentation is not entirely accurate.

I fear it is your description that is not correct:
  • 'someargumenttopass' is the value of the (optional) HTTP parameter action
  • the third parameter to createSideMenu is also the value of the action parameter and not a function name

I checked the description in the Wiki again and couldn't find any errors.
Please tell me the inaccuracies so I can correct them.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply




Users browsing this thread: 1 Guest(s)