[WordPress] 外掛分享: WP Log in Browser

WordPress 外掛 WP Log in Browser 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「WP Log in Browser」是 2012-12-16 上架。 目前已經下架不再更新,不建議安裝使用。
  • 目前有 10 個安裝啟用數。
  • 上一次更新是 2012-12-17,距離現在已有 4520 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.4 以上版本才可以安裝。
  • 尚未有人給過這款外掛評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

mzaweb |

外掛標籤

debug | console | develop |

內容簡介

我們正在開發一個好的管理畫面,可以設定常見事項(例如 wp_query in pre_get_posts 和 wp)的自動記錄,還有一些附加功能。

您也可以手動記錄一些事項:

browser()->log ( $var, $label );
browser()->warn ( $var, $label );
browser()->info ( $var, $label );
browser()->error( $var, $label );

而且命令是可鏈接的:

browser()->log( 'This is a log...' )->error( '...and this is an error' );

例如,要記錄主要查詢 main query 的 query_vars:

add_filter( 'pre_get_posts', 'log_wp_query', 10000 );

function log_wp_query( $query ) {
if ( $query->is_main_query() )
browser()->log( $query->query_vars, 'pre_get_posts' );

return $query;
}

篩選

wplinb-match-wp-debug:當 wp_debug 為 true 時,設置為 true 以記錄。 防止在 wp_debug 為 false 時記錄:

add_filter( 'wplinb-match-wp-debug', '__return_true' );

wplinb-enabled:完全禁用記錄。 它優先於 wplinb-match-wp-debug,要禁用記錄:

add_filter( 'wplinb-enabled', '__return_false' );

分析

該外掛包含一個非常簡單的功能,讓您可以跟踪代碼的不同部分的執行時間。

browser()->timer( $key, $log = false );

第一次使用具有給定 $key(字符串)的該函數將啟動計時器並返回 false。您可以使用不同的 $key 值開始任意多個計時器。對於該第一次調用,您可以忽略第二個參數。

第二次使用具有給定 $key 的該函數將返回自您啟動此 $key 計時器以來的過去時間(以秒為單位)。如果您將第二個參數設置為 true,它還會將此值記錄到瀏覽器。

範例1:依序使用,手動記錄。

browser()->timer( 'Mega loop' );
for ( $i = 0; $i < 1000000; $i++ ) {
//do something
}
$time = browser()->timer( 'Mega loop' );
browser()->log( $time, 'The mega loop took:' );

範例2:在不同的地方開始和結束,自動記錄。

add_action( 'posts_selection', 'start_timer', 100 );
add_filter( 'the_posts', 'end_timer', 1, 2 );

function start_timer( $query ) {
browser()->timer( 'Main query time' );
}

function end_timer( $posts, $query ) {
browser()->timer( 'Main query time', true );
return $posts;
}

這不是測量查詢運行時間的好方法,只是演示如何使用計時器。

以完全相同的方式,您可以使用函數

Browser()->memory( $key, $log = false );

測量從您的第一次調用和第二次具有相同 $key 的增量記憶體消耗。

範例:

Browser()->memory( 'testing' );
$test = array();
for ( $i = 0; $i < 100; $i++ ) {
$test[$i] = md5( rand( 1, $i ) );
}
Browser()->memory( 'testing', true );

Browser()->memory( 'testing' );
$test = array();
for ( $i = 0; $i < 10000; $i++ ) {
$test[$i] = md5( rand( 1, $i ) );
}
Browser()->memory( 'testing', true );

原文外掛簡介

I’m working on a nice admin screen to config auto-logging of some common things (like wp_query in pre_get_posts and wp), and some other goodies.
To log things manually, you can use:
browser()->log ( $var, $label );
browser()->warn ( $var, $label );
browser()->info ( $var, $label );
browser()->error( $var, $label );

Also, commandas are chainable:
browser()->log( 'This is a log...' )->error( '...and this is an error' );

For example, to log all your main query’s query_vars:
add_filter( 'pre_get_posts', 'log_wp_query', 10000 );

function log_wp_query( $query ) {
if ( $query->is_main_query() )
browser()->log( $query->query_vars, 'pre_get_posts' );

return $query;
}

Filters
wplinb-match-wp-debug: Set to true to only log when wp_debug is true. To prevent logging when wp_debug is false:
add_filter( 'wplinb-match-wp-debug', '__return_true' );

wplinb-enabled: To disable logging completely. It takes precedence over wplinb-match-wp-debug. To disable logging:
add_filter( 'wplinb-enabled', '__return_false' );

Profiling
The plugin includes a really simple function to allow you to track execution time of different parts of your code.
browser()->timer( $key, $log = false );

