-
Notifications
You must be signed in to change notification settings - Fork 7
/
class-gamajo-dashboard-rightnow.php
75 lines (68 loc) · 2.12 KB
/
class-gamajo-dashboard-rightnow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Gamajo Dashboard Glancer, for WP 3.7 and earlier.
*
* @package Gamajo\DashboardGlancer
* @author Gary Jones
* @link https://github.com/gamajo/dashboard-glancer
* @copyright 2013 Gary Jones, Gamajo
* @license GPL-2.0-or-later
* @version 1.0.4
*/
/**
* Easily add items to the Right Now Dashboard widget in WordPress 3.7-.
*
* @package Gamajo\DashboardGlancer
* @author Gary Jones
*/
class Gamajo_Dashboard_RightNow extends Gamajo_Dashboard_Glancer {
/**
* Automatically show any registered items.
*
* With this, there's no need to explicitly call show() during the
* `dashboard_glance_items` hook, and items can be registered at any time
* before `dashboard_glance_items` priority 20 (including on earlier hooks).
*
* @since 1.0.0
*/
public function __construct() {
add_action( 'right_now_content_table_end', array( $this, 'show' ), 20 );
}
/**
* Build and return the data and markup for a single item.
*
* If the item count is zero, return an empty string, to avoid visual clutter.
*
* @since 1.0.0
*
* @param array $item Registered item.
* @return string Markup, or empty string if item count is zero.
*/
protected function get_single_item( array $item ) {
$num_posts = wp_count_posts( $item['type'] );
$count = $num_posts->{$item['status']};
if ( ! $count ) {
return '';
}
$href = $this->get_link_url( $item );
$num = $this->maybe_link( number_format_i18n( $count ), $href );
$text = $this->maybe_link( $this->get_label( $item, $count ), $href );
return $this->get_markup( $num . '|' . $text, $item['type'] );
}
/**
* Wrap number and text within table row markup.
*
* @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 ) {
$text_parts = explode( '|', $text );
return '<tr>
<td class="first b ' . sanitize_html_class( 'b-' . $post_type ) . '">' . $text_parts[0] . '</td>
<td class="t ' . sanitize_html_class( $post_type ) . '">' . $text_parts[1] . '</td>
</tr>';
}
}