• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

「WordPressでのデバッグ」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(外部リソース: 原文タグの修正)
(最新英語版を反映 en:Debugging in WordPress 00:53, 25 December 2015‎ Atachibana版)
9行目: 9行目:
 
これは、デフォルトではfalseであるとみなされ、通常はWordPressの開発コピーでの [[Editing_wp-config.php|wp-config.php]]ファイルにて、trueに設定されています。
 
これは、デフォルトではfalseであるとみなされ、通常はWordPressの開発コピーでの [[Editing_wp-config.php|wp-config.php]]ファイルにて、trueに設定されています。
  
  define('WP_DEBUG', true);
+
  define( 'WP_DEBUG', true );
  define('WP_DEBUG', false);
+
  define( 'WP_DEBUG', false );
  
 
注: The <tt>true</tt> and <tt>false</tt> values in the example are not surrounded by apostrophes (') because they are boolean (true/false) values. If you set constants to <tt>'false'</tt>, they will be interpreted as true because the quotes make it a string rather than a boolean.
 
注: The <tt>true</tt> and <tt>false</tt> values in the example are not surrounded by apostrophes (') because they are boolean (true/false) values. If you set constants to <tt>'false'</tt>, they will be interpreted as true because the quotes make it a string rather than a boolean.
31行目: 31行目:
 
Note that this allows you to write to <tt>/wp-content/debug.log</tt> using PHP's built in <tt>error_log()</tt> function, which can be useful for instance when debugging AJAX events.
 
Note that this allows you to write to <tt>/wp-content/debug.log</tt> using PHP's built in <tt>error_log()</tt> function, which can be useful for instance when debugging AJAX events.
  
  define('WP_DEBUG_LOG', true);
+
  define( 'WP_DEBUG_LOG', true );
  
 
注:WP_DEBUG_LOGが何かをするのに、WP_DEBUGは有効(true)にする必要があります。単独でWP_DEBUG_DISPLAYをオフにすることができるので覚えておきましょう。
 
注:WP_DEBUG_LOGが何かをするのに、WP_DEBUGは有効(true)にする必要があります。単独でWP_DEBUG_DISPLAYをオフにすることができるので覚えておきましょう。
39行目: 39行目:
 
<tt>WP_DEBUG_DISPLAY</tt> is another companion to WP_DEBUG that controls whether debug messages are shown inside the HTML of pages or not. The default is 'true' which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used in conjunction with <tt>WP_DEBUG_LOG</tt> so that errors can be reviewed later.  
 
<tt>WP_DEBUG_DISPLAY</tt> is another companion to WP_DEBUG that controls whether debug messages are shown inside the HTML of pages or not. The default is 'true' which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used in conjunction with <tt>WP_DEBUG_LOG</tt> so that errors can be reviewed later.  
  
  define('WP_DEBUG_DISPLAY', false);
+
  define( 'WP_DEBUG_DISPLAY', false );
  
 
Note: for WP_DEBUG_DISPLAY to do anything, WP_DEBUG must be enabled (true).  Remember you can control WP_DEBUG_LOG independently.
 
Note: for WP_DEBUG_DISPLAY to do anything, WP_DEBUG must be enabled (true).  Remember you can control WP_DEBUG_LOG independently.
47行目: 47行目:
 
<tt>SCRIPT_DEBUG</tt> is a related constant that will force WordPress to use the "dev" versions of core CSS and Javascript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in .js or .css files. Default is false.
 
<tt>SCRIPT_DEBUG</tt> is a related constant that will force WordPress to use the "dev" versions of core CSS and Javascript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in .js or .css files. Default is false.
  
  define('SCRIPT_DEBUG', true);
+
  define( 'SCRIPT_DEBUG', true );
  
 
== SAVEQUERIES==
 
== SAVEQUERIES==
53行目: 53行目:
 
The <tt>SAVEQUERIES</tt> definition saves the database queries to an array and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.
 
The <tt>SAVEQUERIES</tt> definition saves the database queries to an array and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.
  
  define('SAVEQUERIES', true);
+
  define( 'SAVEQUERIES', true );
  
 
The array is stored in the global <tt>$wpdb->queries</tt>.
 
The array is stored in the global <tt>$wpdb->queries</tt>.
63行目: 63行目:
  
 
  <nowiki> // Enable WP_DEBUG mode
 
  <nowiki> // Enable WP_DEBUG mode
define('WP_DEBUG', true);
+
define( 'WP_DEBUG', true );
  
 
// Enable Debug logging to the /wp-content/debug.log file
 
// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
+
define( 'WP_DEBUG_LOG', true );
  
 
// Disable display of errors and warnings  
 
// Disable display of errors and warnings  
define('WP_DEBUG_DISPLAY', false);
+
define( 'WP_DEBUG_DISPLAY', false );
@ini_set('display_errors',0);
+
@ini_set( 'display_errors', 0 );
  
 
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
 
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define('SCRIPT_DEBUG', true);</nowiki>
+
define( 'SCRIPT_DEBUG', true );</nowiki>
  
 
NOTE: You must insert this '''BEFORE''' <tt>/* That's all, stop editing! Happy blogging. */</tt> in the [[Editing_wp-config.php|wp-config.php]] file
 
NOTE: You must insert this '''BEFORE''' <tt>/* That's all, stop editing! Happy blogging. */</tt> in the [[Editing_wp-config.php|wp-config.php]] file
88行目: 88行目:
 
* [http://generatewp.com/wp-config/ WordPress 'wp-config.php' ファイルジェネレーター]
 
* [http://generatewp.com/wp-config/ WordPress 'wp-config.php' ファイルジェネレーター]
 
* [https://github.com/stracker-phil/wp-no-white-screen/ 'No White Screen' plugin: Display the error instead of a white screen]
 
* [https://github.com/stracker-phil/wp-no-white-screen/ 'No White Screen' plugin: Display the error instead of a white screen]
 +
 +
{{原文|Debugging in WordPress|155110}}<!--  00:53, 25 December 2015‎ Atachibana版 -->
  
 
[[Category:上級トピック]]
 
[[Category:上級トピック]]
 
[[Category:WordPress の開発]]
 
[[Category:WordPress の開発]]
  
{{原文|Debugging in WordPress|151827}}<!--  06:08, 27 May 2015‎ Go4glory 版 -->
+
[[en:Debugging in WordPress]]
 +
[[es:Depurar en WordPress]]
 +
[[fr:Débogage dans WordPress]]
 +
[[hr:Ispitivanje kvarova u WordPressu]]
 +
[[it:Debug in WordPress]]
 +
[[ja:WordPressでのデバッグ]]
 +
[[pt-br:Depuração no WordPress]]

2015年12月25日 (金) 00:57時点における版

このページ「WordPressでのデバッグ」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

Debugging PHP code is part of any project, but WordPress comes with specific debug systems designed to simplify the process as well as standardize code across the core, plugins and themes. This page describes the various debugging tools in WordPress and how to be more productive in your coding as well as increasing the overall quality and interoperativity of your code.

Note: While it is not mandatory to account for WP_DEBUG in plugins and themes it is highly recommended that plugin and theme developers use WP_DEBUG mode while working on code they plan to release publicly. If your plugin or theme is not compatible then the errors, notices and warnings it throws will make it impossible for other developers to use your plugin/theme while they have WP_DEBUG enabled and your theme will not be eligible for promotion via the official WordPress tools.

WP_DEBUG

WP_DEBUG /en:WP_DEBUG /en はWordPressを通じて、「デバッグ」モードを開始するため用いることができるPHPの定数(永続的なグローバル変数)です。 これは、デフォルトではfalseであるとみなされ、通常はWordPressの開発コピーでの wp-config.phpファイルにて、trueに設定されています。

define( 'WP_DEBUG', true );
define( 'WP_DEBUG', false );

注: The true and false values in the example are not surrounded by apostrophes (') because they are boolean (true/false) values. If you set constants to 'false', they will be interpreted as true because the quotes make it a string rather than a boolean.

これはWP_DEBUGまたは本番サイト上の他のデバッグツールを使用することは推奨されません。それらはローカルテストおよびステージングインストールのためのものです。

PHP Errors、Warnings、Notices

WP_DEBUGを有効にすると、すべてのPHPエラー、通知や警告が表示されます。This is likely to modify the default behavior of PHP which only displays fatal errors and/or shows a white screen of death when errors are reached.

Showing all PHP notices and warnings often results in error messages for things that don't seem broken, but do not follow proper data validation conventions inside PHP. これらの警告は、関連するコードが発見されたら修正することが容易であり、 and the resulting code is almost always more bug-resistant and easier to maintain.

非推奨の関数と引数

Enabling WP_DEBUG will also cause notices about deprecated functions and arguments within WordPress that are being used on your site. These are functions or function arguments that have not been removed from the core code yet but are slated for deletion in the near future. Deprecation notices often indicate the new function that should be used instead.

WP_DEBUG_LOG

WP_DEBUG_LOG is a companion to WP_DEBUG that causes all errors to also be saved to a debug.log log file inside the /wp-content/ directory. This is useful if you want to review all notices later or need to view notices generated off-screen (e.g. during an AJAX request or wp-cron run).

Note that this allows you to write to /wp-content/debug.log using PHP's built in error_log() function, which can be useful for instance when debugging AJAX events.

define( 'WP_DEBUG_LOG', true );

注:WP_DEBUG_LOGが何かをするのに、WP_DEBUGは有効(true)にする必要があります。単独でWP_DEBUG_DISPLAYをオフにすることができるので覚えておきましょう。

WP_DEBUG_DISPLAY

WP_DEBUG_DISPLAY is another companion to WP_DEBUG that controls whether debug messages are shown inside the HTML of pages or not. The default is 'true' which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used in conjunction with WP_DEBUG_LOG so that errors can be reviewed later.

define( 'WP_DEBUG_DISPLAY', false );

Note: for WP_DEBUG_DISPLAY to do anything, WP_DEBUG must be enabled (true). Remember you can control WP_DEBUG_LOG independently.

SCRIPT_DEBUG

SCRIPT_DEBUG is a related constant that will force WordPress to use the "dev" versions of core CSS and Javascript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in .js or .css files. Default is false.

define( 'SCRIPT_DEBUG', true );

SAVEQUERIES

The SAVEQUERIES definition saves the database queries to an array and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.

define( 'SAVEQUERIES', true );

The array is stored in the global $wpdb->queries.

NOTE: This will have a performance impact on your site, so make sure to turn this off when you aren't debugging.

デバッグのための wp-config.php 例

The following code, inserted in your wp-config.php file, will log all errors, notices, and warnings to a file called debug.log in the wp-content directory. It will also hide the errors so they do not interrupt page generation.

 // Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

// Disable display of errors and warnings 
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

NOTE: You must insert this BEFORE /* That's all, stop editing! Happy blogging. */ in the wp-config.php file

デバッグプラグイン

There are many well-written plugins that handle debugging in WordPress and show more information about the internals, either for a specific component or in general. Some examples of such plugins are Debug Bar, Log Deprecated Notices and Total Security.

History

Before WordPress 3.1, the STYLE_DEBUG constant behaved similarly to SCRIPT_DEBUG but affected CSS files rather than JavaScript. In 3.1 the two constants were merged into SCRIPT_DEBUG, which now affects both types of minified file.

外部リソース

最新英語版: WordPress Codex » Debugging in WordPress最新版との差分