2. Filters are functions that take in some kind of input, modify it and return it Source: http://ottopress.com/2011/actions-and-filters-are-not-the-same-thing/
3. Actions are places where a function is called and we don‘t care what it returns. In a sense, a Filter w/o args and return value Source: http://ottopress.com/2011/actions-and-filters-are-not-the-same-thing/
4. In Core /** * Hooks a function on to a specific action. */ functionadd_action( $tag, $function_to_add, $priority = 10, $accepted_args= 1 ) { returnadd_filter( $tag, $function_to_add, $priority, $accepted_args); } /** * Hooks a function or method to a specific filter action. */ functionadd_filter( $tag, $function_to_add, $priority = 10, $accepted_args= 1 ) { global$wp_filter, $merged_filters; $idx= _wp_filter_build_unique_id($tag, $function_to_add, $priority); $wp_filter[$tag][$priority][$idx] = array( 'function‘ => $function_to_add, 'accepted_args' => $accepted_args ); unset( $merged_filters[ $tag ] ); returntrue; }
5. In a Plugin /** * Does something with the content */ functionmy_custom_function( $content ) { // Do something with the content return$content; } add_filter( 'the_content', 'my_custom_function' );
6. In a Class classMy_Custom_Class { /** * Construct */ public function __construct() { add_filter( 'the_content', array( &$this, 'my_custom_method' )); } /** * Does something with the content */ public functionmy_custom_method( $content ) { // Do something with the content return$content; } }