I’ve previously written a few posts about using WordPress Actions and Filters to better extend your plugins and/or themes. This time though, I want to talk about leading by example, and using your own hooks and filters to add functionality. What does this mean? It means where a hook or filter exists, you should use it to add your built in functionality. It’s probably easiest to explain by example…so here is a recent issue I ran into. I wanted the ability to create an arbitrary number of ‘tab’ sections in a plugin settings page I was building. Something like this:

Screen Shot 2014-08-15 at 3.16.04 PM

Now, hard coding a list of tabs is easy, but what if I didn’t want to always show the tabs, just the ones that were active? Well, I could simply make the action of outputting the tabs, an filter that get’s looped on. Like this:

[php light=true]
function ck_generate_tabs() {
$tabs = apply_filters( ‘ck_metabox_tabs’, array() );
foreach ( $tabs as $key => $values ) {
?>

  • Posted by Chris Klosowski

    Chris Klosowski is the President of Easy Digital Downloads, the easiest way to sell your digital products with WordPress. Trusted by over 50,000 smart store owners.