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

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.

主站蜘蛛池模板: 天门市| 中西区| 辽宁省| 定结县| 米林县| 五大连池市| 靖边县| 油尖旺区| 麦盖提县| 双桥区| 芜湖市| 简阳市| 英德市| 农安县| 保山市| 吉安市| 湘潭县| 新疆| 都江堰市| 大田县| 义马市| 东源县| 青铜峡市| 嘉义县| 伊金霍洛旗| 安阳县| 田阳县| 乡城县| 且末县| 额敏县| 广河县| 汝阳县| 登封市| 鲁山县| 巴林右旗| 满城县| 朔州市| 湘西| 临潭县| 灵璧县| 鸡东县|