官术网_书友最值得收藏!

Deconstructing an existing plugin: "Hello Dolly"

WordPress ships with a simple plugin named "Hello Dolly". Its name is a whimsical take on the programmer's obligatory "Hello, World!", and it is trotted out only for pedantic explanations like the one that follows (unless, of course, you really do want random lyrics by Jerry Herman to grace your administration screens).

Activating the plugin

Let's activate this plugin so we can have a look at what it does:

  1. Browse to your WordPress Dashboard at http://yoursite.com/wp-admin/.
  2. Navigate to the Plugins section.
  3. Under the Hello Dolly title, click on the Activate link.

You should now see a random lyric appear in the top-right portion of the Dashboard. Refresh the page a few times to get the full effect.

Examining the hello.php file

Now that we've tried out the "Hello Dolly" plugin, let's have a closer look. In your favorite text editor, open up the /wp-content/plugins/hello.php file. Can you identify the following integral parts?

  • The Information Header which describes details about the plugin (author and description). This is contained in a large PHP /* comment */.
  • User-defined functions, such as the hello_dolly() function.
  • The add_action() and/or add_filter() functions, which hook a WordPress event to a user-defined function.

It looks pretty simple, right? That's all you need for a plugin:

  • An information header
  • Some user-defined functions
  • add_action() and/or add_filter() functions

Now that we've identified the critical component parts, let's examine them in more detail.

主站蜘蛛池模板: 绥宁县| 蒲城县| 天柱县| 商丘市| 东至县| 天台县| 望奎县| 苏尼特左旗| 遂川县| 无极县| 延长县| 开化县| 房产| 新津县| 花垣县| 乌拉特中旗| 满城县| 宁国市| 潼关县| 射阳县| 江门市| 梓潼县| 河东区| 大渡口区| 台中市| 临邑县| 鲁甸县| 望都县| 江山市| 信丰县| 成武县| 施秉县| 称多县| 通辽市| 锡林浩特市| 富阳市| 霸州市| 密云县| 石渠县| 贵州省| 黄梅县|