| @@ -1,23 +1,85 @@ | ||
| 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 | /** |
| 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 | +/** | |
| 20 | 82 | * User Roles Slug from Names |
| 21 | 83 | * |
| 22 | 84 | * @param [type] $user_roles |
| 23 | 85 | * |
| @@ -22,9 +84,9 @@ | ||
| 22 | 84 | * @param [type] $user_roles |
| 23 | 85 | * |
| 24 | 86 | * @return void |
| 25 | 87 | */ |
| 26 | -function pxlbsadminify_menu_roles($user_roles = []) | |
| 88 | +function jltwp_adminify_menu_roles($user_roles = []) | |
| 27 | 89 | { |
| 28 | 90 | $disabled_for_roles = []; |
| 29 | 91 | if (!empty( $user_roles)) { |
| 30 | 92 | foreach ($user_roles as $usr_key) { |
| @@ -43,11 +105,11 @@ | ||
| 43 | 105 | * @param array $menu_options Menu options array. |
| 44 | 106 | * |
| 45 | 107 | * @return array Admin menu array. |
| 46 | 108 | */ |
| 47 | -function pxlbsadminify_build_menu($menu, $submenu, $menu_options) { | |
| 109 | +function jltwp_adminify_build_menu($menu, $submenu, $menu_options) { | |
| 48 | 110 | $admin_menu = []; |
| 49 | - $menu_options = apply_filters('pxlbsadminify_menu_option_compatibility_filter', $menu_options, $menu); | |
| 111 | + $menu_options = apply_filters('jltwp_adminify_menu_option_compatibility_filter', $menu_options, $menu); | |
| 50 | 112 | |
| 51 | 113 | foreach ($menu as $key => $item) { |
| 52 | 114 | if (is_array($menu_options)) { |
| 53 | 115 | if (isset($menu_options[$item[2]])) { |
| @@ -52,10 +114,10 @@ | ||
| 52 | 114 | if (is_array($menu_options)) { |
| 53 | 115 | if (isset($menu_options[$item[2]])) { |
| 54 | 116 | $optiongroup = $menu_options[$item[2]]; |
| 55 | 117 | if (!empty($optiongroup['hidden_for'])) { |
| 56 | - $disabled_for = pxlbsadminify_menu_roles($optiongroup['hidden_for']); | |
| 57 | - if (\PXLBSAdminify\Inc\Utils::restrict_for($disabled_for)) { | |
| 118 | + $disabled_for = jltwp_adminify_menu_roles($optiongroup['hidden_for']); | |
| 119 | + if (\WPAdminify\Inc\Utils::restrict_for($disabled_for)) { | |
| 58 | 120 | continue; |
| 59 | 121 | } |
| 60 | 122 | } |
| 61 | 123 | } |
| @@ -78,9 +140,9 @@ | ||
| 78 | 140 | } |
| 79 | 141 | |
| 80 | 142 | $url = ''; |
| 81 | 143 | |
| 82 | - $arrParsedUrl = wp_parse_url($menu_slug); | |
| 144 | + $arrParsedUrl = parse_url($menu_slug); | |
| 83 | 145 | if (!empty($arrParsedUrl['scheme'])) { |
| 84 | 146 | if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") { |
| 85 | 147 | $url = $menu_slug; |
| 86 | 148 | } |
| @@ -85,10 +147,10 @@ | ||
| 85 | 147 | $url = $menu_slug; |
| 86 | 148 | } |
| 87 | 149 | } else { |
| 88 | 150 | $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); | |
| 151 | + ? maybe_network_admin_url('admin.php?page=' . $menu_slug) | |
| 152 | + : maybe_network_admin_url($menu_slug); | |
| 91 | 153 | } |
| 92 | 154 | |
| 93 | 155 | $admin_menu[$menu_key_id] = [ |
| 94 | 156 | 'key' => $menu_key_id, |
| @@ -127,9 +189,9 @@ | ||
| 127 | 189 | |
| 128 | 190 | |
| 129 | 191 | $sub_url = ''; |
| 130 | 192 | |
| 131 | - $arrParsedUrl = wp_parse_url($sub_slug); | |
| 193 | + $arrParsedUrl = parse_url($sub_slug); | |
| 132 | 194 | if (!empty($arrParsedUrl['scheme'])) { |
| 133 | 195 | if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") { |
| 134 | 196 | $sub_url = $sub_slug; |
| 135 | 197 | } |
| @@ -134,10 +196,10 @@ | ||
| 134 | 196 | $sub_url = $sub_slug; |
| 135 | 197 | } |
| 136 | 198 | } else { |
| 137 | 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") ) ) |
| 138 | - ? \PXLBSAdminify\Inc\Utils::maybe_network_admin_url('admin.php?page=' . $sub_slug) | |
| 139 | - : \PXLBSAdminify\Inc\Utils::maybe_network_admin_url($sub_slug); | |
| 200 | + ? maybe_network_admin_url('admin.php?page=' . $sub_slug) | |
| 201 | + : maybe_network_admin_url($sub_slug); | |
| 140 | 202 | } |
| 141 | 203 | |
| 142 | 204 | // Wrong Menu/Submenu Links |
| 143 | 205 | |
| @@ -155,9 +217,9 @@ | ||
| 155 | 217 | if ('jfb-records' === $sub_slug) { $sub_url = admin_url('edit.php?post_type=jet-form-builder&page=jfb-records'); } |
| 156 | 218 | |
| 157 | 219 | // WP Adminify Support - open in new tab |
| 158 | 220 | if ('adminify-support' === $sub_slug) { |
| 159 | - $sub_url = \PXLBSAdminify\Inc\Admin\AdminSettings::support_url(); | |
| 221 | + $sub_url = \WPAdminify\Inc\Admin\AdminSettings::support_url(); | |
| 160 | 222 | $external_link = true; |
| 161 | 223 | } |
| 162 | 224 | |
| 163 | 225 | // WP Adminify Pricing/Upgrade - open in new tab |
| @@ -255,9 +317,9 @@ | ||
| 255 | 317 | } catch (\Throwable $e) { |
| 256 | 318 | // Silently degrade — menu renders without flyout items |
| 257 | 319 | } |
| 258 | 320 | |
| 259 | - $admin_menu = pxlbsadminify_replaceAmpersandInHref($admin_menu, 'url'); | |
| 321 | + $admin_menu = jlt_adminify_replaceAmpersandInHref($admin_menu, 'url'); | |
| 260 | 322 | return $admin_menu; |
| 261 | 323 | } |
| 262 | 324 | |
| 263 | 325 | /** |
| @@ -266,14 +328,14 @@ | ||
| 266 | 328 | * @see https://wordpress.org/support/topic/automatically-adding-amp-in-url/ |
| 267 | 329 | * @param array $array The input array to process. |
| 268 | 330 | * @return array The updated array with replacements. |
| 269 | 331 | */ |
| 270 | -function pxlbsadminify_replaceAmpersandInHref($array, $indicator='href') { | |
| 332 | +function jlt_adminify_replaceAmpersandInHref($array, $indicator='href') { | |
| 271 | 333 | |
| 272 | 334 | foreach ($array as $key => $value) { |
| 273 | 335 | if (is_array($value)) { |
| 274 | 336 | // Recursively process child arrays |
| 275 | - $array[$key] = pxlbsadminify_replaceAmpersandInHref($value, $indicator); | |
| 337 | + $array[$key] = jlt_adminify_replaceAmpersandInHref($value, $indicator); | |
| 276 | 338 | } elseif ($key === $indicator && is_string($value)) { |
| 277 | 339 | // Replace & with & in $indicator keys |
| 278 | 340 | $array[$key] = str_replace('&', '&', $value); |
| 279 | 341 | } |
| @@ -278,5 +340,12 @@ | ||
| 278 | 340 | $array[$key] = str_replace('&', '&', $value); |
| 279 | 341 | } |
| 280 | 342 | } |
| 281 | 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; | |
| 282 | 351 | } |