| @@ -1,11 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -// no direct access allowed | |
| 4 | -if (!defined('ABSPATH')) { | |
| 5 | - exit; | |
| 6 | -} | |
| 7 | - | |
| 8 | 3 | /** |
| 9 | 4 | * Check given value empty or not |
| 10 | 5 | * |
| 11 | 6 | * @param [type] $value |
| @@ -59,9 +54,9 @@ | ||
| 59 | 54 | { |
| 60 | 55 | return isset($_SERVER["HTTP_SEC_FETCH_DEST"]) && strtolower($_SERVER["HTTP_SEC_FETCH_DEST"]) === "iframe"; |
| 61 | 56 | // $isIframe = isset($_SERVER["HTTP_SEC_FETCH_DEST"]) && strtolower($_SERVER["HTTP_SEC_FETCH_DEST"]) === "iframe"; |
| 62 | 57 | // if ( $isIframe ) return true; |
| 63 | - // if ( isset($_GET['adminify-iframe']) ) return true; | |
| 58 | + // if ( isset($_GET['adminify-iframe']) ) return true; | |
| 64 | 59 | // return false; |
| 65 | 60 | } |
| 66 | 61 | |
| 67 | 62 | /** |
| @@ -82,60 +77,17 @@ | ||
| 82 | 77 | } |
| 83 | 78 | return admin_url($url); |
| 84 | 79 | } |
| 85 | 80 | |
| 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 | -} | |
| 81 | +function build_menu($menu, $submenu) { | |
| 103 | 82 | |
| 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 | 83 | $admin_menu = []; |
| 116 | - $menu_options = apply_filters('jltwp_adminify_menu_option_compatibility_filter', $menu_options, $menu); | |
| 117 | 84 | |
| 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 | - | |
| 85 | + foreach ($menu as $key => $item) { | |
| 131 | 86 | $menu_slug = $item[2]; |
| 132 | 87 | $menu_title = $item[0]; |
| 133 | 88 | $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 | 89 | $menu_icon = isset($item[6]) ? $item[6] : ''; |
| 137 | - $external_link = (isset($item['external_link']) && $item['external_link'] == 1 ) ? true: false; | |
| 138 | 90 | |
| 139 | 91 | $menu_hook = get_plugin_page_hook($menu_slug, 'admin.php'); |
| 140 | 92 | $menu_file = $menu_slug; |
| 141 | 93 | $pos = strpos($menu_file, '?'); |
| @@ -145,9 +97,9 @@ | ||
| 145 | 97 | } |
| 146 | 98 | |
| 147 | 99 | $url = ''; |
| 148 | 100 | |
| 149 | - $arrParsedUrl = wp_parse_url($menu_slug); | |
| 101 | + $arrParsedUrl = parse_url($menu_slug); | |
| 150 | 102 | if (!empty($arrParsedUrl['scheme'])) { |
| 151 | 103 | if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") { |
| 152 | 104 | $url = $menu_slug; |
| 153 | 105 | } |
| @@ -156,31 +108,21 @@ | ||
| 156 | 108 | ? maybe_network_admin_url('admin.php?page=' . $menu_slug) |
| 157 | 109 | : maybe_network_admin_url($menu_slug); |
| 158 | 110 | } |
| 159 | 111 | |
| 160 | - $admin_menu[$menu_key_id] = [ | |
| 161 | - 'key' => $menu_key_id, | |
| 112 | + $admin_menu[$menu_slug] = [ | |
| 113 | + 'key' => $menu_slug, | |
| 162 | 114 | 'title' => $menu_title, |
| 163 | 115 | 'url' => $url, |
| 164 | 116 | 'name' => $menu_name, |
| 165 | 117 | 'icon' => $menu_icon, |
| 166 | 118 | 'children' => [], |
| 167 | - 'separator' => !empty( $item['separator'] ) ? $item['separator'] : '', | |
| 168 | - 'external_link' => $external_link , | |
| 119 | + 'separator' => !empty( $item['separator'] ) ? $item['separator'] : '' | |
| 169 | 120 | ]; |
| 170 | 121 | |
| 171 | 122 | if (!empty($submenu[$menu_slug])) { |
| 172 | 123 | foreach ($submenu[$menu_slug] as $sub_key => $sub_item) { |
| 173 | 124 | $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 | 125 | $sub_title = $sub_item[0]; |
| 184 | 126 | $sub_name = isset($sub_item[5]) ? $sub_item[5] : ''; |
| 185 | 127 | $sub_icon = isset($sub_item[6]) ? $sub_item[6] : ''; |
| 186 | 128 | |
| @@ -190,13 +132,13 @@ | ||
| 190 | 132 | |
| 191 | 133 | if (false !== $pos) { |
| 192 | 134 | $sub_file = substr($sub_file, 0, $pos); |
| 193 | 135 | } |
| 194 | - | |
| 195 | - | |
| 136 | + | |
| 137 | + | |
| 196 | 138 | $sub_url = ''; |
| 197 | 139 | |
| 198 | - $arrParsedUrl = wp_parse_url($sub_slug); | |
| 140 | + $arrParsedUrl = parse_url($sub_slug); | |
| 199 | 141 | if (!empty($arrParsedUrl['scheme'])) { |
| 200 | 142 | if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") { |
| 201 | 143 | $sub_url = $sub_slug; |
| 202 | 144 | } |
| @@ -204,153 +146,18 @@ | ||
| 204 | 146 | $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 | 147 | ? maybe_network_admin_url('admin.php?page=' . $sub_slug) |
| 206 | 148 | : maybe_network_admin_url($sub_slug); |
| 207 | 149 | } |
| 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, | |
| 150 | + | |
| 151 | + $admin_menu[$menu_slug]['children'][$sub_slug] = [ | |
| 152 | + 'key' => $sub_slug, | |
| 153 | + 'title' => $sub_title, | |
| 154 | + 'url' => $sub_url, | |
| 155 | + 'name' => $sub_name, | |
| 156 | + 'icon' => $sub_icon, | |
| 243 | 157 | ]; |
| 244 | 158 | } |
| 245 | 159 | } |
| 246 | 160 | } |
| 247 | 161 | |
| 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 | 162 | return $admin_menu; |
| 328 | -} | |
| 329 | - | |
| 330 | -/** | |
| 331 | -* Recursively replace all occurrences of & 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 & with & in $indicator keys | |
| 345 | - $array[$key] = str_replace('&', '&', $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 | 163 | } |