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
plugins:hooks_filters [2016/05/16 15:26]
shawn_a [Creating and Using Plugin Hooks]
plugins:hooks_filters [2017/01/19 16:10]
lokothodida [Creating and Using Plugin Hooks/Filters]
Line 102: Line 102:
 | nav-tab ​         | Insert navigation bar tab     ​| ​        | | nav-tab ​         | Insert navigation bar tab     ​| ​        |
  
-===== Creating and Using Plugin Hooks =====+===== Creating and Using Plugin Hooks/​Filters ​=====
  
-Similar to core hooks, plugins can create their own hooks by using the function ​''​exec_action('your-plugin-hook')''​.  +Similar to core hooks and filters, plugins can create their own by using the functions ​''​exec_action'' ​and ''​exec_filter''​. ​
-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'​)''​.+<​code>​ 
 +exec_action( '​hook_name'​ ); 
 +</​code>​ 
 + 
 +<​code>​ 
 +exec_filter( '​filter_name',​ '​value_to_filter'​ ); 
 +</​code>​ 
 + 
 +If your plugin uses a GS hook to alter content before it is saved (e.g, the [[http://​get-simple.info/​extend/​plugin/​multi-user/​133/​|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. 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.+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