WP Debugging

外掛說明

這個外掛會將以下偵錯常數加入 wp-config.php 檔案中,隨著外掛的啟用及停用,會加入及移除常數。任何錯誤都會觸發 PHP 例外狀況。請參考〈WordPress 的偵錯功能〉所列的偵錯常數。

預設設定:

define( 'WP_DEBUG_LOG', true );
define( 'SCRIPT_DEBUG', true );
define( 'SAVEQUERIES', true );

外掛啟用後,便會加入 @ini_set( 'display_errors', 1 );。外掛首次執行時,便會將 WP_DEBUG 設定為 true,之後可在外掛設定頁中變更這項設定。

使用者可在外掛設定頁中設定以下常數。

define( 'WP_DEBUG', true ); // Default on initial plugin installation.
define( 'WP_DEBUG_DISPLAY', false ); // Default when not declared is true.
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); // WordPress 5.2 WSOD Override.

外掛停用後,外掛會盡量重新加入預設的常數及常數值。外掛啟用後,會寫入預設設定並還原外掛停用前儲存的設定。

這個外掛使用 wp-cli/wp-config-transformer 命令,將常數寫入 wp-config.php

Andrew Norcross 開發的 Debug Quick Look 已整合至這個外掛中,協助閱讀 debug.log 檔案。如果網站已安裝 Debug Quick Look 外掛,請在啟用 WP Debugging 前刪除這個外掛。

Query MonitorDebug Bar 為選用的相依性外掛,用來協助使用者進行偵錯及疑難排解。相依性外掛安裝通知訊息會在關閉訊息後 45 天再次顯示。

如果網站的 wp-config.php 儲存於非標準位置,請使用 wp_debugging_config_path 篩選器傳回網站安裝後的 wp-config.php 檔案位置。

wp_debugging_add_constants 篩選器能讓使用者將常數新增至 wp-config.php 中。

這個篩選器會傳回一個索引鍵為常數名稱的陣列,而常數值是一個資料陣列,其中包含字串值及布林值,以指示是否要在沒有引號的情況下傳遞這個值。

$my_constants = [
    'my_test_constant' =>
    [
        'value' => 'abc123',
        'raw' => false,
    ],
    'another_test_constant' => [ 'value' => 'true' ],
];

value 選項包含作為常數值的字串。

raw 選項代表沒有引號的值,而不是將值視為字串置於設定中。預設值為 true,如果是非布林值,請設定為 false

範例:

add_filter(
    'wp_debugging_add_constants',
    function( $added_constants ) {
        $my_constants = [
            'my_test_constant'      => [
                'value' => '124xyz',
                'raw'   => false,
            ],
            'another_test_constant' => [ 'value' => 'true' ],
        ];
        return array_merge( $added_constants, $my_constants );
    },
    10,
    1
);

這個範例會建立以下常數。

define( 'MY_TEST_CONSTANT', '124xyz' );
define( 'ANOTHER_TEST_CONSTANT', true );

開發工作

歡迎在 GitHub 上對 develop 分支提出提取要求。

螢幕擷圖

  • 外掛設定頁面

使用者評論

2024 年 2 月 23 日
Yet another one of your plugins that I love and use all the time! Thank you. (Side note: is there a place to buy you a coffee or donate for your time?)
2023 年 11 月 13 日
This little plugin was a lifesaver for a site of ours, self-hosted via docker. The implementation left us with a curious problem … some configuration someplace somewhere other than the standard lines in wp-config.php was overriding our WP_DEBUG setting. This plugin solved that.
閱讀全部 18 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈WP Debugging〉的開發相關工作。

參與者

〈WP Debugging〉外掛目前已有 8 個本地化語言版本。 感謝全部譯者為這個外掛做出的貢獻。

將〈WP Debugging〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

2.12.2 / 2024-12-02

  • add GA to generate POT
  • update for PCP

2.12.1 / 2024-11-08

  • move register_activation_hook and register_deactivation_hook up the chain

2.12.0 / 2024-11-01

  • exit early(ish) if not on WP Debugging settings page
  • composer update
  • remove load_plugin_textdomain()

2.11.24 / 2024-04-29

  • update link to Debugging in WordPress, thanks @tobifjellner
  • cast variable to array in Bootstrap::deactivate() fix for PHP 8.3

2.11.23 / 2024-03-04

  • composer update
  • WPCS updates

2.11.22 / 2023-05-31 🎂

  • update afragen/wp-dismiss-notice

2.11.21 / 2023-04-29

  • update afragen/wp-dismiss-notice
  • update Debug Quick Look

2.11.18, 2.11.19, 2.11.20 / 2023-02-07

  • composer update

2.11.17 / 2023-01-27

  • updated link to Debugging in WordPress and improved text for translators
  • composer update

2.11.16 / 2023-01-19

  • composer update

2.11.15 / 2023-01-02

  • composer update

2.11.14 / 2022-07-15

  • composer update

