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

345 lines 12.4 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 $menu_icon = isset($item[6]) ? $item[6] : '';
130 $external_link = (isset($item['external_link']) && $item['external_link'] == 1 ) ? true: false;
131
132 $menu_hook = get_plugin_page_hook($menu_slug, 'admin.php');
133 $menu_file = $menu_slug;
134 $pos = strpos($menu_file, '?');
135
136 if (false !== $pos) {
137 $menu_file = substr($menu_file, 0, $pos);
138 }
139
140 $url = '';
141
142 $arrParsedUrl = parse_url($menu_slug);
143 if (!empty($arrParsedUrl['scheme'])) {
144 if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") {
145 $url = $menu_slug;
146 }
147 } else {
148 $url = ( ! empty($menu_hook) || ( ( 'index.php' !== $menu_slug ) && file_exists(WP_PLUGIN_DIR . "/$menu_file") && ! file_exists(ABSPATH . "/wp-admin/$menu_file") ) )
149 ? maybe_network_admin_url('admin.php?page=' . $menu_slug)
150 : maybe_network_admin_url($menu_slug);
151 }
152
153 $admin_menu[$menu_slug] = [
154 'key' => $menu_slug,
155 'title' => $menu_title,
156 'url' => $url,
157 'name' => $menu_name,
158 'icon' => $menu_icon,
159 'children' => [],
160 'separator' => !empty( $item['separator'] ) ? $item['separator'] : '',
161 'external_link' => $external_link ,
162 ];
163
164 if (!empty($submenu[$menu_slug])) {
165 foreach ($submenu[$menu_slug] as $sub_key => $sub_item) {
166 $external_link = false;
167 if( isset($optiongroup['submenu'][$sub_item[2]])){
168 $external_link = ($optiongroup['submenu'][$sub_item[2]]['external_link'] == 1)? true : false ;
169 }
170 $sub_slug = $sub_item[2];
171 $sub_title = $sub_item[0];
172 $sub_name = isset($sub_item[5]) ? $sub_item[5] : '';
173 $sub_icon = isset($sub_item[6]) ? $sub_item[6] : '';
174
175 $sub_menu_hook = get_plugin_page_hook($sub_slug, $menu_slug);
176 $sub_file = $sub_slug;
177 $pos = strpos($sub_file, '?');
178
179 if (false !== $pos) {
180 $sub_file = substr($sub_file, 0, $pos);
181 }
182
183
184 $sub_url = '';
185
186 $arrParsedUrl = parse_url($sub_slug);
187 if (!empty($arrParsedUrl['scheme'])) {
188 if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") {
189 $sub_url = $sub_slug;
190 }
191 } else {
192 $sub_url = ( ! empty($sub_menu_hook) || ( ( 'index.php' !== $sub_slug ) && file_exists(WP_PLUGIN_DIR . "/$sub_file") && ! file_exists(ABSPATH . "/wp-admin/$sub_file") ) )
193 ? maybe_network_admin_url('admin.php?page=' . $sub_slug)
194 : maybe_network_admin_url($sub_slug);
195 }
196
197 // Wrong Menu/Submenu Links
198
199 // Support for White Label Plugin Url
200 if ('white-label' === $sub_slug) {
201 $sub_url = admin_url('options-general.php?page=white-label');
202 }
203
204 // JetFormBuilder
205 if ('jet-form-builder' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder'); }
206 if ('jet-form-builder' === $sub_slug) { $sub_url = admin_url('post-new.php?post_type=jet-form-builder'); }
207 if ('jfb-settings' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-settings'); }
208 if ('jfb-addons' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-addons'); }
209 if ('jfb-payments' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-payments'); }
210 if ('jfb-records' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-records'); }
211
212 // WP Adminify Support - open in new tab
213 if ('adminify-support' === $sub_slug) {
214 $sub_url = \WPAdminify\Inc\Admin\AdminSettings::support_url();
215 $external_link = true;
216 }
217
218 // WP Adminify Pricing/Upgrade - open in new tab
219 if ('wp-adminify-settings-pricing' === $sub_slug) {
220 $sub_url = 'https://wpadminify.com/pricing';
221 $external_link = true;
222 }
223
224 $admin_menu[$menu_slug]['children'][$sub_slug] = [
225 'key' => $sub_slug,
226 'title' => $sub_title,
227 'url' => $sub_url,
228 'name' => $sub_name,
229 'icon' => $sub_icon,
230 'external_link' => $external_link,
231 ];
232 }
233 }
234 }
235
236 // Elementor 3rd-level flyout menu integration
237 // Grabs Quick Start, Settings, Tools, Role Manager, etc. from Elementor's sidebar navigation
238 // Wrapped in Throwable catch so any Elementor API change degrades gracefully
239 try {
240 $elementor_flyout_class = '\Elementor\Modules\EditorOne\Classes\Menu_Data_Provider';
241
242 if (class_exists($elementor_flyout_class)) {
243 $elementor_menu_key = isset($admin_menu['elementor-home']) ? 'elementor-home' :
244 (isset($admin_menu['elementor']) ? 'elementor' : null);
245
246 if ($elementor_menu_key && isset($admin_menu[$elementor_menu_key]['children']['elementor'])
247 && method_exists($elementor_flyout_class, 'instance')
248 ) {
249 $menu_data_provider = $elementor_flyout_class::instance();
250
251 // Try known method names in order: current API → known alternates
252 $flyout_items = [];
253 $method_candidates = [
254 'get_third_level_data' => ['editor_flyout'], // Current Elementor API
255 'get_editor_flyout_data' => [], // Legacy / alternate
256 'get_level3_items' => [], // Fallback
257 ];
258
259 foreach ($method_candidates as $method => $args) {
260 if (!method_exists($menu_data_provider, $method)) {
261 continue;
262 }
263
264 $result = call_user_func_array([$menu_data_provider, $method], $args);
265
266 if (is_array($result)) {
267 // Normalize: result might wrap items under an 'items' key or be the array itself
268 $flyout_items = isset($result['items']) && is_array($result['items'])
269 ? $result['items']
270 : $result;
271 }
272 break;
273 }
274
275 if (!empty($flyout_items)) {
276 $flyout_children = [];
277
278 foreach ($flyout_items as $item) {
279 if (!is_array($item)) {
280 continue;
281 }
282
283 // Flexible key mapping — tolerate renamed fields
284 $slug = $item['slug'] ?? ($item['id'] ?? '');
285 $label = $item['label'] ?? ($item['title'] ?? '');
286 $url = $item['url'] ?? ($item['link'] ?? '');
287
288 if (empty($slug) || empty($label)) {
289 continue;
290 }
291
292 $flyout_children[$slug] = [
293 'key' => $slug,
294 'title' => $label,
295 'url' => $url,
296 'icon' => $item['icon'] ?? '',
297 'name' => '',
298 'is_flyout_child' => true,
299 'external_link' => false,
300 ];
301 }
302
303 if (!empty($flyout_children)) {
304 $admin_menu[$elementor_menu_key]['children']['elementor']['children'] = $flyout_children;
305 $admin_menu[$elementor_menu_key]['children']['elementor']['has_flyout_children'] = true;
306 }
307 }
308 }
309 }
310 } catch (\Throwable $e) {
311 // Silently degrade — menu renders without flyout items
312 }
313
314 $admin_menu = jlt_adminify_replaceAmpersandInHref($admin_menu, 'url');
315 return $admin_menu;
316 }
317
318 /**
319 * Recursively replace all occurrences of &amp; with & in an array.
320 *
321 * @see https://wordpress.org/support/topic/automatically-adding-amp-in-url/
322 * @param array $array The input array to process.
323 * @return array The updated array with replacements.
324 */
325 function jlt_adminify_replaceAmpersandInHref($array, $indicator='href') {
326
327 foreach ($array as $key => $value) {
328 if (is_array($value)) {
329 // Recursively process child arrays
330 $array[$key] = jlt_adminify_replaceAmpersandInHref($value, $indicator);
331 } elseif ($key === $indicator && is_string($value)) {
332 // Replace &amp; with & in $indicator keys
333 $array[$key] = str_replace('&amp;', '&', $value);
334 }
335 }
336 return $array;
337 }
338
339 function jlt_adminify_sluggify_with_underscores($string) {
340 $slug = sanitize_title($string);
341 $slug = str_replace('-', '_', $slug);
342
343 return $slug;
344 }
345