PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | php/Integration/Admin_Bar.php +53 -4 3.10.24.0.0-beta.2 View file →
@@ -154,8 +154,48 @@
154 154 $this->add_safe_mode_link( $wp_admin_bar );
155 155 }
156 156
157 157 /**
158 + * Render a small color badge for a snippet's execution kind, matching the
159 + * type-badge treatment on the snippets list.
160 + *
161 + * @param string $kind Execution kind: 'php', 'content', 'css', 'js'.
162 + *
163 + * @return string Safe HTML.
164 + */
165 + private function format_kind_badge( string $kind ): string {
166 + $kind = 'content' === $kind ? 'html' : $kind;
167 + $labels = [
168 + 'php' => 'PHP',
169 + 'html' => 'HTML',
170 + 'css' => 'CSS',
171 + 'js' => 'JS',
172 + 'cond' => 'COND',
173 + ];
174 + $colours = [
175 + 'php' => '#2271b1',
176 + 'html' => '#cd4510',
177 + 'css' => '#9b59b6',
178 + 'js' => '#f7d67a',
179 + 'cond' => '#22826f',
180 + ];
181 + $text_colours = [
182 + 'js' => '#1c1f20',
183 + ];
184 +
185 + $label = $labels[ $kind ] ?? strtoupper( $kind );
186 + $colour = $colours[ $kind ] ?? '#5b7290';
187 + $text_colour = $text_colours[ $kind ] ?? '#fff';
188 +
189 + return sprintf(
190 + '<span class="code-snippets-kind-badge" style="background:%1$s;color:%2$s">%3$s</span> ',
191 + esc_attr( $colour ),
192 + esc_attr( $text_colour ),
193 + esc_html( $label )
194 + );
195 + }
196 +
197 + /**
158 198 * Add menu item for safe mode status.
159 199 *
160 200 * @param WP_Admin_Bar $wp_admin_bar Admin bar instance.
161 201 *
@@ -286,8 +326,17 @@
286 326 }
287 327
288 328 $wp_admin_bar->add_node(
289 329 [
330 + 'id' => self::ROOT_NODE_ID . '-insights',
331 + 'title' => esc_html_x( 'Insights', 'snippets', 'code-snippets' ),
332 + 'href' => $plugin->get_menu_url( 'insights' ),
333 + 'parent' => self::ROOT_NODE_ID,
334 + ]
335 + );
336 +
337 + $wp_admin_bar->add_node(
338 + [
290 339 'id' => self::ROOT_NODE_ID . '-import',
291 340 'title' => esc_html_x( 'Import', 'snippets', 'code-snippets' ),
292 341 'href' => $plugin->get_menu_url( 'import' ),
293 342 'parent' => self::ROOT_NODE_ID,
@@ -400,9 +449,9 @@
400 449 foreach ( $active_page_snippets as $snippet ) {
401 450 $wp_admin_bar->add_node(
402 451 [
403 452 'id' => self::ROOT_NODE_ID . '-snippet-' . $snippet->id,
404 - 'title' => esc_html( $this->format_snippet_title( $snippet ) ),
453 + 'title' => $this->format_snippet_title( $snippet ),
405 454 'href' => esc_url( add_query_arg( 'id', $snippet->id, $plugin->get_menu_url( 'edit' ) ) ),
406 455 'parent' => self::ROOT_NODE_ID . '-active-snippets',
407 456 'meta' => [ 'class' => 'code-snippets-snippet-item' ],
408 457 ]
@@ -433,9 +482,9 @@
433 482 foreach ( $inactive_page_snippets as $snippet ) {
434 483 $wp_admin_bar->add_node(
435 484 [
436 485 'id' => self::ROOT_NODE_ID . '-snippet-' . $snippet->id,
437 - 'title' => esc_html( $this->format_snippet_title( $snippet ) ),
486 + 'title' => $this->format_snippet_title( $snippet ),
438 487 'href' => esc_url( add_query_arg( 'id', $snippet->id, $plugin->get_menu_url( 'edit' ) ) ),
439 488 'parent' => self::ROOT_NODE_ID . '-inactive-snippets',
440 489 'meta' => [ 'class' => 'code-snippets-snippet-item' ],
441 490 ]
@@ -447,12 +496,12 @@
447 496 * Build an admin bar snippet title including type prefix.
448 497 *
449 498 * @param Snippet $snippet Snippet object.
450 499 *
451 - * @return string
500 + * @return string Safe HTML.
452 501 */
453 502 private function format_snippet_title( Snippet $snippet ): string {
454 - return sprintf( '(%s) %s', strtoupper( $snippet->type ), $snippet->display_name );
503 + return $this->format_kind_badge( $snippet->type ) . esc_html( $snippet->display_name );
455 504 }
456 505
457 506 /**
458 507 * Retrieve the number of snippets to show per page in the admin bar.