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 ) || in_array( 'administrator', $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 = []; 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; } } } // Get Taxonomies public static function get_taxonomies() { $args = [ 'public' => true, 'show_ui' => true, ]; $output = 'objects'; $taxonomies = get_taxonomies( $args, $output ); $taxonomies = $taxonomies; return $taxonomies; } // Get Post Types public static function get_post_types() { $args = [ 'public' => true, 'show_ui' => true, ]; $output = 'objects'; $post_types = get_post_types( $args, $output ); $post_types = $post_types; return $post_types; } // Get Post Meta public static function post_meta( $meta_key ) { $meta_key = get_post_meta( get_the_ID(), $meta_key, true ); return $meta_key; } // verfiy current page id public static function jltwp_adminify_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 : WP_ADMINIFY ); echo esc_html( $title ) ; if ( is_multisite() ) { $text = ' | ' . esc_html__( 'Current Blog ID', 'adminify' ) . ': ' . get_current_blog_id(); ?> > ', '?', '[', ']', '{', '}', '|', ':' ], '', $name ); return $class; } public static function jltwp_adminify_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( [ '.php', '.', '/', '?', '=' ], [ '', '_', '_', '_', '_' ], $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.*?>.*?@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 ); } /** * User Defined Settings */ public static function get_user_preference( $key ) { $userid = get_current_user_id(); $current = get_user_meta( $userid, '_wpadminify_preferences', true ); $value = false; if ( is_array( $current ) ) { if ( isset( $current[$key] ) ) { $value = $current[$key]; } } return $value; } /** * 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 = []; $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://wpadminify.com/kb'; } 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://wpadminify.com/support/wp-adminify'; } else { $support = $support; } $help_content = sprintf( __( '%1$s ' . self::docs_icon() . ' Docs ' . self::video_tutorials_icon() . ' Video Tutorial ' . self::fbgroup_icon() . ' Facebook Group ' . self::support_icon() . ' Support', 'adminify' ), $module_name, $docs, $youtube, $facebook_grp, $support ); return $help_content; } // Upgrade to Pro Notice public static function adminify_upgrade_pro( $custom_message = '' ) { $pro_content = ''; $pro_message = ''; if ( empty($custom_message) ) { $pro_message = 'Get Pro Version to Unlock this feature.'; } else { $pro_content = $custom_message; } if ( !empty($custom_message) ) { $pro_message = wp_kses_post( $custom_message ); } $jltwp_pro_notice = sprintf( __( '%s Upgrade to Pro Now!', 'adminify' ), wp_kses_post( $pro_message ) ); $pro_content = '

' . self::wp_kses_custom( $jltwp_pro_notice ) . '

'; return self::wp_kses_custom( $pro_content ); } /** * 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 jltwp_adminify_white_label_upgrade() { ?>

Pro for White Labeling', 'adminify' ) ) ; ?>

%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. ', 'adminify' ), esc_html( WP_ADMINIFY ) ) ; ?>

