| 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 |
function build_menu($menu, $submenu) { |
| 82 |
|
| 83 |
$admin_menu = []; |
| 84 |
|
| 85 |
foreach ($menu as $key => $item) { |
| 86 |
$menu_slug = $item[2]; |
| 87 |
$menu_title = $item[0]; |
| 88 |
$menu_name = isset($item[5]) ? $item[5] : ''; |
| 89 |
$menu_icon = isset($item[6]) ? $item[6] : ''; |
| 90 |
|
| 91 |
$menu_hook = get_plugin_page_hook($menu_slug, 'admin.php'); |
| 92 |
$menu_file = $menu_slug; |
| 93 |
$pos = strpos($menu_file, '?'); |
| 94 |
|
| 95 |
if (false !== $pos) { |
| 96 |
$menu_file = substr($menu_file, 0, $pos); |
| 97 |
} |
| 98 |
|
| 99 |
$url = ''; |
| 100 |
|
| 101 |
$arrParsedUrl = parse_url($menu_slug); |
| 102 |
if (!empty($arrParsedUrl['scheme'])) { |
| 103 |
if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") { |
| 104 |
$url = $menu_slug; |
| 105 |
} |
| 106 |
} else { |
| 107 |
$url = ( ! empty($menu_hook) || ( ( 'index.php' !== $menu_slug ) && file_exists(WP_PLUGIN_DIR . "/$menu_file") && ! file_exists(ABSPATH . "/wp-admin/$menu_file") ) ) |
| 108 |
? maybe_network_admin_url('admin.php?page=' . $menu_slug) |
| 109 |
: maybe_network_admin_url($menu_slug); |
| 110 |
} |
| 111 |
|
| 112 |
$admin_menu[$menu_slug] = [ |
| 113 |
'key' => $menu_slug, |
| 114 |
'title' => $menu_title, |
| 115 |
'url' => $url, |
| 116 |
'name' => $menu_name, |
| 117 |
'icon' => $menu_icon, |
| 118 |
'children' => [], |
| 119 |
'separator' => !empty( $item['separator'] ) ? $item['separator'] : '' |
| 120 |
]; |
| 121 |
|
| 122 |
if (!empty($submenu[$menu_slug])) { |
| 123 |
foreach ($submenu[$menu_slug] as $sub_key => $sub_item) { |
| 124 |
$sub_slug = $sub_item[2]; |
| 125 |
$sub_title = $sub_item[0]; |
| 126 |
$sub_name = isset($sub_item[5]) ? $sub_item[5] : ''; |
| 127 |
$sub_icon = isset($sub_item[6]) ? $sub_item[6] : ''; |
| 128 |
|
| 129 |
$sub_menu_hook = get_plugin_page_hook($sub_slug, $menu_slug); |
| 130 |
$sub_file = $sub_slug; |
| 131 |
$pos = strpos($sub_file, '?'); |
| 132 |
|
| 133 |
if (false !== $pos) { |
| 134 |
$sub_file = substr($sub_file, 0, $pos); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
$sub_url = ''; |
| 139 |
|
| 140 |
$arrParsedUrl = parse_url($sub_slug); |
| 141 |
if (!empty($arrParsedUrl['scheme'])) { |
| 142 |
if ($arrParsedUrl['scheme'] === "http" || $arrParsedUrl['scheme'] === "https") { |
| 143 |
$sub_url = $sub_slug; |
| 144 |
} |
| 145 |
} else { |
| 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") ) ) |
| 147 |
? maybe_network_admin_url('admin.php?page=' . $sub_slug) |
| 148 |
: maybe_network_admin_url($sub_slug); |
| 149 |
} |
| 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, |
| 157 |
]; |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
return $admin_menu; |
| 163 |
} |
| 164 |
|