PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.17
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.17
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.17, at Inc/functions.php

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