PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.14
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.14
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / functions.php

functions.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.1.14, at Inc/functions.php

352 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Check given value empty or not
5 *
6 * @param [type] $value
7 *
8 * @return void
9 */
10 function check_is_empty($value, $default = '')
11 {
12 $value = !empty(esc_attr($value)) ? $value : $default;
13 return $value;
14 }
15
16
17 // WP Adminify function for get an option
18 if (!function_exists('jltwp_adminify_get_option')) {
19 function jltwp_adminify_get_option($option = '', $default = null)
20 {
21 $options = [];
22 // if (is_multisite() && is_site_wide('wp-adminify/wp-adminify.php')) {
23 $options = (array) \WPAdminify\Inc\Admin\AdminSettings::get_instance()->get();
24 // }
25 return (isset($options[$option])) ? $options[$option] : $default;
26 }
27 }
28
29 function is_site_wide($plugin)
30 {
31 if (!is_multisite()) {
32 return false;
33 }
34
35 $plugins = get_site_option('active_sitewide_plugins');
36 if (isset($plugins[$plugin])) {
37 return true;
38 }
39
40 return false;
41 }
42
43
44
45
46 /**
47 * Check if the request is coming from an iframe.
48 *
49 * @param None
50 * @throws None
51 * @return bool
52 */
53 function is_iframe()
54 {
55 return isset($_SERVER["HTTP_SEC_FETCH_DEST"]) && strtolower($_SERVER["HTTP_SEC_FETCH_DEST"]) === "iframe";
56 // $isIframe = isset($_SERVER["HTTP_SEC_FETCH_DEST"]) && strtolower($_SERVER["HTTP_SEC_FETCH_DEST"]) === "iframe";
57 // if ( $isIframe ) return true;
58 // if ( isset($_GET['adminify-iframe']) ) return true;
59 // return false;
60 }
61
62 /**
63 * Load a template file.
64 *
65 * @param string $template_name The name of the template file to load.
66 * @throws None
67 * @return void
68 */
69 function adminify_load_template($template_name)
70 {
71 require_once WP_ADMINIFY_PATH . 'Inc/Admin/Frames/Templates/' . $template_name;
72 }
73
74 function maybe_network_admin_url($url) {
75 if ( is_network_admin() ) {
76 return network_admin_url($url);
77 }
78 return admin_url($url);
79 }
80
81 /**
82 * User Roles Slug from Names
83 *
84 * @param [type] $user_roles
85 *
86 * @return void
87 */
88 function jltwp_adminify_menu_roles($user_roles = [])
89 {
90 $disabled_for_roles = [];
91 if (!empty( $user_roles)) {
92 foreach ($user_roles as $usr_key) {
93 $disabled_for_roles[] = strtolower(str_replace(' ', '_', $usr_key));
94 }
95 }
96 return $disabled_for_roles;
97 }
98
99
100 /**
101 * Build admin menu array.
102 *
103 * @param array $menu Menu array.
104 * @param array $submenu Submenu array.
105 * @param array $menu_options Menu options array.
106 *
107 * @return array Admin menu array.
108 */
109 function jltwp_adminify_build_menu($menu, $submenu, $menu_options) {
110 $admin_menu = [];
111 $menu_options = apply_filters('jltwp_adminify_menu_option_compatibility_filter', $menu_options, $menu);
112
113 foreach ($menu as $key => $item) {
114 if (is_array($menu_options)) {
115 if (isset($menu_options[$item[2]])) {
116 $optiongroup = $menu_options[$item[2]];
117 if (!empty($optiongroup['hidden_for'])) {
118 $disabled_for = jltwp_adminify_menu_roles($optiongroup['hidden_for']);
119 if (\WPAdminify\Inc\Utils::restrict_for($disabled_for)) {
120 continue;
121 }
122 }
123 }
124 }
125
126 $menu_slug = $item[2];
127 $menu_title = $item[0];
128 $menu_name = isset($item[5]) ? $item[5] : '';
129 // Use unique key for custom menu items instead of link URL
130 $menu_key_id = (!empty($menu_name) && strpos($menu_name, 'adminify-custom-menu-') !== false) ? $menu_name : $menu_slug;
131 $menu_icon = isset($item[6]) ? $item[6] : '';
132 $external_link = (isset($item['external_link']) && $item['external_link'] == 1 ) ? true: false;
133
134 $menu_hook = get_plugin_page_hook($menu_slug, 'admin.php');
135 $menu_file = $menu_slug;
136 $pos = strpos($menu_file, '?');
137
138 if (false !== $pos) {
139 $menu_file = substr($menu_file, 0, $pos);
140 }
141
142 $url = '';
143
144 $arrParsedUrl = parse_url($menu_slug);
145 if (!empty($arrParsedUrl['scheme'])) {
146 if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") {
147 $url = $menu_slug;
148 }
149 } else {
150 $url = ( ! empty($menu_hook) || ( ( 'index.php' !== $menu_slug ) && file_exists(WP_PLUGIN_DIR . "/$menu_file") && ! file_exists(ABSPATH . "/wp-admin/$menu_file") ) )
151 ? maybe_network_admin_url('admin.php?page=' . $menu_slug)
152 : maybe_network_admin_url($menu_slug);
153 }
154
155 $admin_menu[$menu_key_id] = [
156 'key' => $menu_key_id,
157 'title' => $menu_title,
158 'url' => $url,
159 'name' => $menu_name,
160 'icon' => $menu_icon,
161 'children' => [],
162 'separator' => !empty( $item['separator'] ) ? $item['separator'] : '',
163 'external_link' => $external_link ,
164 ];
165
166 if (!empty($submenu[$menu_slug])) {
167 foreach ($submenu[$menu_slug] as $sub_key => $sub_item) {
168 $sub_slug = $sub_item[2];
169 // Use unique key for custom submenu items instead of link URL
170 $sub_key_id = isset($sub_item['key']) ? $sub_item['key'] : $sub_slug;
171 $external_link = false;
172 // Look up external_link setting using unique key first, then fall back to slug
173 if( isset($optiongroup['submenu'][$sub_key_id])){
174 $external_link = ($optiongroup['submenu'][$sub_key_id]['external_link'] == 1) ? true : false;
175 } elseif( isset($optiongroup['submenu'][$sub_slug])){
176 $external_link = ($optiongroup['submenu'][$sub_slug]['external_link'] == 1) ? true : false;
177 }
178 $sub_title = $sub_item[0];
179 $sub_name = isset($sub_item[5]) ? $sub_item[5] : '';
180 $sub_icon = isset($sub_item[6]) ? $sub_item[6] : '';
181
182 $sub_menu_hook = get_plugin_page_hook($sub_slug, $menu_slug);
183 $sub_file = $sub_slug;
184 $pos = strpos($sub_file, '?');
185
186 if (false !== $pos) {
187 $sub_file = substr($sub_file, 0, $pos);
188 }
189
190
191 $sub_url = '';
192
193 $arrParsedUrl = parse_url($sub_slug);
194 if (!empty($arrParsedUrl['scheme'])) {
195 if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") {
196 $sub_url = $sub_slug;
197 }
198 } else {
199 $sub_url = ( ! empty($sub_menu_hook) || ( ( 'index.php' !== $sub_slug ) && file_exists(WP_PLUGIN_DIR . "/$sub_file") && ! file_exists(ABSPATH . "/wp-admin/$sub_file") ) )
200 ? maybe_network_admin_url('admin.php?page=' . $sub_slug)
201 : maybe_network_admin_url($sub_slug);
202 }
203
204 // Wrong Menu/Submenu Links
205
206 // Support for White Label Plugin Url
207 if ('white-label' === $sub_slug) {
208 $sub_url = admin_url('options-general.php?page=white-label');
209 }
210
211 // JetFormBuilder
212 if ('jet-form-builder' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder'); }
213 if ('jet-form-builder' === $sub_slug) { $sub_url = admin_url('post-new.php?post_type=jet-form-builder'); }
214 if ('jfb-settings' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-settings'); }
215 if ('jfb-addons' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-addons'); }
216 if ('jfb-payments' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-payments'); }
217 if ('jfb-records' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-records'); }
218
219 // WP Adminify Support - open in new tab
220 if ('adminify-support' === $sub_slug) {
221 $sub_url = \WPAdminify\Inc\Admin\AdminSettings::support_url();
222 $external_link = true;
223 }
224
225 // WP Adminify Pricing/Upgrade - open in new tab
226 if ('wp-adminify-settings-pricing' === $sub_slug) {
227 $sub_url = 'https://wpadminify.com/pricing';
228 $external_link = true;
229 }
230
231 $admin_menu[$menu_key_id]['children'][$sub_key_id] = [
232 'key' => $sub_key_id,
233 'title' => $sub_title,
234 'url' => $sub_url,
235 'name' => $sub_name,
236 'icon' => $sub_icon,
237 'external_link' => $external_link,
238 ];
239 }
240 }
241 }
242
243 // Elementor 3rd-level flyout menu integration
244 // Grabs Quick Start, Settings, Tools, Role Manager, etc. from Elementor's sidebar navigation
245 // Wrapped in Throwable catch so any Elementor API change degrades gracefully
246 try {
247 $elementor_flyout_class = '\Elementor\Modules\EditorOne\Classes\Menu_Data_Provider';
248
249 if (class_exists($elementor_flyout_class)) {
250 $elementor_menu_key = isset($admin_menu['elementor-home']) ? 'elementor-home' :
251 (isset($admin_menu['elementor']) ? 'elementor' : null);
252
253 if ($elementor_menu_key && isset($admin_menu[$elementor_menu_key]['children']['elementor'])
254 && method_exists($elementor_flyout_class, 'instance')
255 ) {
256 $menu_data_provider = $elementor_flyout_class::instance();
257
258 // Try known method names in order: current API → known alternates
259 $flyout_items = [];
260 $method_candidates = [
261 'get_third_level_data' => ['editor_flyout'], // Current Elementor API
262 'get_editor_flyout_data' => [], // Legacy / alternate
263 'get_level3_items' => [], // Fallback
264 ];
265
266 foreach ($method_candidates as $method => $args) {
267 if (!method_exists($menu_data_provider, $method)) {
268 continue;
269 }
270
271 $result = call_user_func_array([$menu_data_provider, $method], $args);
272
273 if (is_array($result)) {
274 // Normalize: result might wrap items under an 'items' key or be the array itself
275 $flyout_items = isset($result['items']) && is_array($result['items'])
276 ? $result['items']
277 : $result;
278 }
279 break;
280 }
281
282 if (!empty($flyout_items)) {
283 $flyout_children = [];
284
285 foreach ($flyout_items as $item) {
286 if (!is_array($item)) {
287 continue;
288 }
289
290 // Flexible key mapping — tolerate renamed fields
291 $slug = $item['slug'] ?? ($item['id'] ?? '');
292 $label = $item['label'] ?? ($item['title'] ?? '');
293 $url = $item['url'] ?? ($item['link'] ?? '');
294
295 if (empty($slug) || empty($label)) {
296 continue;
297 }
298
299 $flyout_children[$slug] = [
300 'key' => $slug,
301 'title' => $label,
302 'url' => $url,
303 'icon' => $item['icon'] ?? '',
304 'name' => '',
305 'is_flyout_child' => true,
306 'external_link' => false,
307 ];
308 }
309
310 if (!empty($flyout_children)) {
311 $admin_menu[$elementor_menu_key]['children']['elementor']['children'] = $flyout_children;
312 $admin_menu[$elementor_menu_key]['children']['elementor']['has_flyout_children'] = true;
313 }
314 }
315 }
316 }
317 } catch (\Throwable $e) {
318 // Silently degrade — menu renders without flyout items
319 }
320
321 $admin_menu = jlt_adminify_replaceAmpersandInHref($admin_menu, 'url');
322 return $admin_menu;
323 }
324
325 /**
326 * Recursively replace all occurrences of &amp; with & in an array.
327 *
328 * @see https://wordpress.org/support/topic/automatically-adding-amp-in-url/
329 * @param array $array The input array to process.
330 * @return array The updated array with replacements.
331 */
332 function jlt_adminify_replaceAmpersandInHref($array, $indicator='href') {
333
334 foreach ($array as $key => $value) {
335 if (is_array($value)) {
336 // Recursively process child arrays
337 $array[$key] = jlt_adminify_replaceAmpersandInHref($value, $indicator);
338 } elseif ($key === $indicator && is_string($value)) {
339 // Replace &amp; with & in $indicator keys
340 $array[$key] = str_replace('&amp;', '&', $value);
341 }
342 }
343 return $array;
344 }
345
346 function jlt_adminify_sluggify_with_underscores($string) {
347 $slug = sanitize_title($string);
348 $slug = str_replace('-', '_', $slug);
349
350 return $slug;
351 }
352