07) Hooks

At various times while running, WordPress checks to see if any Plugins have registered functions to run at that time.

If so, the functions are run.

Plugins register their functions to execute at various times using “filter” and “action” hooks. Filters expect you to return something and actions do not.

Use these commands in your plugin:

 add_action( $hook, $myFunction );
 add_filter( $hook, $myFunction );

Look for these commands in the PHP source code to see where hooks are executed:

 do_action( "$hook" )
 apply_filters( "$hook", "what_to_filter" )

For instance, look into the wordpress/wp-admin/admin-footer.php template to find the admin_footer_text filter hook. It looks like this:

echo apply_filters( 'admin_footer_text', '<span id="footer-thankyou">' . $text . '</span>' );

Look into the wordpress/wp-admin/admin-header.php template to find the admin_notices action hook.