Exploring Plugin Interaction with WordPress

WordPress plugins use an Application Programming Interface (API) provided within WordPress to make plugin development easier. The API provides hooks, which are means of calling pieces of functionality built into the WordPress core application. For example, in the core of WordPress is functionality for publishing a post. If a plugin wants to execute that functionality, it uses an action hook to call and execute the publish post functionality.

The two types of hooks in the API are

  • Action hooks: WordPress launches these hooks at specific points during execution of PHP code or as specific events occur.
  • Filter hooks: WordPress launches these hooks to modify text before it's added to the database or sent to the browser screen.

image A complete list of action hooks available for plugin development can be found in the WordPress documentation at http://codex.wordpress.org/Plugin_API/Action_Reference. A complete list of filter hooks can be found at http://codex.wordpress.org/Plugin_API/Filter_Reference.

Understanding action hooks

To explore a simple action hook within the API, we analyze the Hello Dolly plugin by Matt Mullenweg. When activated, the Hello Dolly plugin randomly displays a lyric from the song “Hello Dolly!” by Louis Armstrong in the upper right of every page in the WordPress Dashboard.

The following code in the Hello Dolly plugin calls ...

Get WordPress® All-in-One For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.