<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[26664] trunk/src: Allow for Dashicons and base64-encoded data:image/svg+xml URIs when specifying menu icons.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/26664">26664</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-12-05 06:37:20 +0000 (Thu, 05 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow for Dashicons and base64-encoded data:image/svg+xml URIs when specifying menu icons.

Both of these icons can be colored to match the color scheme, including hover states.
Both are accepted for register_post_type()'s menu_icon argument, and also add_menu_page()'s $icon_url argument.

To use a Dashicon, pass the name of the helper class, e.g. 'dashicons-piechart'.
To use an SVG, pass a valid data URI string starting with 'data:image/svg+xml;base64,'.

props helen.
fixes <a href="http://core.trac.wordpress.org/ticket/25147">#25147</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincsswpadmincss">trunk/src/wp-admin/css/wp-admin.css</a></li>
<li><a href="#trunksrcwpadminincludesmiscphp">trunk/src/wp-admin/includes/misc.php</a></li>
<li><a href="#trunksrcwpadminincludespluginphp">trunk/src/wp-admin/includes/plugin.php</a></li>
<li><a href="#trunksrcwpadminmenuheaderphp">trunk/src/wp-admin/menu-header.php</a></li>
<li><a href="#trunksrcwpadminmenuphp">trunk/src/wp-admin/menu.php</a></li>
<li><a href="#trunksrcwpincludesjssvgpainterjs">trunk/src/wp-includes/js/svg-painter.js</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincsswpadmincss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/css/wp-admin.css (26663 => 26664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/css/wp-admin.css      2013-12-05 06:30:56 UTC (rev 26663)
+++ trunk/src/wp-admin/css/wp-admin.css 2013-12-05 06:37:20 UTC (rev 26664)
</span><span class="lines">@@ -1874,6 +1874,8 @@
</span><span class="cx">  width: 34px;
</span><span class="cx">  height: 30px;
</span><span class="cx">  margin: 0;
</span><ins>+       background-repeat: no-repeat;
+       background-position: center;
</ins><span class="cx">   text-align: center;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunksrcwpadminincludesmiscphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/misc.php (26663 => 26664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/misc.php     2013-12-05 06:30:56 UTC (rev 26663)
+++ trunk/src/wp-admin/includes/misc.php        2013-12-05 06:37:20 UTC (rev 26664)
</span><span class="lines">@@ -618,9 +618,21 @@
</span><span class="cx"> 
</span><span class="cx">  $color_scheme = get_user_option( 'admin_color' );
</span><span class="cx"> 
</span><ins>+       // It's possible to have a color scheme set that is no longer registered.
+       if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) {
+               $color_scheme = 'fresh';
+       }
+
</ins><span class="cx">   if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) {
</span><del>-               echo '<script type="text/javascript">var _wpColorScheme = ' . json_encode( array( 'icons' => $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) . ";</script>\n";
</del><ins>+                $icon_colors = $_wp_admin_css_colors[ $color_scheme ]->icon_colors;
+       } elseif ( ! empty( $_wp_admin_css_colors['fresh']->icon_colors ) ) {
+               $icon_colors = $_wp_admin_css_colors['fresh']->icon_colors;
+       } else {
+               // Fall back to the default set of icon colors if the default scheme is missing.
+               $icon_colors = array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' );
</ins><span class="cx">   }
</span><ins>+
+       echo '<script type="text/javascript">var _wpColorScheme = ' . json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n";
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'admin_head', 'wp_color_scheme_settings' );
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunksrcwpadminincludespluginphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/plugin.php (26663 => 26664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/plugin.php   2013-12-05 06:30:56 UTC (rev 26663)
+++ trunk/src/wp-admin/includes/plugin.php      2013-12-05 06:37:20 UTC (rev 26664)
</span><span class="lines">@@ -966,8 +966,11 @@
</span><span class="cx">  * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="cx">  * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
</span><span class="cx">  * @param callback $function The function to be called to output the content for this page.
</span><del>- * @param string $icon_url The url to the icon to be used for this menu. Using 'none' would leave div.wp-menu-image empty
- *                         so an icon can be added as background with CSS.
</del><ins>+ * @param string $icon_url The url to the icon to be used for this menu.
+ *     * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme.
+ *       This should begin with 'data:image/svg+xml;base64,'.
+ *     * Pass the name of a Dashicons helper class to use a font icon, e.g. 'dashicons-piechart'.
+ *     * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS.
</ins><span class="cx">  * @param int $position The position in the menu order this one should appear
</span><span class="cx">  *
</span><span class="cx">  * @return string The resulting page's hook_suffix
</span></span></pre></div>
<a id="trunksrcwpadminmenuheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/menu-header.php (26663 => 26664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/menu-header.php       2013-12-05 06:30:56 UTC (rev 26663)
+++ trunk/src/wp-admin/menu-header.php  2013-12-05 06:37:20 UTC (rev 26664)
</span><span class="lines">@@ -67,11 +67,24 @@
</span><span class="cx"> 
</span><span class="cx">          $class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
</span><span class="cx">          $id = ! empty( $item[5] ) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : '';
</span><del>-               $img = '';
</del><ins>+                $img = $img_style = $img_class = '';
+
</ins><span class="cx">           // if the string 'none' (previously 'div') is passed instead of an URL, don't output the default menu image
</span><span class="cx">          // so an icon can be added to div.wp-menu-image as background with CSS.
</span><del>-               if ( ! empty( $item[6] ) )
-                       $img = ( 'none' === $item[6] || 'div' === $item[6] ) ? '<br />' : '<img src="' . $item[6] . '" alt="" />';
</del><ins>+                // Dashicons and base64-encoded data:image/svg_xml URIs are also handled as special cases.
+               if ( ! empty( $item[6] ) ) {
+                       $img = '<img src="' . $item[6] . '" alt="" />';
+
+                       if ( 'none' === $item[6] || 'div' === $item[6] ) {
+                               $img = '<br />';
+                       } elseif ( 0 === strpos( $item[6], 'data:image/svg+xml;base64,' ) ) {
+                               $img = '<br />';
+                               $img_style = ' style="background-image:url(\'' . esc_attr( $item[6] ) . '\')"';
+                       } elseif ( 0 === strpos( $item[6], 'dashicons-' ) ) {
+                               $img = '<br />';
+                               $img_class = ' dashicons ' . sanitize_html_class( $item[6] );
+                       }
+               }
</ins><span class="cx">           $arrow = '<div class="wp-menu-arrow"><div></div></div>';
</span><span class="cx"> 
</span><span class="cx">          $title = wptexturize( $item[0] );
</span><span class="lines">@@ -88,9 +101,9 @@
</span><span class="cx">                          $menu_file = substr( $menu_file, 0, $pos );
</span><span class="cx">                  if ( ! empty( $menu_hook ) || ( ( 'index.php' != $submenu_items[0][2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) {
</span><span class="cx">                          $admin_is_parent = true;
</span><del>-                               echo "<a href='admin.php?page={$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image'>$img</div><div class='wp-menu-name'>$title</div></a>";
</del><ins>+                                echo "<a href='admin.php?page={$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>$title</div></a>";
</ins><span class="cx">                   } else {
</span><del>-                               echo "\n\t<a href='{$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image'>$img</div><div class='wp-menu-name'>$title</div></a>";
</del><ins>+                                echo "\n\t<a href='{$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>$title</div></a>";
</ins><span class="cx">                   }
</span><span class="cx">          } elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
</span><span class="cx">                  $menu_hook = get_plugin_page_hook( $item[2], 'admin.php' );
</span><span class="lines">@@ -99,9 +112,9 @@
</span><span class="cx">                          $menu_file = substr( $menu_file, 0, $pos );
</span><span class="cx">                  if ( ! empty( $menu_hook ) || ( ( 'index.php' != $item[2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) {
</span><span class="cx">                          $admin_is_parent = true;
</span><del>-                               echo "\n\t<a href='admin.php?page={$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image'>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>";
</del><ins>+                                echo "\n\t<a href='admin.php?page={$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>";
</ins><span class="cx">                   } else {
</span><del>-                               echo "\n\t<a href='{$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image'>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>";
</del><ins>+                                echo "\n\t<a href='{$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>";
</ins><span class="cx">                   }
</span><span class="cx">          }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunksrcwpadminmenuphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/menu.php (26663 => 26664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/menu.php      2013-12-05 06:30:56 UTC (rev 26663)
+++ trunk/src/wp-admin/menu.php 2013-12-05 06:37:20 UTC (rev 26664)
</span><span class="lines">@@ -107,8 +107,14 @@
</span><span class="cx">          continue;
</span><span class="cx">  $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first.
</span><span class="cx">  $ptype_for_id = sanitize_html_class( $ptype );
</span><ins>+
</ins><span class="cx">   if ( is_string( $ptype_obj->menu_icon ) ) {
</span><del>-               $menu_icon   = esc_url( $ptype_obj->menu_icon );
</del><ins>+                // Special handling for data:image/svg+xml and Dashicons.
+               if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) {
+                       $menu_icon = $ptype_obj->menu_icon;
+               } else {
+                       $menu_icon = esc_url( $ptype_obj->menu_icon );
+               }
</ins><span class="cx">           $ptype_class = $ptype_for_id;
</span><span class="cx">  } else {
</span><span class="cx">          $menu_icon   = 'none';
</span></span></pre></div>
<a id="trunksrcwpincludesjssvgpainterjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/svg-painter.js (26663 => 26664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/svg-painter.js  2013-12-05 06:30:56 UTC (rev 26663)
+++ trunk/src/wp-includes/js/svg-painter.js     2013-12-05 06:37:20 UTC (rev 26664)
</span><span class="lines">@@ -200,7 +200,7 @@
</span><span class="cx">                          $element.data( 'wp-ui-svg-' + color, xml );
</span><span class="cx">                  }
</span><span class="cx"> 
</span><del>-                       $element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
</del><ins>+                        $element.css( 'background-image', 'url("data:image/svg+xml;base64,' + xml + '")' );
</ins><span class="cx">           }
</span><span class="cx">  };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/post.php (26663 => 26664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/post.php   2013-12-05 06:30:56 UTC (rev 26663)
+++ trunk/src/wp-includes/post.php      2013-12-05 06:37:20 UTC (rev 26664)
</span><span class="lines">@@ -1129,6 +1129,10 @@
</span><span class="cx">  *     * show_in_menu must be true
</span><span class="cx">  *     * Defaults to null, which places it at the bottom of its area.
</span><span class="cx">  * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
</span><ins>+ *     * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme.
+ *      This should begin with 'data:image/svg+xml;base64,'.
+ *     * Pass the name of a Dashicons helper class to use a font icon, e.g. 'dashicons-piechart'.
+ *     * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS.
</ins><span class="cx">  * - capability_type - The string to use to build the read, edit, and delete capabilities. Defaults to 'post'.
</span><span class="cx">  *     * May be passed as an array to allow for alternative plurals when using this argument as a base to construct the
</span><span class="cx">  *       capabilities, e.g. array('story', 'stories').
</span></span></pre>
</div>
</div>

</body>
</html>