I just read within the documentation several occasions and also have been getting a difficult time trying to puzzle out what's going on using the function. I am increasingly more confused after searching in the documentation, overlooking the origin code too.

add_filter($tag, $hook, $priority, $args)

it appears in my experience the brand new function stretches parents function. What puzzle's me is exactly what areas of the hook becomes overridden. in certain good examples within the documentation i observe that some variables are changed using the $args inside your new $tag.

I almost understood everything here: http://world wide web.andrewnacin.com/2010/05/18/rethinking-template-tags-in-plug ins/

however i could not work out how you pass arguments and which end up overriden.

thanks ahead of time.

add_filter() is really a companion function to apply_filters(). Before apply_filters operates for any certain filter (the $tag argument in add_filter()), you should use add_filter to join up a filter for any tag. When apply_filters() is performed with this tag title, it calls all of the registered filters so as. Filters are utilized to pass data through functions for manipulation. For instance, one which I frequently find myself using may be the wordpress_list_pages filter. I personally use it to get rid of line breaks in the pages list. So here's how it operates:

First I define a function that can take one parameter and returns it we have spent by using it:

function my_list_pages_filter($pages)

I Quickly add the filter hook: add_filter( 'wp_list_pages', 'my_list_pages_filter' )

add_filter informs WordPress "Once the function apply_filters is known as using the first argument being 'wp_list_pages', call my_list_pages_filter." Filters must send a minumum of one value (regardless of the sort: string, array, integer, etc.), plus they expect the function to come back one value.

They offer you a method to manipulate the input before delivering it back.

do_action is definitely an entirely different hook. To be able to send information for your filter function, perform the following (obtained from your example):

<div id="content" <?php $class='post publish_content' echo apply_filters('my_custom_classes', $class) ?>>

After which inside your functions.php file, add this:

add_filter('my_custom_classes','my_custom_classes_function')

function my_custom_classes_function($classes)

This is a pretty rudimentary utilization of filters, but it is a start. You are able to really get a concept of you skill with filters with similar example with a few improvements:

function my_custom_classes_function($classes)

Chris, You appear to become confused with a couple of things:

  1. Filters and Actions aren't related (they are both a kind of what Wordpress calls a 'hook', but otherwise unrelated). Above you stated "with my filter..." but do_action() is perfect for Actions not Filters.
  2. The Tag (i.e. tag parameter to include_filter, apply_filter, add_action, do_action do not have anything related to tags within the XML/HTML sense (- maybe you will know).
  3. When invoking an Action, using do_action() you most likely wish to pass a disagreement additionally towards the mandatory tag title. Above you known as do_action('content_class'), which, first of all, may have no effect unless of course you've first registered an Action using the tag title "content_class", and next, inside your action function content_class_filter (which may be superior named content_class_action out of the box is not related to filters), comes with an optional parameter $classes, which will be '' because you did not supply a disagreement to completemotion following the tag title. Note you also most likely designed to write $output = ..
  4. Filters don't "override" anything (particularly in the OO language sense). Adding multiple filters with similar tag will result in most of these being known as once the apply_filters for that tag is known as. You are able to control the ordering while using priority parameter. Same applies to Actions.