我已经更新了Michael的解决方案,这样就可以在一个页面内将其用作选项卡。通过调用main_function()
, 您将输出选项卡,这些选项卡将链接并输出$my_plugin_tabs
部分
例如,通过单击设置,您将加载选项卡settings.php
并显示选项卡。我想这也可能有助于上传:
<?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 );
}