O'Reilly logo

WordPress® All-in-One For Dummies® by Michael Torbert, Andrea Rennick, Kevin Palmer, Cory Miller, Lisa Sabin-Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required