User Tools

Site Tools


plugins:tabs_menus

This is an old revision of the document!


Side Menu Creation Function

You can add menu links to any of GetSimple's tabs with the following code

add_action( 'xxxxxx-sidebar', 'createSideMenu', array( 'your-plugin-filename', 'Menu Text' ) );

Replace xxxxxx-sidebar with the sidebar you want(e.g.: backups-sidebar, files-sidebar, pages-sidebar, plugins-sidebar, settings-sidebar, support-sidebar or theme-sidebar)

(3.1+) If you want to add multiple links for your plugin, you can add an optional 3rd parameter in the params array:

add_action( 'xxxxxx-sidebar', 'createSideMenu', array( 'your-plugin-filename', 'Menu Text', 'my-action' ) );

This way a new parameter my-action is added to the link so you can determine which link was clicked.

(3.1+) If you want a functionality like the “Edit Page” link which is only visible if the function is active, add a 4th parameter in the params array as false:

add_action( 'xxxxxx-sidebar', 'createSideMenu', array( 'your-plugin-filename', 'Show It', 'list' ) );
add_action( 'xxxxxx-sidebar', 'createSideMenu', array( 'your-plugin-filename', 'Edit It', 'edit', false ) );

When you click the newly created menu link, the function you registered in register_plugin() will be called, and unless you specified the page your new menu link is on in the 7th argument of register_plugin(), the side menu will disappear.

Thus if you add side bar links to two different tabs, you need to change this page type parameter dynamically, e.g. setup on the plugins tab, other functionality on theme tab:

$thisfile = basename(__FILE__, ".php");

# register plugin
register_plugin(
	$thisfile,      //Plugin id
	'Hello World', 	//Plugin name
	'1.0', 		//Plugin version
	'Chris Cagle',  //Plugin author
	'http://www.cagintranet.com/', //author website
	'Finds email addresses in content and components and "hides" them', //Plugin description
	 @$_GET['id'] == $thisfile && @$_GET['action'] == 'setup' ? 'plugins' : 'theme', 
 			//page type - on which admin tab to display
	'hello_world_show'  //main function (administration)
);

add_action( 'plugins-sidebar', 'createSideMenu', array( $thisfile, 'Setup Hello World', 'setup' ) );
add_action( 'theme-sidebar', 'createSideMenu', array( $thisfile, 'Show Hello World', 'show' ) );

If you have multiple sidebar items like above, your main function (here hello_world_show) would look like this:

function hello_world_show() {
  if ( isset ( $_GET['setup'] ) {
    ...
  } elseif ( isset ( $_GET['show'] ) {
    ...
  }
}

Tab Creation Function

(3.1+) You can also add a new tab to the GetSimple administration by using the following code:

add_action( 'nav-tab', 'createNavTab', array( 'thetabname', 'your-plugin-filename', 'Tab Text', 'my-action' ) );

Use a unique name for the tab, e.g. your plugin name like newsmanager. Also use this name for the page type in register_plugin(). The action parameter is again optional. You can then add sidebar links for this tab with

add_action( 'thetabname-sidebar', ... ); // e.g. 'newsmanager-sidebar'

Only use this functionality, if you need a lot of side bar links for you plugin and want to group them.

plugins/tabs_menus.1389180363.txt.gz · Last modified: 2014/01/08 11:26 by Everyone