| 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 |
|
| 213 |
$admin_menu[$menu_slug]['children'][$sub_slug] = [ |
| 214 |
'key' => $sub_slug, |
| 215 |
'title' => $sub_title, |
| 216 |
'url' => $sub_url, |
| 217 |
'name' => $sub_name, |
| 218 |
'icon' => $sub_icon, |
| 219 |
'external_link' => $external_link, |
| 220 |
]; |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
$admin_menu = jlt_adminify_replaceAmpersandInHref($admin_menu, 'url'); |
| 225 |
return $admin_menu; |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Recursively replace all occurrences of & with & in an array. |
| 230 |
* |
| 231 |
* @see https://wordpress.org/support/topic/automatically-adding-amp-in-url/ |
| 232 |
* @param array $array The input array to process. |
| 233 |
* @return array The updated array with replacements. |
| 234 |
*/ |
| 235 |
function jlt_adminify_replaceAmpersandInHref($array, $indicator='href') { |
| 236 |
|
| 237 |
foreach ($array as $key => $value) { |
| 238 |
if (is_array($value)) { |
| 239 |
// Recursively process child arrays |
| 240 |
$array[$key] = jlt_adminify_replaceAmpersandInHref($value, $indicator); |
| 241 |
} elseif ($key === $indicator && is_string($value)) { |
| 242 |
// Replace & with & in $indicator keys |
| 243 |
$array[$key] = str_replace('&', '&', $value); |
| 244 |
} |
| 245 |
} |
| 246 |
return $array; |
| 247 |
} |
| 248 |
|
| 249 |
function jlt_adminify_sluggify_with_underscores($string) { |
| 250 |
$slug = sanitize_title($string); |
| 251 |
$slug = str_replace('-', '_', $slug); |
| 252 |
|
| 253 |
return $slug; |
| 254 |
} |
| 255 |
|