PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 2.4.8
Admin Columns v2.4.8
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / column / used-by-menu.php
codepress-admin-columns / classes / column Last commit date
comment 10 years ago link 10 years ago media 10 years ago post 10 years ago user 10 years ago acf-placeholder.php 10 years ago actions.php 10 years ago custom-field.php 10 years ago default.php 10 years ago taxonomy.php 10 years ago used-by-menu.php 10 years ago wc-placeholder.php 10 years ago
used-by-menu.php
148 lines
1 <?php
2 /**
3 * Column displaying the menus the item is used in. Supported by all object types that
4 * can be referenced in menus (i.e. posts).
5 *
6 * @since 2.2.5
7 */
8 class CPAC_Column_Used_By_Menu extends CPAC_Column {
9
10 /**
11 * @see CPAC_Column::init()
12 * @since 2.2.5
13 */
14 public function init() {
15
16 parent::init();
17
18 // Properties
19 $this->properties['type'] = 'column-used_by_menu';
20 $this->properties['label'] = __( 'Used by Menu', 'codepress-admin-columns' );
21
22 // Options
23 $this->options['link_to_menu'] = false;
24 }
25
26 /**
27 * @see CPAC_Column::apply_conditional()
28 * @since 2.2.5
29 */
30 function apply_conditional() {
31 if ( ! $this->get_meta_type() ) {
32 return false;
33 }
34 return true;
35 }
36
37 /**
38 * @see CPAC_Column::get_value()
39 * @since 2.2.5
40 */
41 function get_value( $object_id ) {
42
43 $menus = array();
44 if ( $menu_ids = $this->get_raw_value( $object_id ) ) {
45 foreach ( $menu_ids as $menu_id ) {
46 $term = get_term_by( 'id', $menu_id, 'nav_menu' );
47
48 $title = $term->name;
49 if ( 'on' == $this->options->link_to_menu ) {
50 $title = '<a href="' . esc_url( add_query_arg( array( 'menu' => $menu_id ), admin_url('nav-menus.php') ) ) . '">' . $term->name . '</a>';
51 }
52
53 $menus[] = $title;
54 }
55 }
56
57 return implode( ', ', $menus );
58 }
59
60 /**
61 * Get object metatype of the storage model
62 *
63 * @since 2.2.5
64 */
65 function get_meta_type() {
66 $object_type = false;
67 if ( isset( $this->storage_model->taxonomy ) ) {
68 $object_type = $this->storage_model->taxonomy;
69 }
70 elseif ( isset( $this->storage_model->post_type ) ) {
71 $object_type = $this->storage_model->post_type;
72 }
73 return $object_type;
74 }
75
76 /**
77 * @see CPAC_Column::get_raw_value()
78 * @since 2.2.5
79 */
80 function get_raw_value( $object_id ) {
81
82 $object_type = $this->get_meta_type();
83
84
85 $menu_item_ids = get_posts( array(
86 'post_type' => 'nav_menu_item',
87 'numberposts' => -1,
88 'post_status' => 'publish',
89 'fields' => 'ids',
90 'meta_query' => array(
91 array(
92 'key' => '_menu_item_object_id',
93 'value' => $object_id
94 ),
95 array(
96 'key' => '_menu_item_object',
97 'value' => $object_type
98 ),
99 )
100 ) );
101
102 if ( ! $menu_item_ids ) {
103 return false;
104 }
105
106 $menu_ids = wp_get_object_terms( $menu_item_ids, 'nav_menu', array( 'fields' => 'ids') );
107 if ( ! $menu_ids || is_wp_error( $menu_ids ) ) {
108 return false;
109 }
110
111 return $menu_ids;
112 }
113
114 /**
115 * @see CPAC_Column::display_settings()
116 * @since 2.2.5
117 */
118 public function display_settings() {
119
120 $this->display_field_link_to_menu();
121 }
122
123 /**
124 * Display the settings field for selecting whether the column value should link to the corresponding post
125 *
126 * @since 2.2.5
127 */
128 public function display_field_link_to_menu() {
129
130 $field_key = 'link_to_menu';
131 ?>
132 <tr class="column_<?php echo $field_key; ?>">
133 <?php $this->label_view( __( 'Link to menu', 'codepress-admin-columns' ), __( 'This will make the title link to the menu.', 'codepress-admin-columns' ), $field_key ); ?>
134 <td class="input">
135 <label for="<?php $this->attr_id( $field_key ); ?>-on">
136 <input type="radio" value="on" name="<?php $this->attr_name( $field_key ); ?>" id="<?php $this->attr_id( $field_key ); ?>-on"<?php checked( $this->options->link_to_menu, 'on' ); ?> />
137 <?php _e( 'Yes'); ?>
138 </label>
139 <label for="<?php $this->attr_id( $field_key ); ?>-off">
140 <input type="radio" value="off" name="<?php $this->attr_name( $field_key ); ?>" id="<?php $this->attr_id( $field_key ); ?>-off"<?php checked( in_array( $this->options->link_to_menu, array( '', 'off' ) ) ); ?> />
141 <?php _e( 'No'); ?>
142 </label>
143 </td>
144 </tr>
145 <?php
146 }
147
148 }