Repository navigation
Conversation
A `content` set on `.ab-item::before` no longer replaces the icon of a node that has an SVG icon. Hide it, so that the two icons are not shown side by side.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
.ab-item::before icons next to SVG icons.ab-item::before icons next to SVG icons
.ab-item::before icons next to SVG icons.ab-item::before icons next to SVG icons
.ab-item::before icons next to SVG icons.ab-item::before icons next to SVG icons
.ab-item::before icons next to SVG icons.ab-item::before icons next to SVG icons
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
… title. A node given the `icon` argument now has the first empty `<span class="ab-icon">` in its title replaced by the icon, as core nodes already do. So a node that draws a Dashicon in its title for earlier versions does not also show it next to the SVG icon.
.ab-item::before icons next to SVG icons
peterwilsoncc
left a comment
There was a problem hiding this comment.
This tests well, I've left a few minor notes inline within the test file.
For testing I used this mini-plugin:
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
$wp_admin_bar->add_node(
array(
'id' => 'example1',
'icon' => 'core-admin/pin', // Used in 7.2, ignored before.
'title' => '<span class="ab-icon dashicons-before dashicons-admin-post"></span>' . __( 'Example 1', 'my-plugin' ), // Span replaced by the icon in 7.2.
'href' => admin_url( 'admin.php?page=my-plugin-notes' ),
)
);
$wp_admin_bar->add_node(
array(
'id' => 'example2',
'icon' => 'core-admin/pin', // Used in 7.2, ignored before.
'title' => __( 'Example 2', 'my-plugin' ),
'href' => admin_url( 'admin.php?page=my-plugin-notes' ),
)
);
$wp_admin_bar->add_node(
array(
'id' => 'example3',
// 'icon' => 'core-admin/pin', // Used in 7.2, ignored before.
'title' => __( 'Example 3', 'my-plugin' ),
'href' => admin_url( 'admin.php?page=my-plugin-notes' ),
)
);
} );
add_action( 'admin_enqueue_scripts', function() {
?>
<style>
/* Used before 7.2, hidden in 7.2. */
#wpadminbar #wp-admin-bar-example2 > .ab-item::before,
#wpadminbar #wp-admin-bar-example3 > .ab-item::before {
content: "\f109"; /* dashicons-admin-post */
}
</style>
<?php
} );|
Thanks for testing, reviewing, and pointing out the handbook page. Addressed the comments 👍 |
|
@peterwilsoncc: I added the last commit to address @mcsf's comment from the previous PR. Let us know what you think. |
|
Tested bd11baf on 7.2-beta3-64990, counting visible icons per toolbar node in Chrome. Way 1 and Way 2 nodes that pass Full table on the ticket: https://core.trac.wordpress.org/ticket/65089 |
| * @param string $title Node title. | ||
| * @return string|false Title without the empty icon element, or false if it has none. | ||
| */ | ||
| private static function remove_empty_icon_element( $title ) { |
There was a problem hiding this comment.
Using the HTML API here feels like overkill to me 🤔 How about handling this with CSS only?
When the element is removed on the server under certain conditions, plugin developers can’t tell why it disappeared without reading the core source. With a CSS-only approach, they can find the selector that hides it in the browser dev tools and override it if needed.
In a quick tes, the following CSS gave the same result as this PR, including the unregistered icon case. It would also make the title restoring logic unnecessary, and hide the empty .svg-icon wrapper when the icon is not registered.
#wpadminbar .ab-item:has(> .ab-icon.svg-icon > svg)::before,
#wpadminbar .ab-item:has(> .ab-icon.svg-icon > svg) .ab-icon:not(.svg-icon):empty,
#wpadminbar .ab-icon.svg-icon:empty {
display: none;
}One difference is that :empty doesn’t match an icon element with whitespace inside, but I think that’s an acceptable trade-off.
There was a problem hiding this comment.
Does the above CSS work with this scenario: a plugin replaces wp-logo with a title that doesn't have empty span, e.g. <img>...my brand logo</img>
- Before 7.2: no WP logo (expected)
- 7.2 trunk: the WP logo SVG icon is not shown. Because we have logic to not show such core node's default icon if the title has no empty span
- If we replace that logic with your CSS, I think both default WP logo SVG, and the image from the title, are now shown?
|
@fushar I'm seeing a random gap when using an invalid icon name with the dashicon, to my test plugin above I added: $wp_admin_bar->add_node(
array(
'id' => 'example4',
'icon' => 'core-admin/invalid-icon-name',
'title' => __( 'Example 4', 'my-plugin' ),
'href' => admin_url( 'admin.php?page=my-plugin-notes' ),
)
);and #wpadminbar #wp-admin-bar-example4 > .ab-item::before {
content: "\f109"; /* dashicons-admin-post */
}In the admin bar the dashicon is shown but there is an empty space for the SVG icon that isn't shown as the mark-up includes |
@peterwilsoncc: yeah, it's an edge case. There are two ways to add dashicon in admin bar nodes:
If the dashicon is added using (2), it's already handled in this PR. Your case (1) is the only edge case missing. It's hard to "fix" it because we can't detect the presence of such CSS-added dashicons in PHP side. If we want to "fix" it, one idea is to hide the empty slot using CSS something like this, but not sure if it's worth it: /*
* Dashicons back-compat: when the icon is not registered, an icon drawn on `.ab-item::before` takes the place of
* the empty icon element instead of showing next to it.
*/
#wpadminbar .ab-item:has(> .ab-icon.svg-icon:empty)::before {
width: 24px;
margin-right: -24px;
text-align: center;
}What do you think? I'm sorry that this PR is becoming more complicated... but admin bar logic is already complicated. It seems we can simplify things e.g. using @t-hamano 's CSS but we need to give up some back-compat behaviors. I'll also brainstorm in the meantime. |
So I believe the complications come from us trying to have back-compat logic for plugins that modify core nodes. Core nodes inconsistently add dashicons using both So maybe, if we give up some of that and instead focus on providing a clean way where plugin's |
|
Thanks all for the patience... I think I managed to implement @t-hamano's idea to hide the old dashicon via CSS. But it has one cost: now unregistered icon will show nothing instead of an empty slot wrapper. I think this is acceptable, since we still report on debug with Please check the test cases here: https://htmlpreview.github.io/?https://github.com/fushar/wordpress-develop/blob/f832b0c4d51b33019381ea23182d0c9a59c061f8/index.html (I also updated the PR description). I think the back-compat behavior is sufficient. The only breakage is when the code manipulates |
| while ( $processor->next_tag( $query ) ) { | ||
| $processor->next_token(); | ||
|
|
||
| if ( 'SPAN' === $processor->get_tag() && $processor->is_tag_closer() ) { | ||
| return true; | ||
| } | ||
| } |
There was a problem hiding this comment.
The scan skips an empty .ab-icon nested directly inside another .ab-icon, so a core node such as wp-logo loses its default icon. Could we keep that inner span as a search candidate and add a nested-span test?
There was a problem hiding this comment.
Sorry, I don't get it. How will this break core's wp-logo, or maybe how can plugin code break that? I think I've listed all possible cases exhaustively here: https://htmlpreview.github.io/?https://github.com/fushar/wordpress-develop/blob/f832b0c4d51b33019381ea23182d0c9a59c061f8/index.html 😄
I also don't think nested .ab-icon spans make sense in admin bar node titles; or at least I've never seen it.
There was a problem hiding this comment.
That's true, core's normal wp-logo title works. Apologies if I wasn't clear.
I meant a plugin-supplied title such as:
$wp_admin_bar->add_node(
array(
'id' => 'wp-logo',
'title' => '<span class="ab-icon"><span class="ab-icon"></span></span>Label',
)
);Here, next_token() consumes the inner opening span. The next next_tag() starts after it, so the helper returns false even though the inner span is empty. I reproduced one SVG on the base and none with this PR. I haven't found a plugin using this structure, so I'd treat this as optional robustness and test coverage, not a merge blocker.
t-hamano
left a comment
There was a problem hiding this comment.
If I understand correctly, what we're aiming for is the same as the admin menu: replace Dashicons with SVG icons in as many scenarios as possible, without forcing developers to write back-compat code.
Most of the complexity comes from the wp-logo node. It is there to avoid showing both the WordPress logo and the plugin's own logo when a plugin replaces the title of this node. Another source of complexity is that core nodes mix two ways of getting their icon: some use the icon argument, and others rely on the empty icon element in their title.
As one idea, what do you think about the following approach?
- All core nodes except
wp-logouse theiconargument, and the empty<span class="ab-icon">is removed from their titles. - Only the
wp-logonode does not use theiconargument, and the SVG icon is put directly in its title instead. When a plugin replaces the title with its own logo, the SVG icon is replaced along with it. get_default_icon()and the check for an empty icon element in the title are removed.- For plugin nodes, keep hiding the old Dashicon (an empty icon element or
.ab-item::before) with CSS when there is an SVG icon, as the latest version of this PR does.
This should solve the back-compat issue with wp-logo while keeping the handling of core node icons simpler.
As a trade-off, if a plugin calls remove_node() and then re-adds a node with the same ID (such as edit) without the icon argument, the node no longer gets an icon.
I haven't tested it, but the change against trunk would probably look like the following. What do you think? Am I missing anything that would affect backward compatibility?
Diff against trunk
diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php
index 1cf33f2..3600b0d 100644
--- a/src/wp-includes/admin-bar.php
+++ b/src/wp-includes/admin-bar.php
@@ -122,10 +122,16 @@ function wp_admin_bar_render() {
* @access private
*
* @param string $icon_name Namespaced icon name, e.g. 'core-admin/wordpress'.
- * @return string Admin bar icon markup. The wrapper is empty if the icon is not found.
+ * @return string Admin bar icon markup, or empty string if the icon is not found.
*/
function _wp_admin_bar_icon( $icon_name ) {
- return '<span class="ab-icon svg-icon" aria-hidden="true">' . wp_get_icon( $icon_name ) . '</span>';
+ $icon = wp_get_icon( $icon_name );
+
+ if ( '' === $icon ) {
+ return '';
+ }
+
+ return '<span class="ab-icon svg-icon" aria-hidden="true">' . $icon . '</span>';
}
/**
@@ -149,7 +155,11 @@ function wp_admin_bar_wp_menu( $wp_admin_bar ) {
$wp_logo_menu_args = array(
'id' => 'wp-logo',
- 'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' .
+ /*
+ * Dashicons back-compat: the icon is part of the title, so that a plugin that replaces
+ * the title with its own logo does not also get the WordPress logo.
+ */
+ 'title' => _wp_admin_bar_icon( 'core-admin/wordpress' ) . '<span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'About WordPress' ) .
'</span>',
@@ -255,7 +265,8 @@ function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
$wp_admin_bar->add_node(
array(
'id' => 'menu-toggle',
- 'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' .
+ 'icon' => 'core-admin/menu',
+ 'title' => '<span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Menu' ) .
'</span>',
@@ -1016,7 +1027,7 @@ function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void {
$is_apple_os = (bool) preg_match( "/{$apple_pattern}/i", $_SERVER['HTTP_USER_AGENT'] ?? '' );
$shortcut_label = $is_apple_os ? $shortcut_labels['appleOS'] : $shortcut_labels['default'];
$title = sprintf(
- '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span>',
+ '<span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span>',
$shortcut_label,
/* translators: Hidden accessibility text. */
__( 'Open command palette' ),
@@ -1049,6 +1060,7 @@ function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void {
$wp_admin_bar->add_node(
array(
'id' => 'command-palette',
+ 'icon' => 'core-admin/search',
'title' => $title,
'href' => '#',
'meta' => array(
@@ -1113,11 +1125,12 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
return;
}
- $title = '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
+ $title = '<span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
$wp_admin_bar->add_node(
array(
'id' => 'new-content',
+ 'icon' => 'core-admin/plus',
'title' => $title,
'href' => admin_url( array_key_first( $actions ) ),
'meta' => array(
@@ -1171,14 +1184,14 @@ function wp_admin_bar_comments_menu( $wp_admin_bar ) {
number_format_i18n( $awaiting_mod )
);
- $icon = '<span class="ab-icon" aria-hidden="true"></span>';
$title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>';
$title .= '<span class="screen-reader-text comments-in-moderation-text">' . $awaiting_text . '</span>';
$wp_admin_bar->add_node(
array(
'id' => 'comments',
- 'title' => $icon . $title,
+ 'icon' => 'core-admin/comment',
+ 'title' => $title,
'href' => admin_url( 'edit-comments.php' ),
)
);
@@ -1286,14 +1299,14 @@ function wp_admin_bar_updates_menu( $wp_admin_bar ) {
number_format_i18n( $update_data['counts']['total'] )
);
- $icon = '<span class="ab-icon" aria-hidden="true"></span>';
$title = '<span class="ab-label" aria-hidden="true">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
$title .= '<span class="screen-reader-text updates-available-text">' . $updates_text . '</span>';
$wp_admin_bar->add_node(
array(
'id' => 'updates',
- 'title' => $icon . $title,
+ 'icon' => 'core-admin/update',
+ 'title' => $title,
'href' => network_admin_url( 'update-core.php' ),
)
);
diff --git a/src/wp-includes/class-wp-admin-bar.php b/src/wp-includes/class-wp-admin-bar.php
index a657ec7..6c8bbef 100644
--- a/src/wp-includes/class-wp-admin-bar.php
+++ b/src/wp-includes/class-wp-admin-bar.php
@@ -117,7 +117,9 @@ class WP_Admin_Bar {
* @type string $id ID of the item.
* @type string $title Title of the node.
* @type string $icon Optional. Namespaced icon name in the form "collection/icon-name",
- * e.g. 'core-admin/pin'. Rendered before the title.
+ * e.g. 'core-admin/pin'. Rendered before the title, and hides a
+ * Dashicon that the node draws in an empty `<span class="ab-icon">`
+ * or on `.ab-item::before`. Ignored if the icon is not registered.
* @type string $parent Optional. ID of the parent node.
* @type string $href Optional. Link for the item.
* @type bool $group Optional. Whether or not the node is a group. Default false.
@@ -183,68 +185,6 @@ class WP_Admin_Bar {
$this->_set_node( $args );
}
- /**
- * Dashicons back-compat: returns the default icon for a node ID that core registers.
- *
- * The icons of these nodes used to be added with CSS rules for the node ID,
- * in one of two ways. A node that has no icon of its own gets the icon under
- * the same condition as before:
- *
- * - On `.ab-item::before`: the node gets the icon whatever its title is. The
- * `my-account` node only gets it without the `with-avatar` class.
- * - On `.ab-icon::before`: the node gets the icon in place of the empty
- * `<span class="ab-icon">` of its title, and no icon without that element.
- *
- * @since 7.2.0
- *
- * @param object $node The node.
- * @return array|false {
- * Default icon, or false if the node has none.
- *
- * @type string $icon Namespaced icon name.
- * @type bool $in_title Whether the icon takes the place of the empty icon element of the title.
- * }
- */
- private static function get_default_icon( $node ) {
- $id = $node->id;
- $default_icons = array(
- // On `.ab-item::before`.
- 'site-name' => array( 'core-admin/dashboard', false ),
- 'my-sites' => array( 'core-admin/sites', false ),
- 'site-editor' => array( 'core-admin/brush', false ),
- 'customize' => array( 'core-admin/brush', false ),
- 'edit' => array( 'core-admin/pencil', false ),
- 'my-account' => array( 'core-admin/people', false ),
- // On `.ab-icon::before`, in the title.
- 'wp-logo' => array( 'core-admin/wordpress', true ),
- 'menu-toggle' => array( 'core-admin/menu', true ),
- 'command-palette' => array( 'core-admin/search', true ),
- 'new-content' => array( 'core-admin/plus', true ),
- 'comments' => array( 'core-admin/comment', true ),
- 'updates' => array( 'core-admin/update', true ),
- );
-
- if ( ! isset( $default_icons[ $id ] ) ) {
- return false;
- }
-
- // The account icon is only for a node without an avatar.
- if ( 'my-account' === $id && in_array( 'with-avatar', explode( ' ', $node->meta['class'] ?? '' ), true ) ) {
- return false;
- }
-
- $icon = $default_icons[ $id ][0];
-
- if ( 'site-name' === $id && ( is_admin() || ! current_user_can( 'read' ) ) ) {
- $icon = 'core-admin/home';
- }
-
- return array(
- 'icon' => $icon,
- 'in_title' => $default_icons[ $id ][1],
- );
- }
-
/**
* @since 3.3.0
*
@@ -641,24 +581,8 @@ class WP_Admin_Bar {
$menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"';
}
- $title = $node->title;
$icon_name = $node->icon;
- // Dashicons back-compat: a core node that was given no icon gets its default icon.
- $default_icon = self::get_default_icon( $node );
-
- // Dashicons back-compat: the icon replaces the first empty `<span class="ab-icon">` in the title; without one, the node gets no default icon.
- if ( $default_icon && $default_icon['in_title'] ) {
- $title = preg_replace( '/<span\b[^>]*\bclass=(["\'])(?:[^"\']*\s)?ab-icon(?:\s[^"\']*)?\1[^>]*>\s*<\/span>/', '', (string) $title, 1, $count );
- if ( ! $count ) {
- $default_icon = false;
- }
- }
-
- if ( ! $icon_name && $default_icon ) {
- $icon_name = $default_icon['icon'];
- }
-
$icon = '';
if ( wp_is_valid_icon_name( $icon_name ) ) {
$icon = _wp_admin_bar_icon( $icon_name );
@@ -699,7 +623,7 @@ class WP_Admin_Bar {
}
}
- echo ">{$arrow}{$icon}{$title}";
+ echo ">{$arrow}{$icon}{$node->title}";
if ( $has_link ) {
echo '</a>';
diff --git a/src/wp-includes/css/admin-bar.css b/src/wp-includes/css/admin-bar.css
index eab5e89..d95093e 100644
--- a/src/wp-includes/css/admin-bar.css
+++ b/src/wp-includes/css/admin-bar.css
@@ -278,6 +278,17 @@ html:lang(he-il) .rtl #wpadminbar * {
text-indent: 0;
}
+/*
+ * Dashicons back-compat: hide a Dashicon next to the SVG icon, except `.ab-icon::before` on core nodes,
+ * and the icon in the title of the `wp-logo` node when the node is given an icon.
+ */
+#wpadminbar .ab-item:has(> .ab-icon.svg-icon)::before,
+#wpadminbar .ab-item:has(> .ab-icon.svg-icon) .ab-icon:not(.svg-icon):empty,
+#wpadminbar li:not(#wp-admin-bar-site-name, #wp-admin-bar-my-sites, #wp-admin-bar-site-editor, #wp-admin-bar-customize, #wp-admin-bar-edit, #wp-admin-bar-my-account, #wp-admin-bar-wp-logo, #wp-admin-bar-menu-toggle, #wp-admin-bar-command-palette, #wp-admin-bar-new-content, #wp-admin-bar-comments, #wp-admin-bar-updates) > .ab-item > .ab-icon.svg-icon::before,
+#wpadminbar .ab-item > .ab-icon.svg-icon ~ .ab-icon.svg-icon {
+ display: none;
+}
+
#wpadminbar .ab-icon.svg-icon svg {
flex: none;
width: 24px;
Yes, that's the goal!
No, you're not missing anything 😄 at this point this really is down to what we want to support for back-compat. For example, with your proposal, the following will break:
What's more important is having a way for plugin authors to write code that works across versions as non-complicated as possible. I believe your and my versions already satisfy that requirement. So now this boils down to simpler core code vs better back-compat. |
Personally, I prefer starting with a simple approach and iterating based on consumer feedback. Trying to cover every edge case from the beginning overcomplicates the logic, making it harder for consumers to understand the rules. That said, I think either approach could work. Since you know this feature best, I defer to your judgment 🙂 |
Interesting, this makes sense. I think I'm starting to like your approach. If we do that, then in 7.2 Core finally have a consistent structure for admin bar nodes (title + icon, except Is there still a time to switch to your approach? Is there a time to pivot to another approach in RC if we have more feedback? Also, I've been holding off releasing the dev note until we settle on this backcompat story 🙂 cc: release tech leads @peterwilsoncc, @Mamaduka |
Exactly. My preference is to minimize exceptions as much as possible and start small and simple.
In my opinion, this should still be possible since we are currently in the beta phase. If time permits, I would like to see either this PR or mine committed by Beta 3, and then make any final adjustments by Beta 4 or RC 1 if necessary. |
|
For reference, I regenerated the test case report using Aki's proposal, showing the difference between the existing PR and the proposal: https://htmlpreview.github.io/?https://github.com/fushar/wordpress-develop/blob/c54f9f3/compare.html I added 3 new cases where the back-compat logic would fail below:
Everything else is good. |
|
Thanks for the comparison, @fushar!
I think this is quite a rare case. Plugins can already replace the
These two could be solved by putting the SVG icon in the Personally, I think these cases are acceptable, and we can cover them in the dev note. |
That's actually a good point. 😅 What if we do your simpler patch, then ship Beta 4 + dev note and see if we have feedback? It seems @peterwilsoncc (who's been quite involved in the feature) is AFK right now to give opinion. |
Personally, I prefer this one 👍 |
If we can make it in time, I would like to release it in Beta 3 (Tuesday, 3rd at 15:00 UTC). |
|
Beta 3 shipped last week with the security release. We'll do beta 4 and 5 instead. |
…-ab-item-before-with-svg-icon # Conflicts: # tests/phpunit/tests/adminbar.php
t-hamano
left a comment
There was a problem hiding this comment.
At this point, this seems to be the best approach. Unless anyone has any objections, I plan to commit this in time for today's Beta 4 release.
When an admin bar node has an SVG icon, the Dashicon it draws for earlier WordPress versions is now hidden, whether that Dashicon is an empty icon element in the title or is drawn with CSS on the link. Plugins can therefore pass the `icon` argument with the same title on 7.2 and earlier versions, without a version check, and an unregistered icon now renders nothing instead of leaving an empty gap. Core nodes now set their icons with the `icon` argument instead of an empty icon element in the title, and the title is no longer modified when the node is rendered. Developed in #14999 Follow-up to [64583]. Props fushar, mamaduka, mciampini, mcsf, peterwilsoncc, sadmansakibnadvi, wildworks. See #65089. git-svn-id: https://develop.svn.wordpress.org/trunk@65223 602fd350-edb4-49c9-b593-d223f7449a82
When an admin bar node has an SVG icon, the Dashicon it draws for earlier WordPress versions is now hidden, whether that Dashicon is an empty icon element in the title or is drawn with CSS on the link. Plugins can therefore pass the `icon` argument with the same title on 7.2 and earlier versions, without a version check, and an unregistered icon now renders nothing instead of leaving an empty gap. Core nodes now set their icons with the `icon` argument instead of an empty icon element in the title, and the title is no longer modified when the node is rendered. Developed in WordPress/wordpress-develop#14999 Follow-up to [64583]. Props fushar, mamaduka, mciampini, mcsf, peterwilsoncc, sadmansakibnadvi, wildworks. See #65089. Built from https://develop.svn.wordpress.org/trunk@65223 git-svn-id: http://core.svn.wordpress.org/trunk@64372 1a063a9b-81f0-0310-95a4-ce76da25c4cd
mcsf
left a comment
There was a problem hiding this comment.
I'm trusting the reviews/judgement of the other committers in this PR, but this looks good from a superficial glance! I'm happy to see simplifications in the PHP logic, so thanks. :)
I think a comment could be polished, but that's a minor thing.
| * Dashicons back-compat: hide a Dashicon next to the SVG icon, except `.ab-icon::before` on core nodes, | ||
| * and the icon in the title of the `wp-logo` node when the node is given an icon. |
There was a problem hiding this comment.
We can improve this comment, because I think future readers will have a hard time understanding this without spending some time reading this very PR:
- what does "hide Dashicon next to the SVG icon" mean? -> explain that, for compat, we render both these things, and the new one is X, and we hide the element of Y, etc.
- why is wp-logo special? -> explain something along the lines of: we don't want to break plugins that replace the WP logo, so we kept its rendering in the old style



Proposed changes
Trac ticket: https://core.trac.wordpress.org/ticket/65089
This PR makes it possible to write admin bar code that works on 7.2 and earlier versions without a version check, and removes the title manipulation from
WP_Admin_Bar::_render_item()..ab-item::before, in an empty<span class="ab-icon">, or on.ab-icon::beforeof that span.contenton.ab-icon::beforestill takes the place of core's icon.<span class="ab-icon">stays in the title of core's nodes and is hidden with CSS.WP_HTML_Tag_Processoris only used to check that the span is there, as a node without it still gets no default icon._wp_admin_bar_icon()returns an empty string when there is no icon, so an empty wrapper is never rendered. An unregisterediconrenders nothing, which fixes the gap reported by @peterwilsoncc.See the "Change to unpublished dev note" section below to see how this affects the dev note.
Comparison on 7.1 and 7.2
See this page for all the test cases: https://htmlpreview.github.io/?https://github.com/fushar/wordpress-develop/blob/f832b0c4d51b33019381ea23182d0c9a59c061f8/index.html
Change to unpublished dev note
The draft dev note for the SVG icons (not published yet) has two sections that become simpler.
Show the current and proposed text
1. Replacing an admin bar icon through
.ab-item::beforeIt currently says:
If this PR is accepted, it will be updated to:
2. Supporting earlier versions (admin bar part)
It currently says:
If this PR is accepted, it will be updated to:
Testing
iconargument renders only the SVG icon in place of an empty icon element (with or without Dashicons classes), keeps an icon element that has content, and keeps the element when the value is not an icon name.Use of AI Tools
Used Claude Opus 5.5 to discuss the approach, survey how plugins draw admin bar icons, and implement and test the change.