Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  1.0.3
  Add dashicons support
  Change log: Fix Unreleased comparison link
  • Loading branch information
GaryJones committed Jul 31, 2016
2 parents 069ceb7 + 3fcb7d8 commit 5a30eb0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
56 changes: 51 additions & 5 deletions class-gamajo-dashboard-glancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand All @@ -22,7 +22,7 @@ class Gamajo_Dashboard_Glancer {
*
* @since 1.0.0
*
* @type array
* @var array
*/
protected $items;

Expand All @@ -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' ) );
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -178,22 +180,66 @@ public function get_link_url( array $item ) {
*/
protected function maybe_link( $text, $href ) {
if ( current_user_can( 'edit_posts' ) ) {
return '<a href="' . esc_url( $href ) . '">' . $text . '</a>';
return '<a href="' . esc_url( $href ) . '">' . esc_html( $text ) . '</a>';
}

return $text;
return '<span>' . esc_html( $text ) . '</span>';
}

/**
* 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.
* @param string $post_type Post type.
* @return string Markup for list item.
*/
protected function get_markup( $text, $post_type ) {
return '<li class="' . sanitize_html_class( $post_type . '-count' ) . '">' . $text . '</li>' . "\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 '<li class="' . esc_attr( $class ) . '">' . wp_kses_post( $text ) . '</li>' . "\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 '<style type="text/css">#dashboard_right_now li.dashicons-before a:before, #dashboard_right_now li.dashicons span:before {content: none;}#dashboard_right_now li.dashicons-before:before {color: #82878c;margin: 0 5px 0 0;}</style>';

$added_style = true;
}
}

0 comments on commit 5a30eb0

Please sign in to comment.