The first time you call this function with a given $key (string) it will start a timer, and return false. You can start as many timers as you want, using different $key values. You can ignore the second parameter for this first call.
The second time you call this function with a given $key, it will return the ellapsed time in seconds since you started this $key timer. If you set the second parameter to true, it will also log this value to the browser.
Example 1: Sequential use, log manually.
browser()->timer( 'Mega loop' );
for ( $i = 0; $i timer( 'Mega loop' );
browser()->log( $time, 'The mega loop took:' );

Example 2: Start and end in different places, log automatically.
add_action( 'posts_selection', 'start_timer', 100 );
add_filter( 'the_posts', 'end_timer', 1, 2 );

function start_timer( $query ) {
browser()->timer( 'Main query time' );
}

function end_timer( $posts, $query ) {
browser()->timer( 'Main query time', true );
return $posts;
}

This is not a good way of measuring how much time a query takes to run, it’s just to illustrate how to use the timer.
In exactly the same way, you can use the function
Browser()->memory( $key, $log = false );

to measure delta of memory consumption from your first call and your second call with the same $key.
Example:
Browser()->memory( 'testing' );
$test = array();
for ( $i = 0; $i memory( 'testing', true );

Browser()->memory( 'testing' );
$test = array();
for ( $i = 0; $i memory( 'testing', true );

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WP Log in Browser」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.1.2 | trunk |

延伸相關外掛(你可能也想知道)

  • reBusted! 》這個外掛可以免去你問「你有清空快取嗎?」的問題。, 這是根據原本由 Paul Clark 開發的外掛更新,以符合今天的 WordPress 和 PHP。, 功能, , 在線上網站上安...。
  • WP Logger 》這是一個用來除錯網站和應用程式的日誌變數和事件。, , 在您的代碼中插入 do_action( ‘logger’, $data ); hook, 到工具 > 日誌, , 可用的其他 ho...。
  • Shortcodes Generator 》在視覺化編輯器中添加短代码可能會很麻煩,但現在不用了。, 現在,您只需使用陣列和此外掛,便可將短代码和按鈕簡單添加到編輯器中。多棒啊!, 您可以查看更...。
  • Prime Timeline 》此外掛可分析 WordPress 的執行狀態,以進行除錯、效能檢查以及學習。, 顯示所有鉤子、所有查詢、所有載入的檔案,以及一些有關目前請求的資訊。, 相關連結, ...。
  • Site Renamer 》你在本地安裝了 WordPress (例如: localhost/blogs),用於開發和測試所有你的佈景主題。啟用此外掛後,每當你切換佈景主題時,網站名稱(blogname)選項將...。
  • Checking Variables (Dev. Tool) 》您是一位 WordPress 開發人員嗎?只需要檢查變數的值即可。您可以在 Query Monitor 結果中或獨立使用此外掛。, 使用方式, , 使用 console( $var [, $var [, $...。
  • hiWeb Core 》這個外掛讓 WordPress 網站創作者可以快速且容易地加入所有常見的功能,例如控制選單、小工具來自訂管理面板,以及更方便簡單地刪除或重新命名選單項目。, 讓...。
  • Code To Post 》⚠️ 此外掛正在開發中, 此外掛將從靜態 HTML 檔案更新或建立文章。, 它適用於開發。, 運作方式:, , 在您的伺服器上建立基本目錄。, 在基本目錄中以"文章類型...。
  • Add Page From Template 》你是否厭倦了在不同的環境創建頁面?, , 自動從 PHP 模板檔案添加 WordPress 虛擬「頁面」。, , 不需要從管理員面板中添加「頁面」。, page-xxx.php 應位於 &...。
  • Try theme to develop 》如果您有「edit_themes」的能力,您可以在「Design」菜單中看到一個新的選項「Try Theme」。, 在這個頁面中,您可以看到一個表單,讓您選擇一個主題,在您登...。
  • Reloadr for WordPress 》此外掛基於「Reloadr」,可以監視網站專案的檔案變更,並自動重新整理其頁面。這對於客戶端資源(例如 *.css、*.js 等等)和伺服器端資源(例如 *.php)非常有用...。
  • Mountee 》使用您喜愛的工具, 每個人都有自己喜歡的 Mac 應用程式,那為什麼要被限制在 WordPress 瀏覽器視窗內創建模板呢?Mountee 讓您可以將模板作為 Finder 檔案進...。
  • Hilp – WordPress support 》世界瞬息萬變,WordPress外掛也一樣!, 遇到瓶頸了嗎?或許你遇到了自己無法解決的問題。也許你能解決,但時間不夠用?, 透過 Hilp,您只需簡單幾個點擊,輕...。
  • Basic Developer Tools 》Developer Tools 目前僅支援變數、錯誤和例外情況的記錄。尚不支援分析網站資料庫查詢和伺服器記憶體使用等功能。, 功能, , 記錄任何類型的變數, 記錄任何可...。
  • All-in-One Debug Lab 》這款「All-in-One Debug Lab」外掛可輕鬆協助搜尋並定位 WordPress 中的錯誤。, 查看「debug.log」檔案, 透過此外掛,您可以查看「debug.log」檔案。, 切換偵...。

文章
Filter
Apply Filters
Mastodon