[WordPress] 外掛分享: Kint Debugger

首頁外掛目錄 › Kint Debugger
WordPress 外掛 Kint Debugger 的封面圖片
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
2,000+
安裝啟用
★★★★
4.8/5 分(14 則評價)
2617 天前
最後更新
0%
問題解決
WordPress 2.5+ v1.2 上架:2012-02-14

內容簡介

此外掛正在等待領養。

Kint Debugger 是一個簡單的包裝工具,使用Kint,這是一個偵錯工具,可以輸出有關於變數和追踪的資訊,並以一個有樣式、可摺疊的格式呈現深層陣列和物件的內容,使它更容易了解。

不再需要在 print_r 或 var_dump 之前添加 PRE 標籤!

Kint Debugger 能與 Debug Bar 外掛配合良好,通過創建自己的面板以顯示您的調試結果。

基本使用
<?php d( $var ); ?>

例子:

<?php
global $post;
$term_list = wp_get_post_terms( $post->ID, 'my_taxonomy', array( 'fields' => 'all' ) );
d( $term_list );
?>

Kint Debugger 還提供一些輔助函數,以更經常使用的方式顯示變量。

dump_wp_query()
dump_wp()
dump_post()
dump_this( $var, $inline = false ) – 下面有解釋

例子:

<?php dump_post(); ?>

<?php add_action( 'wp_head', 'dump_post' ); ?>

如果此外掛沒有啟用,呼叫輔助函數將會引起錯誤。

自訂函數

如果您在不同的位置輸出相同的資訊,考慮在主題的 functions.php 檔案或 mu-plugin 中編寫自己的輔助函數。例如:

<?php
function my_dump_terms() {
global $post;
$term_list = wp_get_post_terms( $post->ID, 'my_taxonomy', array( 'fields' => 'all' ) );
d( $term_list );
}
?>

然後在主題或外掛的戰略性點:

<?php my_dump_terms(); ?>

使用 Debug Bar

當 Debug Bar 外掛安裝且啟用時,Kint Debugger 會將 d() 輸出發送到其 Debug Bar 面板。

要改為行內輸出,就像未啟用 Debug Bar 一樣,請在您的 config.php 檔案(或實際上在您的 d() 呼叫之前的任何位置)中聲明常數 KINT_TO_DEBUG_BAR:

define( 'KINT_TO_DEBUG_BAR', false );

或者使用帶有參數 $inline 的輔助函數來印出特定的輸出。通用函數 dump_this() 接受 $inline 為第二個參數。

例子:

<?php dump_post( true ); ?>

<?php
global $post;
$term_list = wp_get_post_terms( $post->ID, 'my_taxonomy', array( 'fields' => 'all' ) );
dump_this( $term_list , true );
?>

Kint Debugger 覆蓋 Kint 的 d() 函數以緩衝其輸出,以供 Debug Bar 使用。如果您已經有修改過的 d() 函數,則需要通過以下兩種方式之一來防止其被覆蓋。

將修改過的 d() 函數移到 mu-plugin 中。Kint Debugger 在聲明它之前檢查函數是否存在,因此把您的函數放在 mu-plugin 中是確保它存在的唯一方法。
如上述所述,聲明 KINT_TO_DEBUG_BAR。

限制輸出

要限制可見性,使用 kint_debug_display 篩選器。例如,要防止非管理員看到調試輸出:

add_filter( 'kint_debug_display', function( $allow ) { return is_super_admin(); } );

嘗試這些外掛

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.2) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Kint Debugger」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin is up for adoption.

Kint Debugger is a simple wrapper for Kint, a debugging tool to output information about variables and traces in a styled, collapsible format that makes understanding deep arrays and objects easier.
No more adding PRE tags before print_r or var_dump!
Kint Debugger works well with the Debug Bar plugin by creating its own panel to display your debug results.
Basic Usage

Examples:
ID, 'my_taxonomy', array( 'fields' => 'all' ) );
d( $term_list );
?>

Kint Debugger also provides some helper functions for dumping variables that are frequently needed.

dump_wp_query()
dump_wp()
dump_post()
dump_this( $var, $inline = false ) – explained below

Examples:

Obviously, if this plugin is not active, calls to the helper functions will cause errors.
Your Own Functions
If you are dumping the same information in different places, consider writing your own helper functions in your theme’s functions file or an mu-plugin. For example:
ID, 'my_taxonomy', array( 'fields' => 'all' ) );
d( $term_list );
}
?>

Then at strategic points in your theme or plugin:

With Debug Bar
By default, when Debug Bar is installed and active, Kint Debugger will send d() output to its Debug Bar panel.
To print debug output inline instead, as if Debug Bar was not active, declare the constant KINT_TO_DEBUG_BAR in your config.php (or really anywhere before your d() call):
define( 'KINT_TO_DEBUG_BAR', false );

Or to print a specific dump inline, use a helper function with the parameter $inline. The generic dump_this() takes $inline as the second parameter.
Examples:

ID, 'my_taxonomy', array( 'fields' => 'all' ) );
dump_this( $term_list , true );
?>

Kint Debugger overrides Kint’s d() function in order to buffer its output for Debug Bar. If you already have a modified d() function, you need to prevent the override in one of two ways.

Move your modified d() function to an mu-plugin. Kint Debugger checks if the function exists before declaring it so putting yours in an mu-plugin is the only way to ensure it exists first.
Declare KINT_TO_DEBUG_BAR as described above.

Restricting Output
To restrict visibility, use the kint_debug_display filter. For example, to prevent non-admins from seeing the debug output:
add_filter( 'kint_debug_display', function( $allow ) { return is_super_admin(); } );

Try these plugins too

What The File – Identify template files without fail.
Debug This – Peek under the hood with sixty debugging reports just one click away.

延伸相關外掛

文章
Filter
Mastodon