$name ) { $options[$id] = $name; } } else { $options['no_template'] = __( 'No saved templates found!', 'adminify' ); } return $options; } public static function get_section_template_options() { $type = 'section'; $page_templates = self::jltwp_adminify_get_page_templates( $type ); $options[-1] = __( 'Select', 'adminify' ); if ( count( $page_templates ) ) { foreach ( $page_templates as $id => $name ) { $options[$id] = $name; } } else { $options['no_template'] = __( 'No saved templates found!', 'adminify' ); } return $options; } public static function get_page_template_options() { $type = 'page'; $page_templates = self::jltwp_adminify_get_page_templates( $type ); $options[-1] = __( 'Select', 'adminify' ); if ( count( $page_templates ) ) { foreach ( $page_templates as $id => $name ) { $options[$id] = $name; } } else { $options['no_template'] = __( 'No saved templates found!', 'adminify' ); } return $options; } public static function get_theme_presets( $theme = null ) { $presets = [ 'preset1' => [ '--adminify-preset-background' => '#F9F9F9', '--adminify-menu-bg' => '#ffffff', '--adminify-menu-text-color' => 'rgba(78, 75, 102, 0.72)', '--adminify-admin-bar-bg' => 'var(--adminify-menu-bg)', '--adminify-admin-bar-icon' => '#14142B', '--adminify-admin-bar-input-bg' => '#F1F1F3', '--adminify-admin-bar-input-text' => '#14142B', '--adminify-admin-bar-icon-brightness' => '1', '--adminify-notif-bg-color' => '#FF1C69', '--adminify-text-color' => '#ffffff', '--adminify-btn-bg' => '#0347FF', '--adminify-admin-bar-icon-filter' => '0.5', ], 'preset2' => [ '--adminify-preset-background' => '#F9F9F9', '--adminify-menu-bg' => '#14142B', '--adminify-menu-text-color' => '#ffffff', '--adminify-admin-bar-bg' => 'var(--adminify-menu-bg)', '--adminify-admin-bar-icon' => '#ffffff', '--adminify-admin-bar-input-bg' => '#2b2a3f', '--adminify-admin-bar-input-text' => '#9391A0', '--adminify-admin-bar-icon-brightness' => '11', '--adminify-notif-bg-color' => '#FF1C69', '--adminify-text-color' => '#ffffff', '--adminify-btn-bg' => '#0347FF', '--adminify-admin-bar-icon-filter' => '1', ], ]; // return all presets if ( is_null( $theme ) ) { return $presets; } // return specific preset if ( array_key_exists( $theme, $presets ) ) { return $presets[$theme]; } // specific preset not found return []; } public static function jltwp_adminify_get_page_templates( $type = '' ) { $args = [ 'post_type' => 'elementor_library', 'posts_per_page' => -1, ]; if ( $type ) { $args['tax_query'] = [ [ 'taxonomy' => 'elementor_library_type', 'field' => 'slug', 'terms' => $type, ] ]; } $page_templates = get_posts( $args ); $options = []; if ( !empty($page_templates) && !is_wp_error( $page_templates ) ) { foreach ( $page_templates as $post ) { $options[$post->ID] = $post->post_title; } } return $options; } public static function assets_ext( $ext ) { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { return $ext; } return '.min' . $ext; } public static function wp_kses_atts_map( array $attrs ) { return array_fill_keys( array_values( $attrs ), true ); } public static function wp_kses_custom( $content ) { $allowed_tags = wp_kses_allowed_html( 'post' ); $custom_tags = [ 'select' => self::wp_kses_atts_map( [ 'class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'multiple', 'required', 'size' ] ), 'input' => self::wp_kses_atts_map( [ 'class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'size', 'type', 'checked', 'readonly', 'placeholder', 'value', 'maxlength', 'min', 'max', 'multiple', 'pattern', 'step', 'autocomplete' ] ), 'textarea' => self::wp_kses_atts_map( [ 'class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'rows', 'cols', 'wrap', 'maxlength' ] ), 'option' => self::wp_kses_atts_map( [ 'class', 'id', 'label', 'disabled', 'label', 'selected', 'value' ] ), 'optgroup' => self::wp_kses_atts_map( [ 'disabled', 'label', 'class', 'id' ] ), 'form' => self::wp_kses_atts_map( [ 'class', 'id', 'data', 'style', 'width', 'height', 'accept-charset', 'action', 'autocomplete', 'enctype', 'method', 'name', 'novalidate', 'rel', 'target' ] ), 'svg' => self::wp_kses_atts_map( [ 'class', 'xmlns', 'viewbox', 'width', 'height', 'fill', 'aria-hidden', 'aria-labelledby', 'role' ] ), 'rect' => self::wp_kses_atts_map( [ 'rx', 'width', 'height', 'fill' ] ), 'path' => self::wp_kses_atts_map( [ 'd', 'fill' ] ), 'g' => self::wp_kses_atts_map( [ 'fill' ] ), 'defs' => self::wp_kses_atts_map( [ 'fill' ] ), 'linearGradient' => self::wp_kses_atts_map( [ 'id', 'x1', 'x2', 'y1', 'y2', 'gradientUnits' ] ), 'stop' => self::wp_kses_atts_map( [ 'stop-color', 'offset', 'stop-opacity' ] ), 'style' => self::wp_kses_atts_map( [ 'type' ] ), 'div' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'ul' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'li' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'label' => self::wp_kses_atts_map( [ 'class', 'for' ] ), 'span' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'h1' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'h2' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'h3' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'h4' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'h5' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'h6' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'a' => self::wp_kses_atts_map( [ 'class', 'href', 'target', 'rel' ] ), 'p' => self::wp_kses_atts_map( [ 'class', 'id', 'style', 'data' ] ), 'table' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'thead' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'tbody' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'tr' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'th' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'td' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'i' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'button' => self::wp_kses_atts_map( [ 'class', 'id' ] ), 'nav' => self::wp_kses_atts_map( [ 'class', 'id', 'style' ] ), 'time' => self::wp_kses_atts_map( [ 'datetime' ] ), 'br' => [], 'strong' => [], 'style' => [], 'img' => self::wp_kses_atts_map( [ 'class', 'src', 'alt', 'height', 'width', 'srcset', 'id', 'loading' ] ), ]; $allowed_tags = array_merge_recursive( $allowed_tags, $custom_tags ); return wp_kses( stripslashes_deep( $content ), $allowed_tags ); } }