User Tools

Site Tools


plugins:tabs_menus

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
plugins:tabs_menus [2014/01/08 22:44]
Everyone [Side Menu Creation Function]
plugins:tabs_menus [2014/02/07 10:02] (current)
datiswous [Side Menu Creation Function]
Line 3: Line 3:
 You can add menu links to any of GetSimple'​s tabs with the following code You can add menu links to any of GetSimple'​s tabs with the following code
  
-<​code>​add_action( '​xxxxxx-sidebar',​ '​createSideMenu',​ array( '​your-plugin-filename',​ 'Menu Text' ) );</​code>​+<​code ​php>​add_action( '​xxxxxx-sidebar',​ '​createSideMenu',​ array( '​your-plugin-filename',​ 'Menu Text' ) );</​code>​
  
 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''​) 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''​)
Line 9: Line 9:
 (3.1+) If you want to add multiple links for your plugin, you can add an optional 3rd parameter in the params array: (3.1+) If you want to add multiple links for your plugin, you can add an optional 3rd parameter in the params array:
  
-<​code>​add_action( '​xxxxxx-sidebar',​ '​createSideMenu',​ array( '​your-plugin-filename',​ 'Menu Text', '​my-action'​ ) );</​code>​+<​code ​php>​add_action( '​xxxxxx-sidebar',​ '​createSideMenu',​ array( '​your-plugin-filename',​ 'Menu Text', '​my-action'​ ) );</​code>​
  
 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: 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:
-<​code>​+<​code ​php>
 if( isset( $_GET[ '​my-action1'​ ] ) ){ if( isset( $_GET[ '​my-action1'​ ] ) ){
  ...  ...
Line 20: Line 20:
 (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'':​ (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'':​
  
-<​code>​+<​code ​php>
 add_action( '​xxxxxx-sidebar',​ '​createSideMenu',​ array( '​your-plugin-filename',​ 'Show It', '​list'​ ) ); 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 ) ); add_action( '​xxxxxx-sidebar',​ '​createSideMenu',​ array( '​your-plugin-filename',​ 'Edit It', '​edit',​ false ) );
Line 28: Line 28:
  
 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: 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:
-<​code>​+<​code ​php>
 function page_type() function page_type()
 { {
Line 41: Line 41:
 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. 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: First, let's create the plugin'​s ID:
-<​code>​+<​code ​php>
 $thisfile = basename( __FILE__, "​.php"​ ); $thisfile = basename( __FILE__, "​.php"​ );
 </​code>​ </​code>​
 Then the dynamic page type function that will return proper page type for chosen actions: Then the dynamic page type function that will return proper page type for chosen actions:
-<​code>​+<​code ​php>
 function page_type() function page_type()
 { {
Line 56: Line 56:
 </​code>​ </​code>​
 Now we can register the plugin with page_type() function call in place of page type parameter: Now we can register the plugin with page_type() function call in place of page type parameter:
-<​code>​+<​code ​php>
 register_plugin( register_plugin(
  $thisfile,​ #​ Plugin id  $thisfile,​ #​ Plugin id
Line 69: Line 69:
 </​code>​ </​code>​
 And the menu entries with proper actions... And the menu entries with proper actions...
-<​code>​+<​code ​php>
 add_action( '​pages-sidebar',​ '​createSideMenu',​ array( $thisfile, 'Edit it', '​edit'​ ) ); add_action( '​pages-sidebar',​ '​createSideMenu',​ array( $thisfile, 'Edit it', '​edit'​ ) );
 add_action( '​theme-sidebar',​ '​createSideMenu',​ array( $thisfile, 'Show it', '​show'​ ) ); add_action( '​theme-sidebar',​ '​createSideMenu',​ array( $thisfile, 'Show it', '​show'​ ) );
 </​code>​ </​code>​
 Finally the plugin'​s main function with action detection: Finally the plugin'​s main function with action detection:
-<​code>​+<​code ​php>
 function main_MyPlugin() { function main_MyPlugin() {
  if ( isset ( $_GET['​edit'​] ) {  if ( isset ( $_GET['​edit'​] ) {
plugins/tabs_menus.txt ยท Last modified: 2014/02/07 10:02 by datiswous