Skip to content

Commit 8942937

Browse files
PHPCS cleanup and simplification in some cases.
* Shifted the Admin Bar CSS to add inline * Hooked into `admin_bar_init` to simplify front-end and back-end CSS rendering.
1 parent cfcdce5 commit 8942937

File tree

7 files changed

+49
-48
lines changed

7 files changed

+49
-48
lines changed

assets/css/admin-bar.html

Lines changed: 0 additions & 32 deletions
This file was deleted.

config/admin-bar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
'message_background_color' => '#cb4b14',
2020
'message_hover_color' => '#1b202d',
2121
],
22-
'css_file' => _get_plugin_root_dir() . '/assets/css/admin-bar.html',
22+
'css_file' => _get_plugin_root_dir() . '/assets/css/admin-bar.php',
2323
];

phpcs.xml.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
<properties>
4848
<property name="prefixes" type="array">
4949
<element value="KnowTheCode\DebugToolkit"/>
50-
<element value="debugtoolkit_"/>
51-
<element value="_genesis"/>
50+
<element value="debug_toolkit"/>
5251
</property>
5352
</properties>
5453
</rule>

src/class-admin-bar.php

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
/**
1616
* Class Admin_Bar
17+
*
1718
* @package KnowTheCode\DebugToolkit
1819
*/
1920
class Admin_Bar {
@@ -42,8 +43,7 @@ public function __construct( array $config ) {
4243
public function init() {
4344
add_filter( 'get_user_option_admin_color', [ $this, 'set_local_development_admin_color_scheme' ], 5 );
4445
add_action( 'admin_bar_menu', [ $this, 'add_admin_bar_notice' ], 9999 );
45-
add_action( 'admin_head', [ $this, 'render_admin_bar_css' ], 9999 );
46-
add_action( 'wp_head', [ $this, 'render_admin_bar_css' ], 9999 );
46+
add_action( 'admin_bar_init', [ $this, 'render_admin_bar_css' ], 9999 );
4747
}
4848

4949
/**
@@ -93,12 +93,42 @@ public function render_admin_bar_css() {
9393
return;
9494
}
9595

96-
ob_start();
97-
98-
include $this->config['css_file'];
96+
$css =
97+
"
98+
#wpadminbar {
99+
background-color: %s !important;
100+
}
101+
102+
#wp-admin-bar-environment-notice {
103+
display: none;
104+
}
105+
106+
#wpadminbar .ab-item,
107+
#wpadminbar a.ab-item,
108+
#wpadminbar > #wp-toolbar span.ab-label,
109+
#wpadminbar > #wp-toolbar span.noticon,
110+
.adminbar--environment-notice {
111+
color: #fff;
112+
}
113+
114+
@media only screen and ( min-width: 800px ) {
115+
#wp-admin-bar-environment-notice {
116+
display: block;
117+
}
118+
119+
#wp-admin-bar-environment-notice .ab-item {
120+
background-color: %s !important;
121+
}
122+
123+
#wp-admin-bar-environment-notice:hover .ab-item {
124+
background-color: %s !important;
125+
color: #fff;
126+
}
127+
}
128+
";
99129

100-
$css_pattern = ob_get_clean();
130+
$css = vsprintf( $css, $this->config['colors'] );
101131

102-
vprintf( $css_pattern, $this->config['colors'] );
132+
wp_add_inline_style( 'admin-bar', $css );
103133
}
104134
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* Class VarDumper_Helpers
22+
*
2223
* @package KnowTheCode\DebugToolkit
2324
*/
2425
class VarDumper_Helpers {
@@ -98,7 +99,7 @@ private static function set_styles() {
9899
* @param string $key Optional. Parameter's key to return.
99100
*
100101
* @return mixed
101-
* @throw InvalidArgumentException If the key does not exist, an error is thrown.
102+
* @throws InvalidArgumentException If the key does not exist, an error is thrown.
102103
*/
103104
private static function get_config( $key = '' ) {
104105
if ( empty( static::$config ) ) {
@@ -109,18 +110,19 @@ private static function get_config( $key = '' ) {
109110
*
110111
* @param array Array of configuration parameters for the VarDump component.
111112
*/
112-
static::$config = apply_filters( 'debugtoolkit_set_html_dumper_config', (array) require _get_plugin_root_dir() . '/config/var-dumper.php' );
113+
static::$config = apply_filters( 'debug_toolkit_set_html_dumper_config', (array) require _get_plugin_root_dir() . '/config/var-dumper.php' );
113114
}
114115

115116
if ( empty( $key ) ) {
116117
return static::$config;
117118
}
118119

119120
if ( ! array_key_exists( $key, static::$config ) ) {
120-
$message = __( 'The key [$s] does not exist in the config:', 'devtoolkit' );
121+
$message = __( 'The key [$s] does not exist in the config:', 'debugtoolkit' );
121122
$message = sprintf( $message, $key );
122123
throw new InvalidArgumentException(
123-
esc_html( $message . ': ' ) . print_r( static::$config, true )
124+
esc_html( $message . ': ' ) .
125+
print_r( static::$config, true ) // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
124126
);
125127
}
126128

src/setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function _setup_plugin() {
3333
*/
3434
function _setup_whoops() {
3535
$whoops = new Run();
36-
$whoops->pushHandler( new PrettyPageHandler );
36+
$whoops->pushHandler( new PrettyPageHandler() );
3737
$whoops->register();
3838
}
3939

src/vardumper-functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
use KnowTheCode\DebugToolkit\VarDumper_Helpers;
1919

20-
require_once __DIR__ . '/class-vardumper.php';
20+
require_once __DIR__ . '/class-vardumper-helpers.php';
21+
22+
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Function names are intentational here.
2123

2224
if ( ! function_exists( 'vdump' ) ) {
2325
/**

0 commit comments

Comments
 (0)