===== 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. This can be done by checking in your plugin's main function if ''$_GET['**//my-action//**']'' was set:
if( isset( $_GET[ 'my-action1' ] ) ){
...
}
(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.
If you need to add side bar menu entries to multiple different tabs, you'll want to dynamically set the page type to ''register_plugin()'', so that the side bar menus won't disappear as soon as you click any menu entry created by your plugin (unless this is desired). One way to get around that is to create a simple function called in place of the page type argument that will check what kind of action was called and return a corresponding page type:
function page_type()
{
if( isset( $_GET[ 'my-action1' ] ) ){
return 'page_type1';
} elseif( isset( $_GET[ 'my-action2' ] ) ){
return 'page_type2';
}
}
Let's combine all that knowledge in this example - we want to have a plugin that adds two side bar menu entries: one with **//edit//** action in ''pages'' tab and one with **//show//** action in ''themes'' tab.
First, let's create the plugin's ID:
$thisfile = basename( __FILE__, ".php" );
Then the dynamic page type function that will return proper page type for chosen actions:
function page_type()
{
if( isset( $_GET[ 'edit' ] ) ){
return 'pages';
} elseif( isset( $_GET[ 'show' ] ) ){
return 'themes';
}
}
Now we can register the plugin with page_type() function call in place of page type parameter:
register_plugin(
$thisfile, # Plugin id
'MyPlugin', # Plugin name
'1.0', # Plugin version
'John Hancock', # Plugin author
'http://website.com', # author website
'A plugin that does things', # Plugin description
page_type(), # (dynamic) page type - on which admin tab to display
'main_MyPlugin' # main plugin function
);
And the menu entries with proper actions...
add_action( 'pages-sidebar', 'createSideMenu', array( $thisfile, 'Edit it', 'edit' ) );
add_action( 'theme-sidebar', 'createSideMenu', array( $thisfile, 'Show it', 'show' ) );
Finally the plugin's main function with action detection:
function main_MyPlugin() {
if ( isset ( $_GET['edit'] ) {
...
} 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.