Menu.php
973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace AC\Helper;
class Menu {
/**
* @param int $object_id
* @param string $object_type
*
* @return int[] Term Ids
*/
public function get_ids( $object_id, $object_type ) {
return get_posts( [
'post_type' => 'nav_menu_item',
'posts_per_page' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'meta_query' => [
[
'key' => '_menu_item_object_id',
'value' => (int) $object_id,
],
[
'key' => '_menu_item_object',
'value' => (string) $object_type,
],
],
] );
}
/**
* @param array $terms_ids
* @param array $args
*
* @return array
* @see WP_Term_Query::__construct() for available $args
*/
public function get_terms( array $terms_ids, array $args = [] ) {
if ( ! $terms_ids ) {
return [];
}
$terms = wp_get_object_terms( $terms_ids, 'nav_menu', $args );
if ( ! $terms || is_wp_error( $terms ) ) {
return [];
}
return $terms;
}
}