2.11.13 / 2022-06-23

  • make anchor preg_match more greedy

2.11.12 / 2022-05-29

  • update to latest afragen/debug-quick-look

2.11.11 / 2022–5-16

  • update wp-dismiss-notice with transient and only poll wp_remote_get() weekly

2.11.10 / 2022-05-10

  • use sanitize_key() for nonces
  • composer update

2.11.9 / 2022-02-05

  • composer update

2.11.8 / 2022-01-24

  • load call to WP_Dependency_Installer() in plugins_loaded hook to avoid loading pluggable.php.
  • update WP_Dependency_Installer

2.11.7 / 2022-01-18

  • fix logic in verify nonce conditional

2.11.6 /2022-01-18

  • proper nonce verification
  • composer updates

2.11.5 / 2022-01-11

  • I messed up the release 🤦‍♂️

2.11.4 / 2022-01-10

  • composer updates

2.11.3 / 2021-12-19

  • more fixes via composer update

2.11.2 / 2021-09-24

  • composer update, cause of course I needed to fix something

2.11.1 / 2021-09-24

  • init in plugins_loaded hook
  • composer update

2.11.0 / 2021-09-23

  • fix security issue for capabilities check, possible CSRF, and nonce checks.

2.10.2 / 2021-09-04

  • only use esc_attr_e for translating strings

2.10.1 / 2021-07-23

  • fix PHP Notice, Settings:line 68
  • update Debug Quick Look admin bar menu for mobile

2.10.0 / 2021-06-30

  • update Debug Quick Look to show menu on mobile

2.9.3 / 2021-06-22

  • update WPConfigTransformer to use alternate anchor if default not present
  • add @10up GitHub Actions for WordPress svn integration

2.9.1 / 2020-11-17

  • update wp-dependency-installer library
  • update wp-cli/wp-config-transformer
  • comment out quote normalization in set_pre_activation_constants(), not sure why I did that but it can cause problems #10

2.9.0 / 2020-08-15

  • use try/catch around use of WPConfigTransformer object

2.8.0 / 2020-08-01

  • exit if called directly
  • NB: I have seen the WPConfigTransformer Exception error live. The issue seems to be that a file_get_contents() on the wp-config.php file path, at random times, returns an empty value. I’m done chasing this random error in wp-cli/wp-config-transformer. Modified version of wp-cli/wp-config-transformer present

2.7.2 / 2020-06-01

  • test wp-config.php everywhere, still occasional WSOD reports.

2.7.1 / 2020-5-15

  • return early if wp-config.php is empty before calling WPConfigTransformer

2.7.0 / 2020-04-30

  • start loading in init hook
  • run process_filter_constants() as chained method in Bootstrap

2.6.1 / 2020-03-28

  • move Settings action link to front
  • change test for wp-config.php file empty

2.6.0 / 2020-02-28

  • load autoloader in main file
  • update composer dependencies

2.5.8 / 2019-12-23

  • badly messed up check for empty wp-config.php

2.5.7 / 2019-12-20

  • check and exit early if wp-config.php is empty
  • return empty array for the above exit

2.5.6 / 2019-11-02

  • early exit if wp-config.php not set in specific functions

2.5.5 / 2019-09-17

  • update composer.json for wp-dependency-installer update, now requires at least PHP 5.6 for spread operator
  • composer update

2.5.4 / 2019-04-25

  • added check for writable wp-config.php, exit with notice if not found

2.5.3 / 2019-04-01

  • update Debug Quick Look to display error log file path

2.5.1 / 2019-04-01

  • updated version of wp-cli/wp-config-transformer

2.5.0 / 2019-03-25

  • added wp_debugging_add_constants filter for users to add their own constants

2.4.3 / 2019-03-09

  • missed an output escape

2.4.2 / 2019-02-26

  • add Domain Path header

2.4.1 / 2019-02-10

  • refactor set/restore pre-activation constants

2.4.0 / 2019-02-06

  • save pre-activation constants for re-installation on deactivation ( say that 5x fast )

2.3.0 / 2019-02-04

  • look for wp-config.php in directory above ABSPATH
  • add filter wp_debugging_config_path to set non-standard path to wp-config.php

2.2.0 / 2019-02-02 🏈

  • initial release on dot org

2.1.1 / 2019-02-01

  • only show WSOD bypass when appropriate
  • update dependencies

2.1.0 / 2019-01-26

  • update Debug Quick Look, minor CSS changes
  • Improve messaging
  • add setting for WP_DISABLE_FATAL_ERROR_HANDLER constant (WSOD)
  • add default setting of WP_DEBUG to true, can be changed

2.0.0 / 2019-01-18

  • total re-write
  • add settings page
  • use wp-cli/wp-config-transformer to change wp-config.php
  • include norcross/debug-quick-look as dependency via composer but use my fork
  • update POT via composer.json and wp-cli
  • add image assets