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

Understanding the Includes

When you activate a plugin, the name of the file containing the information header is stored in the WordPress database. Each time a page is requested, WordPress goes through a laundry list of PHP files it needs to load, so activating a plugin ensures that your own files are on that list. To help illustrate this concept, let's break WordPress again.

Exercise – parse errors

Try the following exercise:

  1. Ensure that the "Hello Dolly" plugin is active.
  2. Open the /wp-content/plugins/hello.php file in your text editor.
  3. Immediately before the line that contains function hello_dolly_get_lyric, type in some gibberish text, such as "asdfasdf" and save the file.
  4. Reload the plugins page in your browser.
  5. This should generate a parse error, something like:
    Parse error: syntax error, unexpected T_FUNCTION in /path/to/wordpress/html/wp-content/plugins/hello.php on line 16

Yikes! Your site is now broken. Why did this happen? We introduced errors into the plugin's main file (hello.php), so including it caused PHP and WordPress to choke. If you did not see any errors and instead saw only a blank white page, you need to refer back to the previous chapter and the section on debugging to ensure that you have configured PHP to report errors. This is vital!

Delete the gibberish line from the hello.php file and save to return the plugin back to normal.

The parse error only occurs if there is an error in an active plugin. Deactivated plugins are not included by WordPress and therefore their code is not parsed. You can try the same exercise after deactivating the plugin and you'll notice that WordPress does not raise any errors.

主站蜘蛛池模板: 梅州市| 杨浦区| 东丽区| 巴东县| 日照市| 乌苏市| 高陵县| 和平县| 汝州市| 综艺| 玉屏| 海门市| 冷水江市| 湖南省| 汝城县| 海门市| 昭苏县| 壤塘县| 怀化市| 遵义县| 措美县| 新余市| 绵阳市| 乌鲁木齐市| 仁布县| 板桥市| 都兰县| 承德市| 扎囊县| 西藏| 延庆县| 南丰县| 剑阁县| 兰州市| 喀什市| 锡林郭勒盟| 济南市| 元江| 麟游县| 东明县| 措勤县|