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

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.

主站蜘蛛池模板: 沈阳市| 敦化市| 时尚| 海盐县| 普陀区| 泽库县| 昌乐县| 马龙县| 公安县| 泽州县| 儋州市| 虹口区| 武城县| 澳门| 水城县| 铜川市| 册亨县| 睢宁县| 荣成市| 福海县| 象山县| 夏津县| 中牟县| 深水埗区| 舞阳县| 德钦县| 昌江| 泰宁县| 渝中区| 思南县| 武宣县| 神木县| 石林| 竹山县| 雷州市| 灵川县| 比如县| 新龙县| 临湘市| 宣恩县| 秭归县|