I've updated Michael's solution so that it can be used as a tab within a single page. By calling main_function()
, you will output the tabs which will link and output the files outlined in the $my_plugin_tabs
section.
For instance, by clicking on Settings you will have the tab load settings.php
and have the tabs showing. I thought it might help to have this uploaded as well:
<?php
// Create WP Admin Tabs on-the-fly
function admin_tabs( $page, $tabs, $current=NULL ) {
if ( is_null( $current ) ) {
if ( isset( $_GET['tab'] ) ) {
$current = $_GET['tab'];
}
}
$content = '';
$content .= '<h2 class="nav-tab-wrapper">';
foreach( $tabs as $tab => $tabname ) {
if ( $current == $tab ) {
$class = ' nav-tab-active';
} else {
$class = '';
}
$content .= '<a class="nav-tab' . $class . '" href="?page=' .
$page . '&tab=' . $tab . '">' . $tabname . '</a>';
}
$content .= '</h2>';
echo $content;
if ( ! $current )
$current = key( $tabs );
require_once( $current . '.php' );
return;
}
function main_function() {
$my_plugin_tabs = array(
'bundles' => 'Bundles',
'settings' => 'Settings',
);
$my_plugin_page = 'bundles';
echo admin_tabs( $my_plugin_page, $my_plugin_tabs );
}