The WordPress SDK offers an easy way to make tabs. The above tabs, taken from ThreeWP Broadcast, consist of the following lines of code.
$tabs = $this->tabs(); $tabs->tab( 'settings' ) ->callback_this( 'admin_menu_settings' ) ->name( 'Settings' ); $tabs->tab( 'post_types' ) ->callback_this( 'admin_menu_post_types' ) ->name( 'Custom post types' ); $tabs->tab( 'maintenance' ) ->callback_this( 'admin_menu_maintenance' ) ->name( 'Maintenance' ); // How I usually handle editing of things // I only display the edit tab if something is being edited. if ( $tabs->get_is( 'edit' ) ) { // Retrieve the id of the thing $id = intval( $_GET[ 'id' ] ); // Check that the thing exists $thing = $this->get_thing( $id ); if ( ! $thing ) $this->wp_die( 'Thing ID does not exist.', $id ); // And now create the tab, passing the ID and the thing as parameters to the callback. // This is so that the callback doesn't have to do double work and retrieve the thing again. $tabs->tab( 'edit' ) ->callback_this( 'admin_menu_edit ) ->name( 'Editing a thing' ) ->parameters( $id, $thing ); } $tabs->tab( 'uninstall' ) ->callback_this( 'admin_uninstall' ) ->name( 'Uninstall' ); echo $tabs;
First the tabs class is instanciated.
Each line after that then creates a tab with a unique ID, settings
, specifies which method to call, $this->admin_menu_settings()
, and finally the name of the tab to display to the user.
Translation
To translate your tabs, your plugin must first load the languages.
$this->load_language();
Then use the following tab methods:
heading_()
instead ofheading()
name_()
instead ofname()
title_()
instead oftitle()
More detailed documentation
For more details, see wordpress/tabs/tabs.php
. There you can find information about:
- Callback parameters
- Default tab
- Tab counts
- Tab headings
- Tab title
Querying the request string