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

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.

主站蜘蛛池模板: 昆山市| 视频| 玉田县| 永和县| 西青区| 会泽县| 天台县| 吴堡县| 东光县| 呼伦贝尔市| 昌黎县| 登封市| 阿拉尔市| 凌云县| 湟中县| 沧州市| 绥中县| 安达市| 肇庆市| 天峨县| 岑巩县| 九江市| 青岛市| 翁源县| 阜新| 清水河县| 门源| 嵊泗县| 漳平市| 浦江县| 汾西县| 中牟县| 大洼县| 西乌| 冕宁县| 石首市| 穆棱市| 柏乡县| 玉门市| 镇远县| 辉县市|