diff --git a/CHANGELOG.md b/CHANGELOG.md index f709b68..64a23fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,15 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [Unreleased][unreleased] +## [Unreleased] _No changes._ +## [1.0.3] - 2016-07-31 + +- Added support for dashicons. +- Fixed incorrect link in change log. + ## [1.0.2] - 2015-08-12 - Fix regression in 1.0.1 for labels. @@ -20,6 +25,7 @@ _No changes._ - Initial release. -[unreleased]: https://github.com/GaryJones/Gamajo-Dashboard-Glancer/compare/1.0.0...HEAD +[Unreleased]: https://github.com/GaryJones/Gamajo-Dashboard-Glancer/compare/1.0.3...HEAD +[1.0.3]: https://github.com/GaryJones/Gamajo-Dashboard-Glancer/compare/1.0.2...1.0.3 [1.0.2]: https://github.com/GaryJones/Gamajo-Dashboard-Glancer/compare/1.0.1...1.0.2 [1.0.1]: https://github.com/GaryJones/Gamajo-Dashboard-Glancer/compare/1.0.0...1.0.1 diff --git a/class-gamajo-dashboard-glancer.php b/class-gamajo-dashboard-glancer.php index 04e3e5b..fd79be8 100644 --- a/class-gamajo-dashboard-glancer.php +++ b/class-gamajo-dashboard-glancer.php @@ -7,7 +7,7 @@ * @link http://gamajo.com/dashboard-glancer * @copyright 2013 Gary Jones, Gamajo Tech * @license GPL-2.0+ - * @version 1.0.2 + * @version 1.0.3 */ /** @@ -22,7 +22,7 @@ class Gamajo_Dashboard_Glancer { * * @since 1.0.0 * - * @type array + * @var array */ protected $items; @@ -37,6 +37,7 @@ class Gamajo_Dashboard_Glancer { */ public function __construct() { add_action( 'dashboard_glance_items', array( $this, 'show' ), 20 ); + add_action( 'admin_enqueue_scripts', array( $this, 'dashboard_css' ) ); } /** @@ -55,6 +56,7 @@ public function add( $post_types, $statuses = 'publish' ) { // If relevant output action hook has already passed, then no point in proceeding. if ( did_action( 'dashboard_glance_items' ) ) { _doing_it_wrong( __CLASS__, 'Trying to add At a Glance items to dashboard widget afterhook already fired', '1.0.0' ); + return; } @@ -178,15 +180,17 @@ public function get_link_url( array $item ) { */ protected function maybe_link( $text, $href ) { if ( current_user_can( 'edit_posts' ) ) { - return '' . $text . ''; + return '' . esc_html( $text ) . ''; } - return $text; + return '' . esc_html( $text ) . ''; } /** * Wrap number and text within list item markup. * + * The extra work for populating classes is to provide dashicons support. + * * @since 1.0.0 * * @param string $text Text to display. May be wrapped in a link. @@ -194,6 +198,48 @@ protected function maybe_link( $text, $href ) { * @return string Markup for list item. */ protected function get_markup( $text, $post_type ) { - return '
  • ' . $text . '
  • ' . "\n"; + $class = ''; + $classes[] = $post_type . '-count'; + $post_type_object = get_post_type_object( $post_type ); + $menu_icon = isset( $post_type_object->menu_icon ) ? $post_type_object->menu_icon : null; + + if ( 0 === strpos( $menu_icon, 'dashicons-' ) ) { + $classes[] = 'dashicons-before'; + $classes[] = $menu_icon; + } + + $class = join( ' ', sanitize_html_class( $classes ) ); + + return '
  • ' . wp_kses_post( $text ) . '
  • ' . "\n"; + } + + /** + * Add post types icon styling to Dashboard page. + * + * To override the overly-specific core styles, we apply styles to ignore + * the default circle, and with the classes added to the list item (not + * anchor), get dashicons showing there instead. + * + * @since 1.1.0 + * + * @return null Return early if style already added, or the Dashboard page. + */ + public function dashboard_css() { + static $added_style; + + if ( $added_style ) { + return; + } + + $screen = get_current_screen(); + + if ( ! in_array( $screen->base, array( 'dashboard' ), true ) ) { + return; + } + + // Remove default circle, and style dashicons we add via classes. + echo ''; + + $added_style = true; } }