Skip to content

Commit 002b7df

Browse files
committed
Many improvements and fixes.
1 parent 4393ee6 commit 002b7df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1037
-644
lines changed

core/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Replacement function for rendering plugin settings sections. Based on the WordPress core do_settings_sections(), but
99
* expanded to add additional layout elements.
1010
*
11-
* @param string $page the slug name of the page whose settings sections you want to output
11+
* @param string $page the slug name of the page whose settings section you want to output
1212
*
1313
* @see \do_settings_sections()
1414
*

core/admin/Plugin.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function __construct() {
2626
add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 2 );
2727
}
2828

29-
/** @return \Dev4Press\Plugin\DebugPress\Admin\Plugin */
3029
public static function instance() : Plugin {
3130
static $instance = null;
3231

core/admin/Settings.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public function __construct() {
1111

1212
}
1313

14-
/** @return \Dev4Press\Plugin\DebugPress\Admin\Settings */
15-
public static function instance() {
14+
public static function instance() : Settings {
1615
static $instance = null;
1716

1817
if ( ! isset( $instance ) ) {

core/display/Loader.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@ class Loader {
1515
public function __construct() {
1616
$this->position = is_admin() ? debugpress_plugin()->get( 'button_admin' ) : debugpress_plugin()->get( 'button_frontend' );
1717

18+
if ( $this->position == 'toolbar' ) {
19+
add_action( 'admin_bar_menu', array( $this, 'display_in_toolbar' ), 1000000 );
20+
}
21+
1822
if ( is_admin() ) {
1923
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
2024
} else {
2125
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
26+
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
2227
}
2328

2429
SQLFormat::$pre_attributes = '';
30+
}
2531

26-
if ( $this->position == 'toolbar' ) {
27-
add_action( 'admin_bar_menu', array( $this, 'display_in_toolbar' ), 1000000 );
28-
}
29-
32+
public function run() {
3033
if ( is_admin() ) {
3134
add_action( 'admin_footer', array( $this, 'debugger_content_prepare' ) );
3235
} else {
3336
add_action( 'wp_footer', array( $this, 'debugger_content_prepare' ) );
37+
add_action( 'login_footer', array( $this, 'debugger_content_prepare' ) );
3438
}
3539
}
3640

@@ -42,7 +46,7 @@ public function debugger_content_prepare() {
4246
add_action( 'shutdown', array( $this, 'debugger_content' ), 1000000 );
4347
}
4448

45-
public static function instance() {
49+
public static function instance() : Loader {
4650
static $instance = null;
4751

4852
if ( ! isset( $instance ) ) {
@@ -257,4 +261,4 @@ private function vars_styling_override() : string {
257261
return '';
258262
}
259263
}
260-
}
264+
}

core/main/AJAX.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public function __construct() {
1414
add_action( 'wp_ajax_nopriv_debugpress_load_debuglog', array( $this, 'load_debuglog' ) );
1515
}
1616

17-
/** @return \Dev4Press\Plugin\DebugPress\Main\AJAX */
1817
public static function instance() : AJAX {
1918
static $instance = null;
2019

core/main/DB.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public function __construct() {
1616

1717
}
1818

19-
/** @return \Dev4Press\Plugin\DebugPress\Main\DB */
2019
public static function instance() : DB {
2120
static $instance = null;
2221

core/main/Files.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public function __construct() {
1414

1515
}
1616

17-
/** @return \Dev4Press\Plugin\DebugPress\Main\Files */
1817
public static function instance() : Files {
1918
static $instance = null;
2019

core/main/OPCache.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public function __construct() {
1818

1919
}
2020

21-
/** @return \Dev4Press\Plugin\DebugPress\Main\OPCache */
2221
public static function instance() : OPCache {
2322
static $instance = null;
2423

core/main/Plugin.php

Lines changed: 96 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Plugin {
1313
private $_settings = array();
1414
private $_defaults = array(
15-
'pr' => 'prettyprint',
15+
'pr' => 'kint',
1616
'active' => false,
1717
'admin' => false,
1818
'frontend' => false,
@@ -55,12 +55,12 @@ class Plugin {
5555
private $_wp_version_real;
5656
private $_cp_version;
5757
private $_cp_version_real;
58+
private $_rest_request = false;
5859

5960
public function __construct() {
6061

6162
}
6263

63-
/** @return \Dev4Press\Plugin\DebugPress\Main\Plugin */
6464
public static function instance() : Plugin {
6565
static $instance = null;
6666

@@ -73,9 +73,25 @@ public static function instance() : Plugin {
7373
}
7474

7575
private function run() {
76+
add_action( 'rest_api_init', array( $this, 'rest_api' ) );
7677
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 0 );
7778
add_action( 'plugins_loaded', array( $this, 'activation' ), DEBUGPRESS_ACTIVATION_PRIORITY );
7879
add_action( 'init', array( $this, 'init' ) );
80+
81+
if ( is_admin() ) {
82+
add_action( 'admin_enqueue_scripts', array( $this, 'loader' ) );
83+
} else {
84+
add_action( 'wp', array( $this, 'loader' ) );
85+
add_action( 'login_init', array( $this, 'loader' ) );
86+
}
87+
}
88+
89+
public function rest_api() {
90+
$this->_rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
91+
}
92+
93+
public function is_rest_request() : bool {
94+
return $this->_rest_request;
7995
}
8096

8197
public function wp_version() : string {
@@ -126,49 +142,21 @@ public function activation() {
126142
debugpress_tracker();
127143
}
128144

129-
private function load_printer( $name = '' ) {
130-
if ( ! function_exists( 'debugpress_r' ) ) {
131-
$name = empty( $name ) ? $this->get( 'pr' ) : 'prettyprint';
132-
$path = DEBUGPRESS_PLUGIN_PATH . 'core/printer/' . $name . '/load.php';
133-
134-
if ( file_exists( $path ) ) {
135-
require_once( $path );
136-
} else {
137-
$this->load_printer( 'prettyprint' );
138-
}
139-
}
140-
}
141-
142-
private function define_constants() {
143-
if ( $this->get( 'auto_wpdebug' ) && ! defined( 'WP_DEBUG' ) ) {
144-
define( 'WP_DEBUG', true );
145-
}
146-
147-
if ( $this->get( 'auto_savequeries' ) && ! defined( 'SAVEQUERIES' ) ) {
148-
define( 'SAVEQUERIES', true );
149-
}
150-
151-
define( 'DEBUGPRESS_IS_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG );
152-
define( 'DEBUGPRESS_IS_DEBUG_LOG', DEBUGPRESS_IS_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG );
153-
154-
$version = str_replace( '.', '', phpversion() );
155-
$version = intval( substr( $version, 0, 2 ) );
156-
157-
define( 'DEBUGPRESS_PHP_VERSION', $version );
158-
}
159-
160145
public function init() {
161146
wp_register_style( 'animated-popup', DEBUGPRESS_PLUGIN_URL . 'popup/popup.min.css', array(), $this->_animated_popup_version );
147+
wp_register_style( 'debugpress-print', DEBUGPRESS_PLUGIN_URL . 'css/prettyprint' . ( DEBUGPRESS_IS_DEBUG ? '' : '.min' ) . '.css', array(), DEBUGPRESS_VERSION );
162148
wp_register_style( 'debugpress', DEBUGPRESS_PLUGIN_URL . 'css/debugpress' . ( DEBUGPRESS_IS_DEBUG ? '' : '.min' ) . '.css', array( 'animated-popup' ), DEBUGPRESS_VERSION );
163149
wp_register_script( 'animated-popup', DEBUGPRESS_PLUGIN_URL . 'popup/popup.min.js', array( 'jquery' ), $this->_animated_popup_version, true );
164150
wp_register_script( 'debugpress', DEBUGPRESS_PLUGIN_URL . 'js/debugpress' . ( DEBUGPRESS_IS_DEBUG ? '' : '.min' ) . '.js', array( 'animated-popup' ), DEBUGPRESS_VERSION, true );
165151

166-
if ( ! DEBUGPRESS_IS_AJAX && ! DEBUGPRESS_IS_CRON && $this->_allowed ) {
167-
$allowed = is_admin() ? $this->get( 'admin' ) : $this->get( 'frontend' );
152+
if ( is_admin() ? $this->get( 'admin' ) : $this->get( 'frontend' ) ) {
153+
Loader::instance();
154+
}
155+
}
168156

169-
if ( $allowed ) {
170-
Loader::instance();
171-
}
157+
public function loader() {
158+
if ( ! $this->is_rest_request() && ! DEBUGPRESS_IS_AJAX && ! DEBUGPRESS_IS_CRON && $this->_allowed ) {
159+
Loader::instance()->run();
172160
}
173161
}
174162

@@ -215,32 +203,6 @@ public function process_settings( $input ) : array {
215203
return $settings;
216204
}
217205

218-
private function is_user_allowed() : bool {
219-
if ( is_super_admin() ) {
220-
return $this->get( 'for_super_admin' );
221-
} else if ( is_user_logged_in() ) {
222-
$allowed = $this->get( 'for_roles' );
223-
224-
if ( $allowed === true || is_null( $allowed ) ) {
225-
return true;
226-
} else if ( is_array( $allowed ) && empty( $allowed ) ) {
227-
return false;
228-
} else if ( is_array( $allowed ) && ! empty( $allowed ) ) {
229-
global $current_user;
230-
231-
if ( is_array( $current_user->roles ) ) {
232-
$matched = array_intersect( $current_user->roles, $allowed );
233-
234-
return ! empty( $matched );
235-
}
236-
}
237-
} else {
238-
return $this->get( 'for_visitor' );
239-
}
240-
241-
return false;
242-
}
243-
244206
public function environment() : array {
245207
$env = array();
246208

@@ -292,4 +254,74 @@ public function build_stats( $key = 'wp_footer' ) : string {
292254

293255
return $gd;
294256
}
257+
258+
public function enqueue_print_style() {
259+
wp_enqueue_style( 'debugpress-print' );
260+
}
261+
262+
private function is_user_allowed() : bool {
263+
if ( is_super_admin() ) {
264+
return $this->get( 'for_super_admin' );
265+
} else if ( is_user_logged_in() ) {
266+
$allowed = $this->get( 'for_roles' );
267+
268+
if ( $allowed === true || is_null( $allowed ) ) {
269+
return true;
270+
} else if ( is_array( $allowed ) && empty( $allowed ) ) {
271+
return false;
272+
} else if ( is_array( $allowed ) && ! empty( $allowed ) ) {
273+
global $current_user;
274+
275+
if ( is_array( $current_user->roles ) ) {
276+
$matched = array_intersect( $current_user->roles, $allowed );
277+
278+
return ! empty( $matched );
279+
}
280+
}
281+
} else {
282+
return $this->get( 'for_visitor' );
283+
}
284+
285+
return false;
286+
}
287+
288+
private function load_printer( $name = '' ) {
289+
if ( ! function_exists( 'debugpress_r' ) ) {
290+
$name = empty( $name ) ? $this->get( 'pr' ) : 'prettyprint';
291+
$path = DEBUGPRESS_PLUGIN_PATH . 'core/printer/' . $name . '/load.php';
292+
293+
if ( $name == 'prettyprint' ) {
294+
if ( is_admin() ) {
295+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_print_style' ) );
296+
} else {
297+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_print_style' ) );
298+
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_print_style' ) );
299+
}
300+
}
301+
302+
if ( file_exists( $path ) ) {
303+
require_once( $path );
304+
} else {
305+
$this->load_printer( 'prettyprint' );
306+
}
307+
}
308+
}
309+
310+
private function define_constants() {
311+
if ( $this->get( 'auto_wpdebug' ) && ! defined( 'WP_DEBUG' ) ) {
312+
define( 'WP_DEBUG', true );
313+
}
314+
315+
if ( $this->get( 'auto_savequeries' ) && ! defined( 'SAVEQUERIES' ) ) {
316+
define( 'SAVEQUERIES', true );
317+
}
318+
319+
define( 'DEBUGPRESS_IS_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG );
320+
define( 'DEBUGPRESS_IS_DEBUG_LOG', DEBUGPRESS_IS_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG );
321+
322+
$version = str_replace( '.', '', phpversion() );
323+
$version = intval( substr( $version, 0, 2 ) );
324+
325+
define( 'DEBUGPRESS_PHP_VERSION', $version );
326+
}
295327
}

core/main/Scope.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function __construct() {
4545
}
4646
}
4747

48-
/** @return \Dev4Press\Plugin\DebugPress\Main\Scope */
4948
public static function instance() : Scope {
5049
static $instance = null;
5150

core/main/WP.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public function __construct() {
1111

1212
}
1313

14-
/** @return \Dev4Press\Plugin\DebugPress\Main\WP */
1514
public static function instance() : WP {
1615
static $instance = null;
1716

core/printer/kint/autoload.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
// autoload.php @generated by Composer
44

5+
if (PHP_VERSION_ID < 50600) {
6+
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
7+
exit(1);
8+
}
9+
510
require_once __DIR__ . '/composer/autoload_real.php';
611

7-
return ComposerAutoloaderInitca51731135e08eb5dc8e6d831f11e177::getLoader();
12+
return ComposerAutoloaderInita9b110c47c3d098ebab405be63c84a1e::getLoader();

0 commit comments

Comments
 (0)