[WordPress] 外掛分享: Debug-Bar-Extender

首頁外掛目錄 › Debug-Bar-Extender
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
700+
安裝啟用
★★★★
4.6/5 分(5 則評價)
5309 天前
最後更新
問題解決
WordPress 3.1+ v0.5 上架:2011-03-01

內容簡介

這個外掛為偵錯列(debug-bar)增加了更多功能,主要針對開發者喜歡除錯(debug)程式碼的人,或測量執行時間以找出程式碼中的錯誤。
它還允許通過在源代碼中添加簡單的代碼片段查找變量。

請注意,本外掛程序應僅用於偵錯或開發環境中使用,並不適用於生產環境的網站。

需求

此外掛需要debug-bar插件 > 0.5和開發人員的大腦才能正常工作。

用法
用法示例:剖析主題的程式迴圈(debug the loop)

按照以下方式將您的檢測點添加到index.php或任何其他模板文件中。

<?php if (have_posts()) : ?>

<?php Debug_Bar_Extender::instance()->checkpoint('loop start'); ?>

<?php while (have_posts()) : the_post(); ?>

<?php Debug_Bar_Extender::instance()->trace_var( $post ); ?>

<?php Debug_Bar_Extender::instance()->checkpoint('loop1'); ?>

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php //before_post(); ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time(get_option('date_format')) ?> by <?php the_author() ?></small>
<div class="entry">
<?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?>
</div>
<p class="postmetadata"><?php the_tags(__('Tags:', 'kubrick') . ' ', ', ', '<br />'); ?> <?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?> <?php comments_popup_link(__('No Comments »', 'kubrick'), __('1 Comment »', 'kubrick'), __('% Comments »', 'kubrick')); ?></p>
<?php after_post(); ?>
</div>

<?php Debug_Bar_Extender::instance()->checkpoint('loop2'); ?>

<?php endwhile; ?>

<?php Debug_Bar_Extender::instance()->checkpoint('loop end'); ?>

<div class="navigation">
<div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries', 'kubrick')) ?></div>
<div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;', 'kubrick')) ?></div>
</div>
<?php else : ?>

進階用法

查看debug-bar-extender.php文件源代碼,您會注意到有各種過濾器(filter)可以控制預設設置。在多站點安裝(multisite install)上工作且希望使用檢測列而不必每次都調整設置時,這很有用。這裡是如何強制執行php文件中的設置的示例(mu-plugins/):

add_filter( 'debugbarextender_default_settings', 'my_debug_bar_extender_settings' );
//強制實行debug bar設置
function my_debug_bar_extender_settings( $default_settings ) {
$default_settings = array(
'enable_profiler' => 1,
'enable_variable_lookup' => 1,
'track_default_vars' => 0,
'add_default_checkpoints' => 1,
'savequeries_debugmode_enable' => 1,
'use_error_log' => 0,
'allow_url_settings' => 1,
'enable_admin_bar_menu' => 1,
);
return $default_settings;}

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.5) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Debug-Bar-Extender」→ 直接安裝(推薦)

原文外掛簡介

This plugins adds more features to the debug-bar and is mainly aimed at developers who like to debug their code or want to measure runtimes to find glitches in their code.
It also allows lookup of variables by adding simple code snippets in your source.
Please note that this plugin should be used solely for debugging or on a development environment and is not intended for use in a production site.
Requirements
This plugin requires the debug-bar plugin >0.5 and a developers’ brain to work correctly.
Usage
Usage example to debug the loop of a theme
Add your checkpoints in the index.php or any other template file as shown below.

checkpoint('loop start'); ?>

trace_var( $post ); ?>

checkpoint('loop1'); ?>

id="post-">

by

checkpoint('loop2'); ?>

checkpoint('loop end'); ?>

Advanced usage
Looking at the source of the debug-bar-extender.php you will notice that there are various filters to control the default settings. This is useful when you are working on a multisite install and want to use the debug bar without having to adjust the settings every time. Here’s an example of how settings enforced by a php file in mu-plugins/ could look like
add_filter( 'debugbarextender_default_settings', 'my_debug_bar_extender_settings' );
// enforce debug bar settings
function my_debug_bar_extender_settings( $default_settings ) {
$default_settings = array(
'enable_profiler' => 1,
'enable_variable_lookup' => 1,
'track_default_vars' => 0,
'add_default_checkpoints' => 1,
'savequeries_debugmode_enable' => 1,
'use_error_log' => 0,
'allow_url_settings' => 1,
'enable_admin_bar_menu' => 1,
);
return $default_settings;
}

add_filter( 'debugbarextender_default_checkpoint_actions', 'my_debug_bar_extender_checkpoints' );
// initiate some default checkpoints
function my_debug_bar_extender_checkpoints( $default_checkpoints ) {
$default_checkpoints = array(
'muplugins_loaded',
'wp_head',
'wp_footer',
'loop_start',
'loop_end',
'shutdown',
);
return $default_checkpoints;
}

Wishlist
This is a work in progress, so feel free to pass by on our plugin page and leave us
your suggestions in the comments.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon