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