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 / class-mark-posts-marker.php

class-mark-posts-marker.php in Mark Posts 1.2.1, at admin/class-mark-posts-marker.php

73 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Mark Posts Marker Class.
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 class Mark_Posts_Marker
15 {
16 /**
17 * Build select dropdown with all available markers for the current user.
18 *
19 * @since 1.0.4
20 *
21 * @param $post_id
22 *
23 * @return string select with available markers as option
24 */
25 public function mark_posts_select($post_id = null)
26 {
27
28 // Retrieve post meta value from the database
29 if (isset($post_id)) :
30 $value = get_post_meta($post_id, 'mark_posts_term_id', true);
31 endif;
32
33 // Get marker terms
34 $markers_terms = get_terms('marker', 'hide_empty=0');
35
36 /**
37 * Filter: 'mark_posts_marker_limit' - Allow custom user capabilities for marker terms.
38 *
39 * @since 1.0.4
40 *
41 * @param array $limited Array with marker term names and appropriate user capability
42 */
43 $limited = [];
44 $limited = apply_filters('mark_posts_marker_limit', $limited);
45
46 // Build select
47 $select = '<select id="mark_posts_term_id" name="mark_posts_term_id">';
48 $select .= '<option value="">---</option>';
49
50 foreach ($markers_terms as $marker_term) {
51
52 // Always display current marker
53 if (isset($value) && $marker_term->term_id == $value) {
54 $select .= '<option value="'.$marker_term->term_id.'" data-color="'.$marker_term->description.'" selected="selected">'.$marker_term->name.'</option>';
55 } else {
56 // Check if there is a custom limit
57 if (isset($limited[$marker_term->name])) :
58 // Display markers depending on user capability
59 if (current_user_can($limited[$marker_term->name])) :
60 $select .= '<option value="'.$marker_term->term_id.'" data-color="'.$marker_term->description.'">'.$marker_term->name.'</option>';
61 endif;
62 // Display markers if there is no custom limit defined
63 else :
64 $select .= '<option value="'.$marker_term->term_id.'" data-color="'.$marker_term->description.'">'.$marker_term->name.'</option>';
65 endif;
66 }
67 }
68 $select .= '</select>';
69
70 return $select;
71 }
72 }
73