User Tools

Site Tools


plugins:hooks_filters

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
plugins:hooks_filters [2014/01/03 10:49]
Everyone [Core Filters]
plugins:hooks_filters [2016/05/16 15:26]
shawn_a [Creating and Using Plugin Hooks]
Line 3: Line 3:
 ===== Core Filters ===== ===== Core Filters =====
  
-<​code>​add_filter('​filter_name','​function_to_call'​);</​code>​+<​code>​add_filter( '​filter_name',​ '​function_to_call'​ );</​code>​
   * **content** Will allow you to alter or filter the //​$content//​ variable. The function that you pass $content to should then return your results back to the system.   * **content** Will allow you to alter or filter the //​$content//​ variable. The function that you pass $content to should then return your results back to the system.
   * **menuitems** Will allow you to alter or filter the main navigation that is shown with the //​get_navigation//​ template tag. The function that you pass //$menu// to should then return your results back to the system.   * **menuitems** Will allow you to alter or filter the main navigation that is shown with the //​get_navigation//​ template tag. The function that you pass //$menu// to should then return your results back to the system.
Line 10: Line 10:
 |content ​       |filters page content data                              | string ​       |         | |content ​       |filters page content data                              | string ​       |         |
 |menuitems ​     |filters the menu html returned in ''​get_navigation()''​ | string ​       |         | |menuitems ​     |filters the menu html returned in ''​get_navigation()''​ | string ​       |         |
-|**pagecache** ​ |filters ​''​$pagesarray''​ data before saving ​            ​array         | 3.3+    |+|**pagecache** ​ |filters ​the page cache xml object ​before saving ​       simplexmlobj  ​| 3.3+    |
 |**sitemap** ​   |filters the ''​$sitemap''​ xmlobj before saving ​         | simplexmlobj ​ | 3.3+    | |**sitemap** ​   |filters the ''​$sitemap''​ xmlobj before saving ​         | simplexmlobj ​ | 3.3+    |
-|**pageid**     ​|filters global page ''​$id'' ​                           | string ​       | 3.3+    |+|**indexid**    |filters global page ''​$id'' ​                           | string ​       | 3.3+    |
 |**data_index** |filters global page ''​$data_index''​ obj                | simplexmlobj ​ | 3.3+    | |**data_index** |filters global page ''​$data_index''​ obj                | simplexmlobj ​ | 3.3+    |
 +|**editorlinks**|filters editor links ''​get_link_menu_array'' ​          | array| 3.3+    |
 ===== Core Hooks ===== ===== Core Hooks =====
  
-<​code>​add_action('​hook_name','​function_to_call',​array(arguments));</​code>​+<​code>​add_action( '​hook_name',​ '​function_to_call',​ array( arguments ) );</​code>​
  
 The last argument is only necessary if function_to_call accepts parameters. The last argument is only necessary if function_to_call accepts parameters.
Line 100: Line 101:
 | theme-sidebar ​   | Sidebar item on Theme Page    |         | | theme-sidebar ​   | Sidebar item on Theme Page    |         |
 | nav-tab ​         | Insert navigation bar tab     ​| ​        | | nav-tab ​         | Insert navigation bar tab     ​| ​        |
 +
 +===== Creating and Using Plugin Hooks =====
 +
 +Similar to core hooks, plugins can create their own hooks by using the function ''​exec_action('​your-plugin-hook'​)''​. ​
 +If your plugin uses a GS hook to alter content before it is saved (eg, the MultiUser plugin changes the output to the user.xml file and makes all changes from other plugins in this hook undone), it is especially important to add a custom hook, so that other plugin developers can make their plugins compatible with yours if they need to alter the data too. 
 +
 +If you created a plugin hook called '​your-plugin-hook',​-as described in the paragraph above-, other plugin developers could then (1) detect whether your plugin is active by using ''​pluginIsActive('​your-plugin-name'​)''​(GS 3.3.4+) or by checking for existence of your init function/ a constant you defined, and (2) use your hook with ''​add_action('​your-plugin-hook',​ '​their-function'​)''​.
 +
 +This is an important step to take in making multiple plugins from different authors compatible with one another.
 +
 +When naming hooks in your plugins be sure to use a unique name to not step on core hook ids.
plugins/hooks_filters.txt ยท Last modified: 2017/01/19 16:10 by lokothodida