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

Commit 16b91d6

Browse files
committed
Better configuration & Tracy 2.5 update
+ brand change from the KTStudio only to the author
1 parent 09c9c43 commit 16b91d6

13 files changed

+193
-149
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea/
12
nbproject/
23
vendor/
34
composer.phar

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015, KTStudio
1+
Copyright (c) 2015,2018 Martin Hlaváč
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,34 @@
44
WP Tracy is port to [WordPress](https://wordpress.org) for test environment.
55
When it's activated, it automatically shows Tracy bar and displays within global WP constants and their values.
66

7-
## Installation
7+
## Installation & Configuration
88

9-
1. Use command on your path: composer require ktstudio/wp-tracy
9+
1. Use command on your path: `composer require hlavacm/wp-tracy`
1010
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)
11+
3. You can optionally define custom PHP constants in the code, but they must be defined in the action `init` with priority 1.
12+
3.1 WP_TRACY_ADMIN_DISABLED - `true`
13+
3.2 WP_TRACY_CHECK_IS_USER_LOGGED_IN - `on`/`off`
14+
3.3 WP_TRACY_ONLY_FOR_USER_ID - `some (existing) user ID (as a number)`
15+
3.4 WP_TRACY_ENABLE_MODE - `detect`/`development`/`production`
16+
3.5 WP_TRACY_PANELS_FILTERING_ALLOWED - `on`/`off`
17+
4. You can optionally define custom options `wp-tracy-user-settings` as serialized array of keys and values:
18+
4.1 `check-is-user-logged-in` => `on`/`off`
19+
4.2 `only-for-user-id` => some (existing) user ID (as number)
20+
4.3 `debugger-mode` => `detect`/`development`/`production`
21+
4.4 `panels-filtering-allowed` => `on`/`off`
22+
5. You can optionally use `wp_tracy_panels_filter` to modify default panels array (full class names)
23+
6. The following panels are visible by default (if they are available):
24+
6.1 `WpTracy\\WpPanel`
25+
6.2 `WpTracy\\WpUserPanel`
26+
6.3 `WpTracy\\WpPostPanel`
27+
6.4 `WpTracy\\WpQueryPanel`
28+
6.5 `WpTracy\\WpQueriedObjectPanel`
29+
6.6 `WpTracy\\WpDbPanel`
30+
6.8 `WpTracy\\WpRewritePanel`
1431

