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 #25147. git-svn-id: https://develop.svn.wordpress.org/trunk@26664 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
721ffcbb07
commit
006045395c
@ -1874,6 +1874,8 @@ form.upgrade .hint {
|
|||||||
width: 34px;
|
width: 34px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,9 +618,21 @@ function wp_color_scheme_settings() {
|
|||||||
|
|
||||||
$color_scheme = get_user_option( 'admin_color' );
|
$color_scheme = get_user_option( 'admin_color' );
|
||||||
|
|
||||||
if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) {
|
// It's possible to have a color scheme set that is no longer registered.
|
||||||
echo '<script type="text/javascript">var _wpColorScheme = ' . json_encode( array( 'icons' => $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) . ";</script>\n";
|
if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) {
|
||||||
|
$color_scheme = 'fresh';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) {
|
||||||
|
$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' );
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<script type="text/javascript">var _wpColorScheme = ' . json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n";
|
||||||
}
|
}
|
||||||
add_action( 'admin_head', 'wp_color_scheme_settings' );
|
add_action( 'admin_head', 'wp_color_scheme_settings' );
|
||||||
|
|
||||||
|
@ -966,8 +966,11 @@ function uninstall_plugin($plugin) {
|
|||||||
* @param string $capability The capability required for this menu to be displayed to the user.
|
* @param string $capability The capability required for this menu to be displayed to the user.
|
||||||
* @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
|
* @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
|
||||||
* @param callback $function The function to be called to output the content for this page.
|
* @param callback $function The function to be called to output the content for this page.
|
||||||
* @param string $icon_url The url to the icon to be used for this menu. Using 'none' would leave div.wp-menu-image empty
|
* @param string $icon_url The url to the icon to be used for this menu.
|
||||||
* so an icon can be added as background with CSS.
|
* * 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.
|
||||||
* @param int $position The position in the menu order this one should appear
|
* @param int $position The position in the menu order this one should appear
|
||||||
*
|
*
|
||||||
* @return string The resulting page's hook_suffix
|
* @return string The resulting page's hook_suffix
|
||||||
|
@ -67,11 +67,24 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
|
|||||||
|
|
||||||
$class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
|
$class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
|
||||||
$id = ! empty( $item[5] ) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : '';
|
$id = ! empty( $item[5] ) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : '';
|
||||||
$img = '';
|
$img = $img_style = $img_class = '';
|
||||||
|
|
||||||
// if the string 'none' (previously 'div') is passed instead of an URL, don't output the default menu image
|
// if the string 'none' (previously 'div') is passed instead of an URL, don't output the default menu image
|
||||||
// so an icon can be added to div.wp-menu-image as background with CSS.
|
// so an icon can be added to div.wp-menu-image as background with CSS.
|
||||||
if ( ! empty( $item[6] ) )
|
// Dashicons and base64-encoded data:image/svg_xml URIs are also handled as special cases.
|
||||||
$img = ( 'none' === $item[6] || 'div' === $item[6] ) ? '<br />' : '<img src="' . $item[6] . '" alt="" />';
|
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] );
|
||||||
|
}
|
||||||
|
}
|
||||||
$arrow = '<div class="wp-menu-arrow"><div></div></div>';
|
$arrow = '<div class="wp-menu-arrow"><div></div></div>';
|
||||||
|
|
||||||
$title = wptexturize( $item[0] );
|
$title = wptexturize( $item[0] );
|
||||||
@ -88,9 +101,9 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
|
|||||||
$menu_file = substr( $menu_file, 0, $pos );
|
$menu_file = substr( $menu_file, 0, $pos );
|
||||||
if ( ! empty( $menu_hook ) || ( ( 'index.php' != $submenu_items[0][2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) {
|
if ( ! empty( $menu_hook ) || ( ( 'index.php' != $submenu_items[0][2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) {
|
||||||
$admin_is_parent = true;
|
$admin_is_parent = true;
|
||||||
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>";
|
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>";
|
||||||
} else {
|
} else {
|
||||||
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>";
|
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>";
|
||||||
}
|
}
|
||||||
} elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
|
} elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
|
||||||
$menu_hook = get_plugin_page_hook( $item[2], 'admin.php' );
|
$menu_hook = get_plugin_page_hook( $item[2], 'admin.php' );
|
||||||
@ -99,9 +112,9 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
|
|||||||
$menu_file = substr( $menu_file, 0, $pos );
|
$menu_file = substr( $menu_file, 0, $pos );
|
||||||
if ( ! empty( $menu_hook ) || ( ( 'index.php' != $item[2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) {
|
if ( ! empty( $menu_hook ) || ( ( 'index.php' != $item[2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) {
|
||||||
$admin_is_parent = true;
|
$admin_is_parent = true;
|
||||||
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>";
|
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>";
|
||||||
} else {
|
} else {
|
||||||
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>";
|
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>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,14 @@ foreach ( (array) get_post_types( array('show_ui' => true, '_builtin' => false,
|
|||||||
continue;
|
continue;
|
||||||
$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.
|
$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.
|
||||||
$ptype_for_id = sanitize_html_class( $ptype );
|
$ptype_for_id = sanitize_html_class( $ptype );
|
||||||
|
|
||||||
if ( is_string( $ptype_obj->menu_icon ) ) {
|
if ( is_string( $ptype_obj->menu_icon ) ) {
|
||||||
|
// 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 );
|
$menu_icon = esc_url( $ptype_obj->menu_icon );
|
||||||
|
}
|
||||||
$ptype_class = $ptype_for_id;
|
$ptype_class = $ptype_for_id;
|
||||||
} else {
|
} else {
|
||||||
$menu_icon = 'none';
|
$menu_icon = 'none';
|
||||||
|
@ -200,7 +200,7 @@ var svgPainter = ( function( $, window, document, undefined ) {
|
|||||||
$element.data( 'wp-ui-svg-' + color, xml );
|
$element.data( 'wp-ui-svg-' + color, xml );
|
||||||
}
|
}
|
||||||
|
|
||||||
$element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
|
$element.css( 'background-image', 'url("data:image/svg+xml;base64,' + xml + '")' );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1129,6 +1129,10 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' )
|
|||||||
* * show_in_menu must be true
|
* * show_in_menu must be true
|
||||||
* * Defaults to null, which places it at the bottom of its area.
|
* * Defaults to null, which places it at the bottom of its area.
|
||||||
* - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
|
* - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
|
||||||
|
* * 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.
|
||||||
* - capability_type - The string to use to build the read, edit, and delete capabilities. Defaults to 'post'.
|
* - capability_type - The string to use to build the read, edit, and delete capabilities. Defaults to 'post'.
|
||||||
* * May be passed as an array to allow for alternative plurals when using this argument as a base to construct the
|
* * May be passed as an array to allow for alternative plurals when using this argument as a base to construct the
|
||||||
* capabilities, e.g. array('story', 'stories').
|
* capabilities, e.g. array('story', 'stories').
|
||||||
|
Loading…
Reference in New Issue
Block a user