Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Commit 09c9c43

Browse files
committed
Initialization is now in scope of WP init action
+ added WP_TRACY_ENABLE_MODE and wp_tracy_panels_filter
1 parent b58da6e commit 09c9c43

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ When it's activated, it automatically shows Tracy bar and displays within global
77
## Installation
88

99
1. Use command on your path: composer require ktstudio/wp-tracy
10-
3. Profit!
11-
4. You can optionally define PHP boolean constant WP_TRACY_CHECK_USER_LOGGED_IN...
10+
2. Profit!
11+
3. You can optionally define PHP (boolean) constant WP_TRACY_CHECK_USER_LOGGED_IN to check only logged users...
12+
4. You can optionally define PHP constant WP_TRACY_ENABLE_MODE to set Tracy\Debugger::enable($mode)...
13+
5. You can optionally use wp_tracy_panels_filter to modify default panels array (full class names)
1214

1315
![WP Tracy](https://ktstudio.github.io/images/wp-tracy.png "Tracy bar auto-display after plugin activation")
1416
![WP Tracy exception](https://ktstudio.github.io/images/wp-tracy-exception.png "Tracy exception dialog when is occured")

src/index.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
<?php
22

3-
if (defined("DOING_AJAX") && DOING_AJAX) {
4-
return; // for IE compatibility WordPress media upload
5-
}
3+
add_action("init", "wp_tracy_init_action", 1);
64

7-
if (defined("WP_TRACY_CHECK_USER_LOGGED_IN") && WP_TRACY_CHECK_USER_LOGGED_IN && is_user_logged_in()) {
8-
return; // cancel for anonymous users
9-
}
5+
function wp_tracy_init_action() {
6+
if (defined("DOING_AJAX") && DOING_AJAX) {
7+
return; // for IE compatibility WordPress media upload
8+
}
109

11-
Tracy\Debugger::enable(); // hooray, enabling debugging using Tracy
10+
if (defined("WP_TRACY_CHECK_USER_LOGGED_IN") && WP_TRACY_CHECK_USER_LOGGED_IN && is_user_logged_in()) {
11+
return; // cancel for anonymous users
12+
}
1213

13-
// panels in the correct order
14-
$panels = array(
15-
"WpTracy\\WpPanel",
16-
"WpTracy\\WpUserPanel",
17-
"WpTracy\\WpPostPanel",
18-
"WpTracy\\WpQueryPanel",
19-
"WpTracy\\WpQueriedObjectPanel",
20-
"WpTracy\\WpDbPanel",
21-
"WpTracy\\WpRewritePanel",
22-
);
14+
Tracy\Debugger::enable(defined("WP_TRACY_ENABLE_MODE") ? WP_TRACY_ENABLE_MODE : null); // hooray, enabling debugging using Tracy
15+
// panels in the correct order
16+
$defaultPanels = array(
17+
"WpTracy\\WpPanel",
18+
"WpTracy\\WpUserPanel",
19+
"WpTracy\\WpPostPanel",
20+
"WpTracy\\WpQueryPanel",
21+
"WpTracy\\WpQueriedObjectPanel",
22+
"WpTracy\\WpDbPanel",
23+
"WpTracy\\WpRewritePanel",
24+
);
25+
$panels = apply_filters("wp_tracy_panels_filter", $defaultPanels);
2326

24-
// panels registration
25-
foreach ($panels as $className) {
26-
Tracy\Debugger::getBar()->addPanel(new $className);
27+
// panels registration
28+
foreach ($panels as $className) {
29+
Tracy\Debugger::getBar()->addPanel(new $className);
30+
}
2731
}

0 commit comments

Comments
 (0)