PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.1
Admin Columns v3.1
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 / Menu.php
codepress-admin-columns / classes / Column Last commit date
Comment 8 years ago Link 8 years ago Media 8 years ago Post 8 years ago User 8 years ago Actions.php 8 years ago AjaxValue.php 8 years ago CustomField.php 8 years ago Menu.php 8 years ago Meta.php 8 years ago Placeholder.php 8 years ago RelationInterface.php 8 years ago Taxonomy.php 8 years ago WooCommercePlaceholder.php 8 years ago
Menu.php
118 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Column displaying the menus the item is used in. Supported by all object types that
9 * can be referenced in menus (i.e. posts).
10 *
11 * @since 2.2.5
12 */
13 class AC_Column_Menu extends AC_Column {
14
15 public function __construct() {
16 $this->set_type( 'column-used_by_menu' );
17 $this->set_label( __( 'Menu', 'codepress-admin-columns' ) );
18 }
19
20 /**
21 * @see AC_Column::get_raw_value()
22 * @since 2.2.5
23 */
24 public function get_raw_value( $object_id ) {
25 return $this->get_menus( $object_id, array( 'fields' => 'ids' ) );
26 }
27
28 /**
29 * @return string Object type: 'post', 'page' or 'user'
30 */
31 public function get_object_type() {
32 $object_type = $this->get_post_type();
33
34 if ( ! $object_type ) {
35 $object_type = $this->get_taxonomy();
36 }
37
38 if ( ! $object_type ) {
39 $object_type = $this->get_list_screen()->get_meta_type();
40 }
41
42 return $object_type;
43 }
44
45 /**
46 * @return string
47 */
48 public function get_item_type() {
49 $item_type = $this->get_list_screen()->get_meta_type();
50
51 switch ( $item_type ) {
52 case 'post' :
53 $item_type = 'post_type';
54 break;
55 }
56
57 return $item_type;
58 }
59
60 /**
61 * @param int $object_id
62 *
63 * @return array
64 */
65 public function get_menu_item_ids( $object_id ) {
66 $menu_item_ids = get_posts( array(
67 'post_type' => 'nav_menu_item',
68 'posts_per_page' => -1,
69 'post_status' => 'publish',
70 'fields' => 'ids',
71 'meta_query' => array(
72 array(
73 'key' => '_menu_item_object_id',
74 'value' => $object_id,
75 ),
76 array(
77 'key' => '_menu_item_object',
78 'value' => $this->get_object_type(),
79 ),
80 ),
81 ) );
82
83 return $menu_item_ids;
84 }
85
86 /**
87 * @param int $object_id
88 * @param array $args
89 *
90 * @return array
91 */
92 public function get_menus( $object_id, $args = array() ) {
93
94 $menu_item_ids = $this->get_menu_item_ids( $object_id );
95
96 if ( ! $menu_item_ids ) {
97 return array();
98 }
99
100 $menu_ids = wp_get_object_terms( $menu_item_ids, 'nav_menu', $args );
101
102 if ( ! $menu_ids || is_wp_error( $menu_ids ) ) {
103 return array();
104 }
105
106 return $menu_ids;
107 }
108
109 public function register_settings() {
110 $this->add_setting( new AC_Settings_Column_LinkToMenu( $this ) );
111 }
112
113 public function is_valid() {
114 return in_array( $this->get_list_screen()->get_meta_type(), array( 'post', 'user', 'term', 'comment' ) );
115 }
116
117 }
118