15-
![WP Tracy](https://ktstudio.github.io/images/wp-tracy.png "Tracy bar auto-display after plugin activation")
16-
![WP Tracy exception](https://ktstudio.github.io/images/wp-tracy-exception.png "Tracy exception dialog when is occured")
32+
![WP Tracy](https://hlavacm.github.io/images/wp-tracy.png "Tracy bar auto-display after plugin activation")
33+
![WP Tracy exception](https://hlavacm.github.io/images/wp-tracy-exception.png "Tracy exception dialog when is occured")
1734

1835
---
1936

20-
Copyright © KTStudio.cz 2015
37+
Copyright © [Martin Hlaváč](https://www.hlavacm.net) 2015-2018

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "ktstudio/wp-tracy",
2+
"name": "hlavacm/wp-tracy",
33
"description": "(Nette) Tracy connector for WordPress",
44
"keywords": ["tracy", "debugger", "wordpress"],
5-
"homepage": "https://github.com/ktstudio/wp-tracy",
5+
"homepage": "https://github.com/hlavacm/wp-tracy",
66
"license": "BSD-3-Clause",
77
"authors": [
88
{
99
"name": "Martin Hlaváč",
10-
"email": "[email protected]",
11-
"homepage": "http://www.ktstudio.cz/",
10+
"email": "[email protected]",
11+
"homepage": "https://www.hlavacm.net/",
1212
"role": "Developer"
1313
}
1414
],
1515
"require": {
1616
"php": ">=5.4.4",
17-
"tracy/tracy": "~2.4"
17+
"tracy/tracy": "~2.5"
1818
},
1919
"autoload": {
2020
"classmap": ["src/panels"],

src/index.php

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,79 @@
11
<?php
22

3-
add_action("init", "wp_tracy_init_action", 1);
3+
add_action("init", "wp_tracy_init_action", 2);
44

5-
function wp_tracy_init_action() {
5+
function wp_tracy_init_action()
6+
{
67
if (defined("DOING_AJAX") && DOING_AJAX) {
78
return; // for IE compatibility WordPress media upload
89
}
910

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-
}
13-
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(
11+
$defaultPanelsClasses = [
1712
"WpTracy\\WpPanel",
1813
"WpTracy\\WpUserPanel",
1914
"WpTracy\\WpPostPanel",
2015
"WpTracy\\WpQueryPanel",
2116
"WpTracy\\WpQueriedObjectPanel",
2217
"WpTracy\\WpDbPanel",
2318
"WpTracy\\WpRewritePanel",
24-
);
25-
$panels = apply_filters("wp_tracy_panels_filter", $defaultPanels);
19+
]; // in the correct order
20+
21+
$defaultSettings = [
22+
"check-is-user-logged-in" => defined("WP_TRACY_CHECK_IS_USER_LOGGED_IN") ? WP_TRACY_CHECK_IS_USER_LOGGED_IN : "off",
23+
"only-for-user-id" => defined("WP_TRACY_ONLY_FOR_USER_ID") ? WP_TRACY_ONLY_FOR_USER_ID : null,
24+
"debugger-mode" => defined("WP_TRACY_ENABLE_MODE") ? WP_TRACY_ENABLE_MODE : "detect",
25+
"panels-classes" => $defaultPanelsClasses,
26+
"panels-filtering-allowed" => defined("WP_TRACY_PANELS_FILTERING_ALLOWED") ? WP_TRACY_PANELS_FILTERING_ALLOWED : "on",
27+
];
28+
29+
$userSettings = get_option("wp-tracy-user-settings", []);
30+
31+
$settings = wp_parse_args($userSettings, $defaultSettings);
32+
33+
if ($settings["check-is-user-logged-in"] === "on") {
34+
$isUserLoggedIn = is_user_logged_in();
35+
if (!$isUserLoggedIn) {
36+
return; // cancel for anonymous users
37+
}
38+
$onlyForUserId = $settings["only-for-user-id"];
39+
if ($onlyForUserId > 0 && $onlyForUserId != get_current_user_id()) {
40+
return; // cancel other users
41+
}
42+
}
43+
44+
switch ($settings["debugger-mode"]) {
45+
case "development":
46+
$debugMode = Tracy\Debugger::DEVELOPMENT;
47+
break;
48+
case "production":
49+
$debugMode = Tracy\Debugger::PRODUCTION;
50+
break;
51+
default:
52+
$debugMode = Tracy\Debugger::DETECT;
53+
break;
54+
}
55+
Tracy\Debugger::enable($debugMode); // hooray, enabling debugging using Tracy
56+
57+
$panelsClasses = $settings["panels-classes"];
58+
if (!is_array($panelsClasses)) {
59+
trigger_error("\"wp-tracy-user-settings->panels-classes\" option must be type of array.", E_USER_WARNING);
60+
exit;
61+
}
62+
63+
// panels (custom) filtering
64+
if ($settings["panels-filtering-allowed"] === "on") {
65+
$panelsClasses = apply_filters("wp_tracy_panels_filter", $panelsClasses);
66+
if (!is_array($panelsClasses)) {
67+
trigger_error("\"wp_tracy_panels_filter\" must return type of array.", E_USER_WARNING);
68+
exit;
69+
}
70+
}
2671

2772
// panels registration
28-
foreach ($panels as $className) {
29-
Tracy\Debugger::getBar()->addPanel(new $className);
73+
foreach ($panelsClasses as $className) {
74+
$panel = new $className;
75+
if ($panel instanceof Tracy\IBarPanel) {
76+
Tracy\Debugger::getBar()->addPanel(new $className);
77+
}
3078
}
3179
}

src/panels/wpdbpanel.class.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44

55
/**
66
* Custom panel based on global $wpdb variable
7-
*
7+
*
88
* @author Martin Hlaváč
9-
* @link http://www.ktstudio.cz/
109
*/
11-
class WpDbPanel extends WpPanelBase {
12-
13-
public function getTab() {
10+
class WpDbPanel extends WpPanelBase
11+
{
12+
public function getTab()
13+
{
1414
return parent::getSimpleTab(__("DB"));
1515
}
1616

17-
public function getPanel() {
17+
public function getPanel()
18+
{
1819
/* @var $wpdb \WPDB */
1920
global $wpdb;
20-
$output = parent::getTablePanel(array(
21-
"Last Query" => $wpdb->last_query,
22-
"Func Call" => $wpdb->func_call,
23-
));
21+
$output = parent::getTablePanel([
22+
"Last Query" => $wpdb->last_query,
23+
]);
2424
$output .= parent::getObjectPanel($wpdb);
2525
return $output;
2626
}
27-
2827
}

src/panels/wppanel.class.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
/**
88
* Custom panel based on global $wp variable + other global (versions) variables
9-
*
9+
*
1010
* @author Martin Hlaváč
11-
* @link http://www.ktstudio.cz/
1211
*/
13-
class WpPanel extends WpPanelBase {
14-
15-
public function getTab() {
16-
return parent::getSimpleTab(__("WP"), null, "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABtUlEQVR42nXTXyjdYRzH8XN0TqZ2oUV2pDXadKwVyR3TtHGlhBuJ3BjGKIq4UBZtDZ3ajb8XUv7kjuGKFEVpKf9KmlxQRgm1FJua97c+v/pp89Src3p+3+f7PL/v8/15Pf+OVKTjj9jwwY/vWHUHe13/H6AaO4hDHhL17AemsY9k9ODSncAWN2IZg0jw/H8coAyvELIkToJ6rOMbHnruHxMoRjg+oMsSvEQsDhGDfAW1Ygt/8RYf0aZfj+Z+WYIa7GIBYfiJKFwjgHOsqbhHCNpClCDSElTiDQYwrxqUa5cq9KMZnzXXgCGMYcoSVOA9NlUgO9qcgi1htoq6p6KPYAbt+OIkqNSVPcaVXiMaX9GBU/VAGrrxHEnodF7hNYpQqh36NF+HRypck+2IQh3fTjnrVfNcYFSTOarJMMZ1K88Qr1O0qF7vEOFVVYM6qv0+wbECrZhP1dorqEWuElofnDiNZEfdwCQ+WYMgE4t63q8bCajVC5Bi3egk8OuqlnQjRSpgnZ6faXEWfiNDm1y5Pya/Fh+opUPqeYuxj6lRlX+BXt3Wna/RGUEV8UZt7MT59Erb7uBbAThl6Btg2vYAAAAASUVORK5CYII=");
12+
class WpPanel extends WpPanelBase
13+
{
14+
public function getTab()
15+
{
16+
return parent::getSimpleTab(__("WP"), null, "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfiCQkLEyXB/kfmAAABbklEQVQozz3RPUjUcQCA4ef/Oy89yCO7LA61oVsqOKzLoMUCU3NosJCG3BpqC8KltraWiqMpaJKWimgo+vCOK7jQ6OOwpYQEG0yTSJLI6zK9Goz2l3d5IuinUZ8h7eoIPrmr6FcBUT+kjUh5oOIbWuxz1Bd5C+tB2iWTbqhSWP/R6rq40xZimQ0uWnJTJKYtk8gkpXw3YERWo1KDw4b91OWyGWf1+e2WvLgmDHocHDepw2YV065J2GnKsqIJdW8cC7bLm7NbDjOeaTAgsmhU1SMdQeSV55ocwZoSDmrDtPfGhYCa+/7o0YptqnY4gK3GzYuCIKXsg11ymm1yW9yASKenmoVgVpd5RY16Zc0ZVdWt0xYv7Tcby9QNKqg5IWlN2Vs9slbNmXDOvWDMojMqJu2R9c6yh+KGvHbKorFgxVV7DSvjhR944qslh+RcsRIw77x23ZZM2Sip5qMWCRd8JvrP3euktNV/3HeU1rn/Av+FclJF48KxAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTA5LTA5VDExOjE5OjM3LTA3OjAwvabE/AAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0wOS0wOVQxMToxOTozNy0wNzowMMz7fEAAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAAAElFTkSuQmCC");
1717
}
1818

19-
public function getPanel() {
19+
public function getPanel()
20+
{
2021
/* @var $wpdb \WP */
2122
global $wp;
2223
global $wp_version;
@@ -25,16 +26,15 @@ public function getPanel() {
2526
global $required_php_version;
2627
global $required_mysql_version;
2728
global $pagenow;
28-
$output = parent::getTablePanel(array(
29-
__("WP Version") => $wp_version,
30-
__("WP DB Version ") => $wp_db_version,
31-
__("TinyMCE Version ") => $tinymce_version,
32-
__("Required PHP Version") => $required_php_version,
33-
__("Required MySQL Version") => $required_mysql_version,
34-
__("Page Now") => $pagenow,
35-
__("WP") => Debugger::dump($wp, true),
36-
));
29+
$output = parent::getTablePanel([
30+
__("WP Version") => $wp_version,
31+
__("WP DB Version ") => $wp_db_version,
32+
__("TinyMCE Version ") => $tinymce_version,
33+
__("Required PHP Version") => $required_php_version,
34+
__("Required MySQL Version") => $required_mysql_version,
35+
__("Page Now") => $pagenow,
36+
__("WP") => Debugger::dump($wp, true),
37+
]);
3738
return $output;
3839
}
39-
4040
}

src/panels/wppanelbase.class.php

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,31 @@
22

33
namespace WpTracy;
44

5-
use Tracy,
6-
Tracy\IBarPanel,
7-
Tracy\Dumper;
5+
use Tracy\Dumper;
6+
use Tracy\IBarPanel;
87

98
/**
10-
* Common basic model for other WP panels
11-
*
9+
* Common basic model for other WP panels
10+
*
1211
* @author Martin Hlaváč
13-
* @link http://www.ktstudio.cz/
1412
*/
15-
abstract class WpPanelBase implements IBarPanel {
16-
13+
abstract class WpPanelBase implements IBarPanel
14+
{
1715
/**
1816
* (HTML) content of tab for panel
19-
*
20-
* @author Martin Hlaváč
21-
* @link http://www.ktstudio.cz/
22-
*
17+
*
2318
* @param string $title
2419
* @param string $description
2520
* @param string $imageBase64
2621
* @return string
2722
*/
28-
public function getSimpleTab($title = null, $description = null, $imageBase64 = null) {
29-
$output = "<span" . (self::issetAndNotEmpty($description) ? " title=\"$description\"" : "") . ">";
30-
if (self::issetAndNotEmpty($imageBase64)) {
31-
$output .= "<img src=\"data:image/png;base64,$imageBase64\" /> ";
23+
public function getSimpleTab($title = null, $description = null, $imageBase64 = null)
24+
{
25+
$output = "<span" . (!empty($description) ? " title=\"$description\"" : "") . ">";
26+
if (!empty($imageBase64)) {
27+
$output .= "<img src=\"data:image/png;base64,$imageBase64\" width=\"16\" height=\"16\" /> ";
3228
}
33-
if (self::issetAndNotEmpty($title)) {
29+
if (!empty($title)) {
3430
$output .= $title;
3531
}
3632
$output .= "</span>";
@@ -39,17 +35,15 @@ public function getSimpleTab($title = null, $description = null, $imageBase64 =
3935

4036
/**
4137
* (HTML) table content of panel based on parameters array
42-
*
43-
* @author Martin Hlaváč
44-
* @link http://www.ktstudio.cz/
45-
*
38+
*
4639
* @param array $params
4740
* @param string $title
4841
* @return string
4942
*/
50-
public function getTablePanel(array $params, $title = null) {
43+
public function getTablePanel(array $params, $title = null)
44+
{
5145
$output = null;
52-
if (self::issetAndNotEmpty($title)) {
46+
if (!empty($title)) {
5347
$output .= "<h1>$title</h1>";
5448
}
5549
$output .= "<div class=\"nette-inner\">";
@@ -72,37 +66,21 @@ public function getTablePanel(array $params, $title = null) {
7266
}
7367

7468
/**
75-
* (HTML) content of panel based on object
76-
*
77-
* @author Martin Hlaváč
78-
* @link http://www.ktstudio.cz/
79-
*
69+
* (HTML) content of panel based on object
70+
*
8071
* @param mixed $object
8172
* @param string $title
8273
* @return string
8374
*/
84-
public function getObjectPanel($object, $title = null) {
75+
public function getObjectPanel($object, $title = null)
76+
{
8577
$output = null;
86-
if (self::issetAndNotEmpty($title)) {
78+
if (!empty($title)) {
8779
$output .= "<h1>$title</h1>";
8880
}
8981
$output .= "<div class=\"nette-inner\">";
90-
$output .= Dumper::toHtml($object, array(Dumper::COLLAPSE => false));
82+
$output .= Dumper::toHtml($object, [Dumper::COLLAPSE => false]);
9183
$output .= "</div>";
9284
return $output;
9385
}
94-
95-
/**
96-
* Check if the value is assigned and if it's not empty
97-
*
98-
* @author Martin Hlaváč
99-
* @link http://www.ktstudio.cz/
100-
*
101-
* @param mixed $value
102-
* @return boolean
103-
*/
104-
public static function issetAndNotEmpty($value) {
105-
return isset($value) && !empty($value);
106-
}
107-
10886
}

0 commit comments

Comments
 (0)