allcaps); } /** * Get User Roles * * @param [type] $user * * @return void */ static function get_user_roles($user) { return $user->roles; } /** * Check given value empty or not * * @param [type] $value * * @return void */ public static function check_is_empty($value, $default = '') { $value = !empty(esc_attr($value)) ? $value : $default; return $value; } /** * Check given value empty or not * * @param [type] $value * * @return void */ public static function restricted_for($restrict_for) { if (!is_array($restrict_for)) { $restrict_for = ['administrator']; } if (!function_exists('wp_get_current_user')) { include(ABSPATH . "wp-includes/pluggable.php"); } $current_user = wp_get_current_user(); $current_name = $current_user->display_name; $current_roles = $current_user->roles; $all_roles = wp_roles()->get_names(); if (in_array($current_name, $restrict_for)) { return true; } // Super Admin for Multisite if (is_super_admin() && is_multisite()) { if (in_array('Super Admin', $restrict_for)) { return true; } else { return false; } } // Normal Super Admin // if ($current_user->ID === 1) { // if (in_array('Super Admin', $restrict_for)) { // return true; // } else { // return false; // } // } foreach ($current_roles as $role) { $role_name = $all_roles[$role]; if (in_array(strtolower($role_name), $restrict_for)) { return true; } } } /** * Check Site wide plugin settings */ public static function is_site_wide($plugin) { if (!is_multisite()) { return false; } $plugins = get_site_option('active_sitewide_plugins'); if (isset($plugins[$plugin])) { return true; } return false; } /** * Restricts for role / user */ public static function restrict_for($disabled_for) { if (!is_array($disabled_for)) { return false; } require_once(ABSPATH . '/wp-includes/pluggable.php'); if (!function_exists('wp_get_current_user')) { return false; } $current_user = wp_get_current_user(); $current_name = $current_user->display_name; $current_roles = $current_user->roles; $formattedroles = array(); foreach ($disabled_for as $item) { $item = strtolower($item); $item = str_replace(' ', '_', $item); array_push($formattedroles, $item); } if (in_array($current_name, $disabled_for)) { return true; } foreach ($current_roles as $role) { if (in_array($role, $formattedroles)) { return true; } } } //// verfiy current page id public static function jlt_admin_bar_currentpage_id($id) { if (!function_exists("get_current_screen")) return true; $screen = get_current_screen(); return is_object($screen) && $screen->id == $id; } /** * Get Current Admin Page Title * * @param string $title * * @return void */ public static function admin_page_title($title = '') { $title = isset($title) && !empty($title) ? $title : JLT_ADMIN_BAR_EDITOR; echo $title; if (is_multisite()) { $text = ' | ' . esc_html__('Current Blog ID', 'admin-bar') . ': ' . get_current_blog_id(); ?> > ', '?', '[', ']', '{', '}', '|', ':',), '', $name); return $class; } public static function jlt_admin_bar_class_cleanup($string) { //Lower case everything $string = strtolower($string); //Make alphanumeric (removes all other characters) $string = preg_replace("/[^a-z0-9_\s-]/", "", $string); //Clean up multiple dashes or whitespaces $string = preg_replace("/[\s-]+/", " ", $string); //Convert whitespaces and underscore to dash $string = preg_replace("/[\s_]/", "-", $string); return $string; } public static function sanitize_id($url) { $url = preg_replace('/^customize.php\?return=.*$/', 'customize', $url); $url = preg_replace('/(&|&|&)?_wpnonce=([^&]+)/', '', $url); return str_replace(array('.php', '.', '/', '?', '='), array('', '_', '_', '_', '_'), $url); } /** * Strip tags and it's content from the given string. * * @link https://stackoverflow.com/questions/14684077/remove-all-html-tags-from-php-string/#answer-39320168 * * @param string $text The string being stripped. * @return string The stripped string. */ public static function strip_tags_content($text) { $cleanup = preg_replace('@<(\w+)\b.*?>.*?\1>@si', '', $text); $cleanup = wp_strip_all_tags($cleanup); $cleanup = trim($cleanup); return $cleanup; } /** * String to ID * Remove Space replace with underscore and lowercase * * @param void * * @return string */ public static function string_to_id($string) { $string_replace = str_replace(" ", "_", $string); $formatted_string = strtolower($string_replace); return $formatted_string; } /** * ID to String * Remove Space replace with underscore and lowercase * * @param void * * @return string */ public static function id_to_string($string) { $string_replace = str_replace("_", " ", $string); $formatted_string = ucwords($string_replace); return $formatted_string; } /** * Check is Plugin Active * * @param [type] $plugin_basename * * @return boolean */ public static function is_plugin_active($plugin_basename) { include_once(ABSPATH . 'wp-admin/includes/plugin.php'); return is_plugin_active($plugin_basename); } /** * Sanitises and strips tags of input from ajax * @since 1.0.0 * @variables $values = item to clean (array or string) */ public static function clean_ajax_input($values) { if (is_array($values)) { foreach ($values as $index => $in) { if (is_array($in)) { $values[$index] = self::clean_ajax_input($in); } else { $values[$index] = strip_tags($in); } } } else { $values = strip_tags($values); } return $values; } /** * Check Ajax Error Messages * * @param [type] $message * * @return void */ public static function ajax_error_message($message) { $returndata = array(); $returndata['error'] = true; $returndata['error_message'] = $message; return json_encode($returndata); } /** * Get All Updates * Themes, Plugins, Core etc * * @return void */ public static function get_all_updates() { $allupdates = []; $allupdates['total'] = 0; $allupdates['wordpress'] = 0; $allupdates['theme'] = 0; $allupdates['plugin'] = 0; if (!is_admin()) { return $allupdates; } if (!current_user_can('install_plugins')) { return $allupdates; } $updatesTotal = 0; if (is_super_admin() && is_admin()) { $pluginUpdates = get_plugin_updates(); $themeUpdates = get_theme_updates(); $wpUpdates = get_core_updates(); if (isset($wpUpdates[0])) { $wpversion = $wpUpdates[0]->version; global $wp_version; if ($wpversion > $wp_version) { $wpUpdates = 1; } else { $wpUpdates = 0; } } else { $wpUpdates = 0; } $updatesTotal = count($pluginUpdates) + count($themeUpdates) + $wpUpdates; $allupdates['total'] = $updatesTotal; $allupdates['wordpress'] = $wpUpdates; $allupdates['theme'] = $themeUpdates; $allupdates['plugin'] = $pluginUpdates; } return $allupdates; } public static function adminfiy_help_urls($module_name = '', $docs = '', $youtube = '', $facebook_grp = '', $support = '') { $help_content = ''; // Modules if (empty($module_name)) { $module_name = 'Module'; } else { $module_name = $module_name; } // Docs if (empty($docs)) { $docs = 'https://jeweltheme.com/admin-bar-editor/docs'; } else { $docs = $docs; } // youtube if (empty($youtube)) { $youtube = 'https://www.youtube.com/playlist?list=PLqpMw0NsHXV-EKj9Xm1DMGa6FGniHHly8'; } else { $youtube = $youtube; } // facebook_grp if (empty($facebook_grp)) { $facebook_grp = 'https://www.facebook.com/groups/jeweltheme'; } else { $facebook_grp = $facebook_grp; } // Support if (empty($support)) { $support = 'https://www.jeweltheme.com/dashboard/support'; } else { $support = $support; } $help_content = sprintf( __('%1$s ' . Utils::docs_icon() . ' Docs ' . Utils::video_tutorials_icon() . ' Video Tutorial ' . Utils::fbgroup_icon() . ' Facebook Group ' . Utils::support_icon() . ' Support', 'admin-bar'), $module_name, $docs, $youtube, $facebook_grp, $support ); return $help_content; } // Upgrade to Pro Notice public static function jlt_admin_bar_upgrade_pro($custom_message = '') { $pro_content = ''; $pro_message = ''; if (empty($custom_message)) { $pro_message = 'Unlock this feature.'; } else { $pro_content = $custom_message; } if ( !jlt_admin_bar_editor_is_premium() ) { $jltwp_pro_notice = sprintf(__('%s Upgrade to Pro Now!', 'admin-bar'), $pro_message); $pro_content = '
'; return $pro_content; } else { return ''; } } /** * Documentation SVG Icon */ public static function docs_icon() { return ''; } /** * Video Tutorials SVG Icon */ public static function video_tutorials_icon() { return ''; } /** * Facebook Group SVG Icon */ public static function fbgroup_icon() { return ''; } /** * Support SVG Icon */ public static function support_icon() { return ''; } /* White Label Upgrade Pro */ public static function jlt_admin_bar_white_label_upgrade() { ?>
%1$s can be completely re-branded with your own brand Logo, Name and Author Details. Your clients will never know what tools you are using to build their website and will think that this is your own tool set. White-labeling works as long as your license is active. ', 'admin-bar'), JLT_ADMIN_BAR_EDITOR);
_e('', 'admin-bar'); ?>