| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle the admin bar setup. |
| 4 |
* |
| 5 |
* @package DebugQuickLook |
| 6 |
*/ |
| 7 |
|
| 8 |
// Call our namepsace. |
| 9 |
namespace DebugQuickLook\AdminBar; |
| 10 |
|
| 11 |
// Set our alias items. |
| 12 |
use DebugQuickLook as Core; |
| 13 |
use DebugQuickLook\Helpers as Helpers; |
| 14 |
|
| 15 |
/** |
| 16 |
* Start our engines. |
| 17 |
*/ |
| 18 |
add_action( 'wp_head', __NAMESPACE__ . '\add_warning_css' ); |
| 19 |
add_action( 'admin_head', __NAMESPACE__ . '\add_warning_css' ); |
| 20 |
add_action( 'wp_head', __NAMESPACE__ . '\add_mobile_css' ); |
| 21 |
add_action( 'admin_head', __NAMESPACE__ . '\add_mobile_css' ); |
| 22 |
add_action( 'admin_bar_menu', __NAMESPACE__ . '\admin_bar_links', 9999 ); |
| 23 |
|
| 24 |
/** |
| 25 |
* Add the CSS to flag our warning message. |
| 26 |
*/ |
| 27 |
function add_warning_css() { |
| 28 |
|
| 29 |
// Run my cap check. |
| 30 |
$hascap = Helpers\check_user_cap( 'warning-css' ); |
| 31 |
|
| 32 |
// Bail without. |
| 33 |
if ( ! $hascap ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
// Open the style tag. |
| 38 |
echo '<style>'; |
| 39 |
|
| 40 |
// Output the actual CSS item. |
| 41 |
echo 'li#wp-admin-bar-debug-quick-look li.debug-quick-look-missing .ab-item span {'; |
| 42 |
echo 'color: #ff0000;'; |
| 43 |
echo 'font-weight: bold;'; |
| 44 |
echo 'font-family: Consolas, Monaco, monospace;'; |
| 45 |
echo '}'; |
| 46 |
|
| 47 |
// Close the style tag. |
| 48 |
echo '</style>'; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Add the links for the debug log file. |
| 53 |
* |
| 54 |
* @param WP_Admin_Bar $wp_admin_bar The global WP_Admin_Bar object. |
| 55 |
* |
| 56 |
* @return void. |
| 57 |
*/ |
| 58 |
function admin_bar_links( $wp_admin_bar ) { |
| 59 |
|
| 60 |
// Run my cap check. |
| 61 |
$hascap = Helpers\check_user_cap( 'admin-bar' ); |
| 62 |
|
| 63 |
// Bail without. |
| 64 |
if ( ! $hascap ) { |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
// Fetch my nodes. |
| 69 |
$nodes = Helpers\get_admin_bar_nodes(); |
| 70 |
|
| 71 |
// Bail without nodes. |
| 72 |
if ( ! $nodes ) { |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
// Add a parent item. |
| 77 |
$wp_admin_bar->add_node( |
| 78 |
[ |
| 79 |
'id' => 'debug-quick-look', |
| 80 |
'title' => __( 'Debug Quick Look', 'debug-quick-look' ), |
| 81 |
] |
| 82 |
); |
| 83 |
|
| 84 |
// Check to see if we have our constant. |
| 85 |
$hascon = Helpers\maybe_constant_set(); |
| 86 |
|
| 87 |
// If no constant is set, show the error. |
| 88 |
if ( ! $hascon ) { |
| 89 |
|
| 90 |
// Show the error node. |
| 91 |
$wp_admin_bar->add_node( $nodes['error'] ); |
| 92 |
|
| 93 |
// And be done. |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
// We have the constant, so unset the error. |
| 98 |
unset( $nodes['error'] ); |
| 99 |
|
| 100 |
// Loop my node data. |
| 101 |
foreach ( $nodes as $node_name => $node_data ) { |
| 102 |
$wp_admin_bar->add_node( $node_data ); |
| 103 |
} |
| 104 |
|
| 105 |
// And be done. |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Add the CSS to add admin bar menu on mobile. |
| 111 |
*/ |
| 112 |
function add_mobile_css() { |
| 113 |
|
| 114 |
// Run my cap check. |
| 115 |
$hascap = Helpers\check_user_cap( 'warning-css' ); |
| 116 |
|
| 117 |
// Bail without. |
| 118 |
if ( ! $hascap ) { |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
// Open the style tag. |
| 123 |
echo '<style>'; |
| 124 |
|
| 125 |
// Output the actual CSS item. |
| 126 |
echo '@media screen and (max-width: 782px) {'; |
| 127 |
echo '#wp-toolbar > ul > li#wp-admin-bar-debug-quick-look {'; |
| 128 |
// Style similar to Query Monitor. |
| 129 |
echo 'display: list-item;'; |
| 130 |
echo 'font: 18px/44px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important;'; |
| 131 |
echo 'padding: 0 10px !important;'; |
| 132 |
echo 'width: auto !important'; |
| 133 |
echo '}'; |
| 134 |
echo '#wp-toolbar > ul > li#wp-admin-bar-debug-quick-look:before {'; |
| 135 |
echo 'content: "DQL";'; |
| 136 |
echo '}'; |
| 137 |
echo '#wp-toolbar > ul > li#wp-admin-bar-debug-quick-look div.ab-item.ab-empty-item {'; |
| 138 |
echo 'display: none;'; |
| 139 |
echo '}'; |
| 140 |
echo '}'; |
| 141 |
|
| 142 |
// Close the style tag. |
| 143 |
echo '</style>'; |
| 144 |
} |
| 145 |
|