Their explanation of hooks is a bit off. Right at the beginning they get it wrong, here:
In this example, we hook our own custom function to WordPress’ publish-post function, which means that every time WordPress executes the publish-post function, it will also execute this hooked function.
That’s not entirely accurate. The hooked function gets executed not when the publish post function is called, but when the code in WordPress does do_action(‘publish_post’). The hook names do not have to match the functions, and not all functions can be hooked. Same goes for filters, you’re not filtering functions, you’re filtering whatever is passed into apply_filters().
This is an important distinction to make, because I often see new plugin programmers trying to hook to function names and then wondering why it doesn’t work.
Other thoughts:
– The example given for number 2 is incredibly brilliant. I can’t believe I didn’t think of it. However, consider caching, wp-super-cache would break this sort of thing.
– Number 8 only gets the body and part of the head, not the whole page. Putting a hook exactly where you need it is much more useful, but if you really want the whole page, no hooks are really needed. Just ob_start(“callback”) in your plugin. You don’t even need the flush, that happens automatically at end of execution. This may make your page seem slower though.
An avid fan of business, education, technology and finance. I lead a lean, highly focussed and capable team of Java Back End developers and Front End developers through a maze of complex software wizardry to fulfill the web maintenance needs of a large chemical manufacturer. As per Myers-Briggs Personality Types, I am an ESTJ. I pride in a project completed on time and according to plan. My hobbies include all kinds of technology, anything that I can taste and anything that goes fast or flies in the air. I like to read business books and comics in my spare time.
Their explanation of hooks is a bit off. Right at the beginning they get it wrong, here:
That’s not entirely accurate. The hooked function gets executed not when the publish post function is called, but when the code in WordPress does do_action(‘publish_post’). The hook names do not have to match the functions, and not all functions can be hooked. Same goes for filters, you’re not filtering functions, you’re filtering whatever is passed into apply_filters().
This is an important distinction to make, because I often see new plugin programmers trying to hook to function names and then wondering why it doesn’t work.
Other thoughts:
– The example given for number 2 is incredibly brilliant. I can’t believe I didn’t think of it. However, consider caching, wp-super-cache would break this sort of thing.
– Number 8 only gets the body and part of the head, not the whole page. Putting a hook exactly where you need it is much more useful, but if you really want the whole page, no hooks are really needed. Just ob_start(“callback”) in your plugin. You don’t even need the flush, that happens automatically at end of execution. This may make your page seem slower though.