PluginProbe
Mark Posts / 2.0.0
Mark Posts v2.0.0
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 2.0.0, at admin/views/dashboard.php

90 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 exit;
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 $marked_posts = '';
43
44 foreach ($markers as $marker) {
45 $post_args = [
46 'post_type' => $mark_posts_posttype,
47 'taxonomy' => $marker->taxonomy,
48 'term' => $marker->slug,
49 'post_status' => ['publish', 'pending', 'draft', 'future'],
50 'posts_per_page' => -1,
51 ];
52 $posts = get_posts(apply_filters('mark_posts_dashboard_query', $post_args));
53 $posts_count = count($posts);
54
55 if (!empty($posts_count)) {
56 $marked_posts .= '<li class="mark-posts-info mark-posts-'.$marker->slug.'">';
57 $marked_posts .= '<a a href="edit.php?post_type='.$mark_posts_posttype.'&marker='.$marker->slug.'">'.$posts_count.' '.$marker->name.'</a>';
58 $marked_posts .= '</li>';
59 }
60 } // end of marker loop
61
62 $marker_post_type_object = get_post_type_object($mark_posts_posttype);
63
64 if (!empty($marked_posts)) {
65 $marker_stats .= '<h3 class="mark_posts_headline">'.$marker_post_type_object->labels->name.'</h3>';
66 $marker_stats .= '<ul class="markers_right_now">';
67 $marker_stats .= $marked_posts;
68 $marker_stats .= '</ul>';
69 }
70 } // end of post type loop
71
72 // set transient
73 set_transient('marker_posts_stats', $marker_stats, 60 * 60 * 12);
74
75 if (!empty($marker_stats)) {
76 return $marker_stats;
77 } else {
78 return __('No marked posts yet.', 'mark-posts');
79 }
80 } else {
81 return get_transient('marker_posts_stats');
82 }
83 }
84
85 if (!empty($markers)) {
86 echo get_marker_stats();
87 } else {
88 _e('No marked posts yet.', 'mark-posts');
89 }
90