Skip to content

Commit

Permalink
Many improvements and fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dev4press committed Aug 31, 2022
1 parent 4393ee6 commit 002b7df
Show file tree
Hide file tree
Showing 45 changed files with 1,037 additions and 644 deletions.
2 changes: 1 addition & 1 deletion core/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Replacement function for rendering plugin settings sections. Based on the WordPress core do_settings_sections(), but
* expanded to add additional layout elements.
*
* @param string $page the slug name of the page whose settings sections you want to output
* @param string $page the slug name of the page whose settings section you want to output
*
* @see \do_settings_sections()
*
Expand Down
1 change: 0 additions & 1 deletion core/admin/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function __construct() {
add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 2 );
}

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

Expand Down
3 changes: 1 addition & 2 deletions core/admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public function __construct() {

}

/** @return \Dev4Press\Plugin\DebugPress\Admin\Settings */
public static function instance() {
public static function instance() : Settings {
static $instance = null;

if ( ! isset( $instance ) ) {
Expand Down
16 changes: 10 additions & 6 deletions core/display/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ class Loader {
public function __construct() {
$this->position = is_admin() ? debugpress_plugin()->get( 'button_admin' ) : debugpress_plugin()->get( 'button_frontend' );

if ( $this->position == 'toolbar' ) {
add_action( 'admin_bar_menu', array( $this, 'display_in_toolbar' ), 1000000 );
}

if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
} else {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}

SQLFormat::$pre_attributes = '';
}

if ( $this->position == 'toolbar' ) {
add_action( 'admin_bar_menu', array( $this, 'display_in_toolbar' ), 1000000 );
}

public function run() {
if ( is_admin() ) {
add_action( 'admin_footer', array( $this, 'debugger_content_prepare' ) );
} else {
add_action( 'wp_footer', array( $this, 'debugger_content_prepare' ) );
add_action( 'login_footer', array( $this, 'debugger_content_prepare' ) );
}
}

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

public static function instance() {
public static function instance() : Loader {
static $instance = null;

if ( ! isset( $instance ) ) {
Expand Down Expand Up @@ -257,4 +261,4 @@ private function vars_styling_override() : string {
return '';
}
}
}
}
1 change: 0 additions & 1 deletion core/main/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public function __construct() {
add_action( 'wp_ajax_nopriv_debugpress_load_debuglog', array( $this, 'load_debuglog' ) );
}

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

Expand Down
1 change: 0 additions & 1 deletion core/main/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public function __construct() {

}

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

Expand Down
1 change: 0 additions & 1 deletion core/main/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public function __construct() {

}

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

Expand Down
1 change: 0 additions & 1 deletion core/main/OPCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function __construct() {

}

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

Expand Down
160 changes: 96 additions & 64 deletions core/main/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Plugin {
private $_settings = array();
private $_defaults = array(
'pr' => 'prettyprint',
'pr' => 'kint',
'active' => false,
'admin' => false,
'frontend' => false,
Expand Down Expand Up @@ -55,12 +55,12 @@ class Plugin {
private $_wp_version_real;
private $_cp_version;
private $_cp_version_real;
private $_rest_request = false;

public function __construct() {

}

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

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

private function run() {
add_action( 'rest_api_init', array( $this, 'rest_api' ) );
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 0 );
add_action( 'plugins_loaded', array( $this, 'activation' ), DEBUGPRESS_ACTIVATION_PRIORITY );
add_action( 'init', array( $this, 'init' ) );

if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', array( $this, 'loader' ) );
} else {
add_action( 'wp', array( $this, 'loader' ) );
add_action( 'login_init', array( $this, 'loader' ) );
}
}

public function rest_api() {
$this->_rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
}

public function is_rest_request() : bool {
return $this->_rest_request;
}

public function wp_version() : string {
Expand Down Expand Up @@ -126,49 +142,21 @@ public function activation() {
debugpress_tracker();
}

private function load_printer( $name = '' ) {
if ( ! function_exists( 'debugpress_r' ) ) {
$name = empty( $name ) ? $this->get( 'pr' ) : 'prettyprint';
$path = DEBUGPRESS_PLUGIN_PATH . 'core/printer/' . $name . '/load.php';

if ( file_exists( $path ) ) {
require_once( $path );
} else {
$this->load_printer( 'prettyprint' );
}
}
}

private function define_constants() {
if ( $this->get( 'auto_wpdebug' ) && ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', true );
}

if ( $this->get( 'auto_savequeries' ) && ! defined( 'SAVEQUERIES' ) ) {
define( 'SAVEQUERIES', true );
}

define( 'DEBUGPRESS_IS_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG );
define( 'DEBUGPRESS_IS_DEBUG_LOG', DEBUGPRESS_IS_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG );

$version = str_replace( '.', '', phpversion() );
$version = intval( substr( $version, 0, 2 ) );

define( 'DEBUGPRESS_PHP_VERSION', $version );
}

public function init() {
wp_register_style( 'animated-popup', DEBUGPRESS_PLUGIN_URL . 'popup/popup.min.css', array(), $this->_animated_popup_version );
wp_register_style( 'debugpress-print', DEBUGPRESS_PLUGIN_URL . 'css/prettyprint' . ( DEBUGPRESS_IS_DEBUG ? '' : '.min' ) . '.css', array(), DEBUGPRESS_VERSION );
wp_register_style( 'debugpress', DEBUGPRESS_PLUGIN_URL . 'css/debugpress' . ( DEBUGPRESS_IS_DEBUG ? '' : '.min' ) . '.css', array( 'animated-popup' ), DEBUGPRESS_VERSION );
wp_register_script( 'animated-popup', DEBUGPRESS_PLUGIN_URL . 'popup/popup.min.js', array( 'jquery' ), $this->_animated_popup_version, true );
wp_register_script( 'debugpress', DEBUGPRESS_PLUGIN_URL . 'js/debugpress' . ( DEBUGPRESS_IS_DEBUG ? '' : '.min' ) . '.js', array( 'animated-popup' ), DEBUGPRESS_VERSION, true );

if ( ! DEBUGPRESS_IS_AJAX && ! DEBUGPRESS_IS_CRON && $this->_allowed ) {
$allowed = is_admin() ? $this->get( 'admin' ) : $this->get( 'frontend' );
if ( is_admin() ? $this->get( 'admin' ) : $this->get( 'frontend' ) ) {
Loader::instance();
}
}

if ( $allowed ) {
Loader::instance();
}
public function loader() {
if ( ! $this->is_rest_request() && ! DEBUGPRESS_IS_AJAX && ! DEBUGPRESS_IS_CRON && $this->_allowed ) {
Loader::instance()->run();
}
}

Expand Down Expand Up @@ -215,32 +203,6 @@ public function process_settings( $input ) : array {
return $settings;
}

private function is_user_allowed() : bool {
if ( is_super_admin() ) {
return $this->get( 'for_super_admin' );
} else if ( is_user_logged_in() ) {
$allowed = $this->get( 'for_roles' );

if ( $allowed === true || is_null( $allowed ) ) {
return true;
} else if ( is_array( $allowed ) && empty( $allowed ) ) {
return false;
} else if ( is_array( $allowed ) && ! empty( $allowed ) ) {
global $current_user;

if ( is_array( $current_user->roles ) ) {
$matched = array_intersect( $current_user->roles, $allowed );

return ! empty( $matched );
}
}
} else {
return $this->get( 'for_visitor' );
}

return false;
}

public function environment() : array {
$env = array();

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

return $gd;
}

public function enqueue_print_style() {
wp_enqueue_style( 'debugpress-print' );
}

private function is_user_allowed() : bool {
if ( is_super_admin() ) {
return $this->get( 'for_super_admin' );
} else if ( is_user_logged_in() ) {
$allowed = $this->get( 'for_roles' );

if ( $allowed === true || is_null( $allowed ) ) {
return true;
} else if ( is_array( $allowed ) && empty( $allowed ) ) {
return false;
} else if ( is_array( $allowed ) && ! empty( $allowed ) ) {
global $current_user;

if ( is_array( $current_user->roles ) ) {
$matched = array_intersect( $current_user->roles, $allowed );

return ! empty( $matched );
}
}
} else {
return $this->get( 'for_visitor' );
}

return false;
}

private function load_printer( $name = '' ) {
if ( ! function_exists( 'debugpress_r' ) ) {
$name = empty( $name ) ? $this->get( 'pr' ) : 'prettyprint';
$path = DEBUGPRESS_PLUGIN_PATH . 'core/printer/' . $name . '/load.php';

if ( $name == 'prettyprint' ) {
if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_print_style' ) );
} else {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_print_style' ) );
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_print_style' ) );
}
}

if ( file_exists( $path ) ) {
require_once( $path );
} else {
$this->load_printer( 'prettyprint' );
}
}
}

private function define_constants() {
if ( $this->get( 'auto_wpdebug' ) && ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', true );
}

if ( $this->get( 'auto_savequeries' ) && ! defined( 'SAVEQUERIES' ) ) {
define( 'SAVEQUERIES', true );
}

define( 'DEBUGPRESS_IS_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG );
define( 'DEBUGPRESS_IS_DEBUG_LOG', DEBUGPRESS_IS_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG );

$version = str_replace( '.', '', phpversion() );
$version = intval( substr( $version, 0, 2 ) );

define( 'DEBUGPRESS_PHP_VERSION', $version );
}
}
1 change: 0 additions & 1 deletion core/main/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function __construct() {
}
}

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

Expand Down
1 change: 0 additions & 1 deletion core/main/WP.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public function __construct() {

}

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

Expand Down
7 changes: 6 additions & 1 deletion core/printer/kint/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
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;
exit(1);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitca51731135e08eb5dc8e6d831f11e177::getLoader();
return ComposerAutoloaderInita9b110c47c3d098ebab405be63c84a1e::getLoader();
Loading

0 comments on commit 002b7df

Please sign in to comment.