Menu.php
1.33 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace AC\Column;
use AC;
use AC\Column;
use AC\Settings;
/**
* Column displaying the menus the item is used in. Supported by all object types that
* can be referenced in menus (i.e. posts).
* @since 2.2.5
*/
abstract class Menu extends Column {
public function __construct() {
$this->set_type( 'column-used_by_menu' );
$this->set_label( __( 'Menu', 'codepress-admin-columns' ) );
}
/**
* @param $object_id
*
* @return array
* @since 2.2.5
*/
public function get_raw_value( $object_id ) {
return $this->get_menus( $object_id, [ 'fields' => 'ids', 'orderby' => 'name' ] );
}
/**
* @return string
*/
public abstract function get_object_type();
/**
* @return string
*/
public abstract function get_item_type();
/**
* @param int $object_id
*
* @return array
*/
public function get_menu_item_ids( $object_id ) {
$helper = new AC\Helper\Menu();
return $helper->get_ids( $object_id, $this->get_object_type() );
}
/**
* @param int $object_id
* @param array $args
*
* @return array
*/
public function get_menus( $object_id, array $args = [] ) {
$helper = new AC\Helper\Menu();
return $helper->get_terms( $helper->get_ids( $object_id, $this->get_object_type() ), $args );
}
public function register_settings() {
$this->add_setting( new Settings\Column\LinkToMenu( $this ) );
}
}