PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Wordpress / Menu.php
kirki / libraries / framework / Wordpress Last commit date
Constants 3 weeks ago Contracts 3 weeks ago Hooks 3 weeks ago Models 3 weeks ago BaseHook.php 3 weeks ago HookServiceProvider.php 3 weeks ago Menu.php 3 weeks ago User.php 3 weeks ago UserMeta.php 3 weeks ago
Menu.php
152 lines
1 <?php
2
3 /**
4 * Base class for declaring WordPress admin menu pages with title, capability, slug, and icon properties.
5 * Supports main menu and submenu types with a render method calling add_menu_page or add_submenu_page.
6 * Subclasses define is_displayable for conditional visibility.
7 *
8 * @package Framework
9 * @subpackage Wordpress
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Wordpress;
13
14 \defined('ABSPATH') || exit;
15 use Kirki\Framework\Wordpress\Constants\MenuTypes;
16 use Kirki\Framework\Supports\Arr;
17 use Exception;
18 use function Kirki\Framework\collection;
19 class Menu
20 {
21 /**
22 * The page menu type i.e. main menu or submenu
23 *
24 * @var MenuTypes
25 *
26 * @since 1.0.0
27 */
28 protected $menu_type = MenuTypes::MAIN_MENU;
29 /**
30 * The page title
31 *
32 * @var string
33 *
34 * @since 1.0.0
35 */
36 protected $page_title = null;
37 /**
38 * The menu title
39 *
40 * @var string
41 *
42 * @since 1.0.0
43 */
44 protected $menu_title = null;
45 /**
46 * The capabilities
47 *
48 * @var string
49 *
50 * @since 1.0.0
51 */
52 protected $capabilities = null;
53 /**
54 * The menu slug
55 *
56 * @var string
57 *
58 * @since 1.0.0
59 */
60 protected $menu_slug = null;
61 /**
62 * The callback
63 *
64 * @var string
65 *
66 * @since 1.0.0
67 */
68 protected $callback = '__return_false';
69 /**
70 * The icon url
71 *
72 * @var string
73 *
74 * @since 1.0.0
75 */
76 protected $icon_url = null;
77 /**
78 * The position
79 *
80 * @var int
81 *
82 * @since 1.0.0
83 */
84 protected $position = null;
85 /**
86 * The parent slug
87 *
88 * @var string
89 *
90 * @since 1.0.0
91 */
92 protected $parent_slug = null;
93 /**
94 * Create a new instance.
95 *
96 * @return void
97 *
98 * @throws \Exception
99 *
100 * @since 1.0.0
101 */
102 public function __construct()
103 {
104 if (!$this->check_required_properties()) {
105 throw new Exception('Missing required properties for making a menu item');
106 }
107 }
108 /**
109 * Determine whether the displayable.
110 *
111 * @return bool
112 *
113 * @since 1.0.0
114 */
115 public function is_displayable()
116 {
117 return \true;
118 }
119 /**
120 * Check required properties.
121 *
122 * @return void
123 *
124 * @since 1.0.0
125 */
126 protected function check_required_properties()
127 {
128 $properties = [$this->page_title, $this->menu_title, $this->capabilities, $this->menu_slug];
129 if (MenuTypes::SUB_MENU === $this->menu_type) {
130 $properties[] = $this->parent_slug;
131 }
132 return collection($properties)->every(function ($property) {
133 return !empty($property);
134 });
135 }
136 /**
137 * Render the menu
138 *
139 * @return void
140 *
141 * @since 1.0.0
142 */
143 public function render()
144 {
145 if ($this->menu_type === MenuTypes::MAIN_MENU) {
146 add_menu_page($this->page_title, $this->menu_title, $this->capabilities, $this->menu_slug, $this->callback, $this->icon_url, $this->position);
147 } else {
148 add_submenu_page($this->parent_slug, $this->page_title, $this->menu_title, $this->capabilities, $this->menu_slug, $this->callback, $this->position);
149 }
150 }
151 }
152