PluginProbe
Mark Posts / 1.2.1
Mark Posts v1.2.1
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 All 28 releases
mark-posts / admin / views / dashboard.php

dashboard.php in Mark Posts 1.2.1, at admin/views/dashboard.php

92 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Renders the view for the dashboard widget.
4 *
5 * @author Michael Schoenrock <hello@michaelschoenrock.com>, Sven Hofmann <info@hofmannsven.com>
6 * @license GPL-2.0+
7 */
8
9 // If this file is called directly, abort.
10 if (!defined('WPINC')) {
11 die;
12 }
13
14 /**
15 * Get available markers.
16 *
17 * @since 1.0.0
18 */
19 $marker_args = [
20 'hide_empty' => true,
21 ];
22 $markers = get_terms('marker', $marker_args);
23
24 /**
25 * Build marker stats for each post type.
26 *
27 * @since 1.0.8
28 */
29 function get_marker_stats()
30 {
31 // attempt to get the stats from the transient
32 if (false === ($latest_marker_stats = get_transient('marker_posts_stats'))) {
33 $marker_args = [
34 'hide_empty' => true,
35 ];
36 $markers = get_terms('marker', $marker_args);
37 $get_mark_posts_setup = get_option('mark_posts_settings');
38 $mark_posts_posttypes = $get_mark_posts_setup['mark_posts_posttypes'];
39 $marker_stats = '';
40
41 foreach ($mark_posts_posttypes as $mark_posts_posttype) :
42
43 $marked_posts = '';
44
45 foreach ($markers as $marker) :
46 $post_args = [
47 'post_type' => $mark_posts_posttype,
48 'taxonomy' => $marker->taxonomy,
49 'term' => $marker->slug,
50 'post_status' => ['publish', 'pending', 'draft', 'future'],
51 'posts_per_page' => -1,
52 ];
53 $posts = get_posts(apply_filters('mark_posts_dashboard_query', $post_args));
54 $posts_count = count($posts);
55
56 if (!empty($posts_count)) :
57 $marked_posts .= '<li class="mark-posts-info mark-posts-'.$marker->slug.'">';
58 $marked_posts .= '<a a href="edit.php?post_type='.$mark_posts_posttype.'&marker='.$marker->slug.'">'.$posts_count.' '.$marker->name.'</a>';
59 $marked_posts .= '</li>';
60 endif;
61
62 endforeach; // end of marker loop
63
64 $marker_post_type_object = get_post_type_object($mark_posts_posttype);
65
66 if (!empty($marked_posts)) :
67 $marker_stats .= '<h3 class="mark_posts_headline">'.$marker_post_type_object->labels->name.'</h3>';
68 $marker_stats .= '<ul class="markers_right_now">';
69 $marker_stats .= $marked_posts;
70 $marker_stats .= '</ul>';
71 endif;
72
73 endforeach; // end of post type loop
74
75 // set transient
76 set_transient('marker_posts_stats', $marker_stats, 60 * 60 * 12);
77
78 if (!empty($marker_stats)) :
79 return $marker_stats; else :
80 return __('No marked posts yet.', 'mark-posts');
81 endif;
82 } else {
83 return get_transient('marker_posts_stats');
84 }
85 }
86
87 if (!empty($markers)) :
88 echo get_marker_stats();
89 else :
90 _e('No marked posts yet.', 'mark-posts');
91 endif;
92