options = (array) AdminSettings::get_instance()->get(); $this->adminify_ui = $this->options['admin_ui']; $global_ui_mode = empty($this->options['light_dark_mode']['admin_ui_mode']) ? 'light' : $this->options['light_dark_mode']['admin_ui_mode']; $current_ui_mode = empty(get_user_meta(get_current_user_id(), 'color_mode', true)) ? $global_ui_mode : get_user_meta(get_current_user_id(), 'color_mode', true); if ( $current_ui_mode === 'dark' || $current_ui_mode === 'system' ) { new DarkModeConflicts(); } // $admin_bar_user_roles = !empty($this->options['admin_bar_user_roles']) ? $this->options['admin_bar_user_roles'] : ''; // if (Utils::restricted_for($admin_bar_user_roles)) { // return; // } // Disable the default admin bar // add_filter('show_admin_bar', '__return_false'); // Add admin-bar support if not already activated // add_theme_support('admin-bar', ['callback' => '__return_false']); // 05-06-2024 // Check Adminify Setup Wizard Page // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change. if (!empty($_GET['page']) && 'wp-adminify-setup-wizard' == sanitize_key(wp_unslash($_GET['page']))) { return; } $this->initialize(); // if (!empty($this->adminify_ui) && !empty($this->options['admin_bar_search'] )) { // add_action('wp_admin_bar_class', [$this, 'load_wp_admin_bar_class']); // add_action('pxlbsadminify/before/secondary_menu', [$this, 'before_secondary_menu']); // } if (is_admin()) { // Switcher for Default UI if (empty($this->adminify_ui)) { if (!empty($this->options['admin_bar_dark_light_btn'])) { add_action('admin_bar_menu', [$this, 'dark_mode_switcher_icon']); } } } } // Add Switcher Icon on Admin Bar Secondary public function dark_mode_switcher_icon($wp_admin_bar) { $args = [ 'parent' => 'top-secondary', 'id' => 'wp-adminify-admin-bar-switcher', 'title' => $this->dark_mode_switcher_dom(), 'meta' => false ]; $wp_admin_bar->add_node($args); } public function dark_mode_switcher_dom() { $global_color_mode = !empty($this->options['light_dark_mode']['admin_ui_mode']) ? $this->options['light_dark_mode']['admin_ui_mode'] : 'light'; $color_mode = empty(get_user_meta(get_current_user_id(), 'color_mode', true))? $global_color_mode : get_user_meta(get_current_user_id(), 'color_mode', true); $color_var = !empty($this->adminify_ui) ? 'var(--adminify-menu-text-color)' : '#fff'; $adminbar_switcher_icon = '
Light
Dark
System
'; return $adminbar_switcher_icon; } public function initialize() { $admin_bar_position = (!empty($this->options['admin_bar_position'])) ? $this->options['admin_bar_position'] : 'top'; if (is_admin()) { if ($admin_bar_position == 'top' || $admin_bar_position == 'bottom') { if (!empty($this->adminify_ui)) { //TODO: not need to adminify ui. alternative use iframe topbar // add_action('admin_init', [$this, 'add_admin_bar']); // } else { add_action('admin_head', [$this, 'legacy_admin_bar_positon']); } } add_action('admin_enqueue_scripts', [$this, 'admin_scripts'], 100); // Remove Unnecessary Menus from Admin bar // add_action('wp_before_admin_bar_render', [$this, 'remove_admin_bar_menus'], 0); // add_filter('admin_body_class', [$this, 'admin_bar_body_class']); // add_action('admin_head', [$this, 'admin_bar_css'], 999); add_action('wp_ajax_pxlbsadminify_all_search', [$this, 'all_search']); add_action('wp_ajax_pxlbsadminify_color_mode', [$this, 'color_mode']); // Screen Option and Help Tab add_action('admin_head', [$this, 'remove_screen_options'], 10, 3); add_action('admin_head', [$this, 'remove_help_tab']); } else { // Admin bar Frontend settings $frontend_admin = (!empty($this->options['admin_bar_hide_frontend'])) ? $this->options['admin_bar_hide_frontend'] : 'show'; // if (jltwp_adminify()->can_use_premium_code__premium_only()) { // if ($frontend_admin == 'show') { // $frontend_admin_roles = (!empty($this->options['admin_bar_hide_frontend_user_roles'])) ? $this->options['admin_bar_hide_frontend_user_roles'] : []; // if (Utils::restricted_for($frontend_admin_roles)) { // $frontend_admin = 'hide'; // } // } // } $this->front_bar(); if ($admin_bar_position == 'bottom') { add_action('init', [$this, 'admin_bar_front_style_init']); } if ($frontend_admin == 'hide') { add_filter('show_admin_bar', '__return_false'); } } } public function before_secondary_menu() { ?>
remove_help_tabs(); } } // Get All registered WP Admin Menus public static function get_wp_admin_menus($thismenu, $thissubmenu) { $options = []; if (!empty($thismenu) && is_array($thismenu)) { foreach ($thismenu as $item) { if (!empty($item[0])) { // the preg_replace removes "Comments" & "Plugins" menu spans. $options[$item[2]] = (preg_replace('/\.*?\<\/span><\/span>/s', '', $item[0])); } } } if (!empty($thissubmenu) && is_array($thissubmenu)) { foreach ($thissubmenu as $items) { foreach ($items as $item) { if (!empty($item[0])) { $options[$item[1]] = (preg_replace('/\.*?\<\/span><\/span>/s', '', $item[0])); } } } } return $options; } public function admin_scripts() { global $pagenow; if ($pagenow == 'wp-login.php' || $pagenow == 'wp-register.php' || $pagenow == 'customize.php') { return; } // Commented on: 9-6-24 if (!empty($this->adminify_ui)) { wp_enqueue_style('wp-adminify-admin-bar'); $this->admin_topbar_loader_css(); } wp_localize_script('adminify-admin', 'PXLBSADMINIFY_ADMINBAR', $this->create_admin_bar_js_object()); } public function create_admin_bar_js_object() { return [ 'ajax_url' => admin_url('admin-ajax.php'), 'security_nonce' => wp_create_nonce('pxlbsadminify-admin-bar-security-nonce'), 'notice_nonce' => wp_create_nonce('pxlbsadminify-notice-nonce'), ]; } /** * Preloader * * @return void */ public function admin_topbar_loader_css() { $output_css = ''; $topbar_wireframe_img = PXLBSADMINIFY_ASSETS_IMAGE . 'topbar-wireframe.svg'; $output_css .= '.js .wp-adminify-topbar-loader{background: url(' . esc_url($topbar_wireframe_img) . '); }'; // Use wp_add_inline_style instead of echo to prevent "headers already sent" errors wp_add_inline_style( 'wp-adminify-admin-bar', wp_strip_all_tags($output_css) ); $screen = get_current_screen(); // Get current screen details if (isset($screen->base) && $screen->base === 'post') { $inline_script = "window.addEventListener('load', function() { const isFullscreenMode = wp.data.select('core/edit-post').isFeatureActive('fullscreenMode'); if (isFullscreenMode) { jQuery('.adminify-top_bar').css({ 'display': 'none !important' }); } });"; wp_add_inline_script( 'adminify-admin', $inline_script ); } } /** * Save Color Mode by Ajax * * @return void */ public function color_mode() { if (defined('DOING_AJAX') && DOING_AJAX) { // Two callers post to this handler with different nonce objects: // - dev/admin/wp-adminify.js uses PXLBSADMINIFY_ADMINBAR.security_nonce // (action: pxlbsadminify-admin-bar-security-nonce) // - dev/admin/frame/utils/uitls.js (React frame topbar dropdown) // uses PXLBSADMINIFY_FRAME.security_nonce (action: adminify_nonce) // Accept either — both are user-bound; failing only one strands the // React frame toggle (the dark-mode dropdown silently 403s). $nonce_ok = ( check_ajax_referer('pxlbsadminify-admin-bar-security-nonce', 'security', false) > 0 ) || ( check_ajax_referer('adminify_nonce', 'security', false) > 0 ); if ( ! $nonce_ok ) { wp_send_json_error( array( 'mess' => __( 'Invalid request.', 'adminify' ) ), 403 ); } // Color mode is per-user preference; require the caller to be // a logged-in user with admin-bar access. if ( ! is_user_logged_in() || ! current_user_can( 'read' ) ) { wp_send_json_error( array( 'mess' => __( 'You are not allowed to perform this action.', 'adminify' ) ), 403 ); } $admin_bar_mode = AdminSettings::get_instance()->get(); if (!empty($_POST['key'])) { $key = sanitize_key($_POST['key']); $value = isset($_POST['value']) ? Utils::clean_ajax_input(wp_unslash($_POST['value'])) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized via Utils::clean_ajax_input(). if ($key == '') { $message = __('No Color Mode supplied to save', 'adminify'); echo wp_json_encode( array( 'error' => true, 'error_message' => $message ) ); die(); } } // Light/Dark Mode if ($key === 'color_mode') { // For User preference $userid = get_current_user_id(); $current = get_user_meta($userid, $key, true); if($current !== $value) { $state = update_user_meta($userid, $key, $value); } die(); } // Screen Options, Help Tabs and WP Hide Links if ($key === 'screen_options_tab' || $key === 'hide_wp_links' || $key === 'adminify_help_tab') { $userid = get_current_user_id(); $current = get_user_meta($userid, 'pxlbsadminify_preferences', true); if (is_array($current)) { $current[$key] = $value; } else { $current = []; $current[$key] = $value; } $state = update_user_meta($userid, 'pxlbsadminify_preferences', $current); if ($state) { $returndata = []; $returndata['success'] = true; $returndata['message'] = __('Preferences saved', 'adminify'); echo wp_json_encode($returndata); } else { $message = __('Unable to save user preferences', 'adminify'); echo wp_json_encode( array( 'error' => true, 'error_message' => $message ) ); die(); } } } } /** * Search Everything * * @return void */ public function all_search() { if (defined('DOING_AJAX') && DOING_AJAX && check_ajax_referer('pxlbsadminify-admin-bar-security-nonce', 'security') > 0) { // Security check - only users who can edit posts should access admin search if (!current_user_can('edit_posts')) { wp_send_json_error(array('message' => __('You do not have permission to perform this action.', 'adminify'))); } $search_text = ''; if (!empty($_POST['search'])) { $search_text = sanitize_text_field(wp_unslash($_POST['search'])); } // Error Handling For Minimum 3 Char if (strlen($search_text) < 3) { wp_send_json_success( [ 'message' => 'Please Enter Minimum 3 Characters' ] ); } // Search Arguments $args = [ 'numberposts' => -1, 's' => $search_text, 'post_status' => ['publish', 'pending', 'draft', 'future', 'private', 'inherit'], // Restrict non-public statuses (private/draft/pending/future) to posts the // current user is allowed to read. Without this, any role holding edit_posts // (e.g. Contributor) could read other authors' unpublished post titles. 'perm' => 'readable', ]; // All Post Types $post_types = $this->get_post_types(); foreach ($post_types as $type) { $args['post_type'][] = $type->name; } // All Categories/Taxonomies $all_taxonomies = get_taxonomies(); // Get Comments — only for users who can moderate them. Otherwise the search // would expose unapproved/pending comment content to roles that cannot see it // in the WordPress admin (e.g. Contributor). $all_comments = current_user_can('moderate_comments') ? get_comments() : []; // Get All Users — only for users who can list users. Prevents leaking user // logins/display names to roles without the list_users capability. $all_users = current_user_can('list_users') ? get_users() : []; // All Users // $blogusers = get_users(); // foreach ($blogusers as $type) { // $name = $type->user_login; // $id = $type->ID; // $args['author__in'][] = $type->ID; // } // // All Menus // $all_admin_menus = self::get_wp_admin_menus(); // All Plugins — only for users who can manage plugins. Prevents leaking the // site's plugin inventory to roles without the activate_plugins capability. $all_plugins = []; if (current_user_can('activate_plugins')) { if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $all_plugins = get_plugins(); } $foundposts = get_posts($args); // $count_items = ''; // if (count($foundposts) > 0) { // $count_items .= count($foundposts); // } elseif (count($all_plugins)) { // $count_items .= count($all_plugins); // } $output_data = [ 'foundposts' => $this->set_edit_url_foundposts($foundposts), 'all_taxonomies' => $this->filter_all_taxonomies($all_taxonomies, $search_text), 'all_comments' => $this->filter_all_comments($all_comments, $search_text), 'all_users' => $this->filter_all_users($all_users, $search_text), 'all_plugins' => $this->filter_all_plugins($all_plugins, $search_text), ]; wp_send_json_success( [ 'data' => wp_json_encode($output_data), ] ); return; ob_start(); ?>

s found'); ?>

post_author; $editurl = get_edit_post_link($item); $public = get_permalink($item); ?> $tax_name, 'hide_empty' => 1, ] ); foreach ($terms as $cat) { if (strpos(strtolower($cat->name), strtolower($term)) === false) { continue; } // $user = get_userdata($cat->term_id); ?> comment_content), strtolower($term)) === false) { continue; } ?> user_login), strtolower($term)) === false) { continue; } ?>
name); ?> taxonomy); ?>
comment_content); ?> comment_type)); ?> user_id)); ?> comment_date)); ?>
display_name); ?> comment_type)); ?> user_id)); ?> user_registered)); ?>
$foundposts, // 'all_taxonomies' => $all_taxonomies, // 'all_comments' => $all_comments, // 'all_users' => $all_users, // 'all_plugins' => $all_plugins, // ]; // echo json_encode($output_data); echo wp_json_encode($foundposts); wp_send_json_success( [ 'data' => $foundposts, ] ); } die(); } /** * Set URL to All Post */ public function set_edit_url_foundposts($foundposts) { $all_posts = []; foreach ($foundposts as $key => $post) { // Defense in depth alongside the query's perm=readable: never surface a post // the current user cannot read (e.g. another author's unpublished content). if (!current_user_can('read_post', $post->ID)) { continue; } $edit_url = get_edit_post_link($post); $all_posts[$key]['title'] = get_the_title($post->ID); $all_posts[$key]['link'] = $edit_url; } return $all_posts; } /** * Search Taxonomies */ public function filter_all_taxonomies($all_taxonomies, $search_text) { $find_taxonomies = []; foreach ($all_taxonomies as $tax_name) { $terms = get_terms( [ 'taxonomy' => $tax_name, 'hide_empty' => 1, ] ); foreach ($terms as $key => $cat) { if (strpos(strtolower($cat->name), strtolower($search_text)) === false) { continue; } $find_taxonomies[$key]['name'] = $cat->name; $find_taxonomies[$key]['link'] = get_edit_term_link($cat); } } return $find_taxonomies; } /** * Search Comments */ public function filter_all_comments($all_comments, $search_text) { $find_comments = []; foreach ($all_comments as $key => $comment) { if (strpos(strtolower($comment->comment_content), strtolower($search_text)) === false) { continue; } $find_comments[$key]['content'] = $comment->comment_content; $find_comments[$key]['link'] = admin_url('comment.php?action=editcomment&c=' . esc_attr($comment->comment_ID)); } return $find_comments; } /** * Search Users */ public function filter_all_users($all_users, $search_text) { $find_users = []; foreach ($all_users as $key => $user) { if (str_contains(strtolower($user->data->user_login), strtolower($search_text)) || str_contains(strtolower($user->data->display_name), strtolower($search_text))) { $find_users[$key]['name'] = $user->data->user_login; $find_users[$key]['display_name'] = $user->data->display_name; $find_users[$key]['link'] = admin_url('user-edit.php?user_id=' . $user->ID); } } return $find_users; } /** * Search Plugins */ public function filter_all_plugins($all_plugins, $search_text) { $find_plugins = []; foreach ($all_plugins as $key => $plugin) { if (strpos(strtolower($plugin['Name']), strtolower($search_text)) === false) { continue; } $find_plugins[] = [ 'name' => $plugin['Name'], 'link' => admin_url('plugins.php') ]; } return $find_plugins; } // Admin Bar Body Class public function admin_bar_body_class($classes) { if (is_admin()) { $classes .= ' wp-adminify-admin-bar'; $admin_bar_position = !empty($this->options['admin_bar_position']) ? $this->options['admin_bar_position'] : 'top'; if ($admin_bar_position === 'top') { $classes .= ' position-top'; } elseif ($admin_bar_position === 'bottom') { $classes .= ' position-bottom'; } if (!empty($this->options['enable_admin_bar'])) { $classes .= ' topbar-disabled'; } } else { global $pagenow; if (!is_user_logged_in() && $pagenow != 'wp-login.php') { return $classes; } $classes[] = 'wp-adminify-admin-bar'; $admin_bar_position = !empty($this->options['admin_bar_position']) ? $this->options['admin_bar_position'] : 'top'; if ($admin_bar_position === 'top') { $classes[] = 'admin-bar-position-top'; } elseif ($admin_bar_position === 'bottom') { $classes[] = 'admin-bar-position-bottom'; } if (!empty($this->options['enable_admin_bar'])) { $classes[] = 'topbar-disabled'; } } return $classes; } public function get_post_types() { if (is_array($this->post_types)) { return $this->post_types; } else { $args = ['public' => true]; $output = 'objects'; $post_types = get_post_types($args, $output); $this->post_types = $post_types; return $post_types; } } public function legacy_admin_bar_positon() { if (!empty($this->options['admin_bar_position']) && $this->options['admin_bar_position'] == 'bottom') { $pxlbsadminify_thirdparty_css = ''; $pxlbsadminify_thirdparty_css .= 'body.wp-adminify.position-bottom { margin-top: -28px; padding-bottom: 28px; } body.wp-adminify.position-bottom.admin-bar #wphead { padding-top: 0; } body.wp-adminify.position-bottom.admin-bar #footer { padding-bottom: 28px; } body.wp-adminify.position-bottom #wpadminbar { top: auto !important; bottom: 0; } body.wp-adminify.position-bottom #wpadminbar .quicklinks .ab-top-menu .menupop .ab-sub-wrapper { bottom: 32px; } body.wp-adminify.position-bottom #wpadminbar .quicklinks .ab-top-menu .menupop .ab-sub-wrapper .ab-submenu .menupop .ab-sub-wrapper { bottom: -9px; }'; echo ''; } } public function add_admin_bar() { // For Testing Admin Bar on Setup Wizard // add_action('admin_head', [$this, 'render_admin_bar']); add_action('in_admin_header', [$this, 'render_admin_bar'], -999999999); // on frontend area add_action('wp_head', [$this, 'render_admin_bar']); } public function render_admin_bar() { global $pagenow; if (!is_user_logged_in() && $pagenow != 'wp-login.php') { return; } // Check Gutenberg Editor Page // if (Utils::is_block_editor_page()) { // return; // } // if (!is_admin_bar_showing()) { // return false; // } // Remove Adminbar from Gutenberg Block Editor Page // if (function_exists('is_gutenberg_page') && is_gutenberg_page()) { // // The Gutenberg plugin is on. // return; // } // if (function_exists('get_current_screen')) { // $current_screen = get_current_screen(); // if (!empty($current_screen->is_block_editor)) { // return; // } // } global $wp_admin_bar; if (empty($wp_admin_bar)) { return false; } $admin_bar_mode = empty($admin_bar_mode['light_dark_mode']['admin_ui_mode']) ? 'light' : $admin_bar_mode['light_dark_mode']['admin_ui_mode']; // Light/Dark Mode $enable_dark_mode = $admin_bar_mode != 'light'; // Screen Option && Hide WP Links $enable_screen_tab = Utils::get_user_preference('screen_options_tab'); $enable_help_tab = Utils::get_user_preference('adminify_help_tab'); // $enable_hide_wp_links = Utils::get_user_preference( 'hide_wp_links' ); // Admin Bar Position if (!empty($this->options['admin_bar_position']) && $this->options['admin_bar_position'] === 'top') { $admin_bar_position = 'top_bar'; } elseif (!empty($this->options['admin_bar_position']) && $this->options['admin_bar_position'] === 'bottom') { $admin_bar_position = 'bottom_bar is-fixed-bottom'; } else { $admin_bar_position = 'top_bar'; } $current_user = wp_get_current_user(); ob_start(); // Temporarily removing Topbar //
// 17-7-23, removed opacity for Conflicting Opacity Issue //
?>
options['light_dark_mode']['admin_ui_logo_type']) ? $this->options['light_dark_mode']['admin_ui_logo_type'] : 'image_logo'; $light_mode = !empty($this->options['light_dark_mode']['admin_ui_light_mode']) ? $this->options['light_dark_mode']['admin_ui_light_mode'] : ''; $light_logo = ''; $light_mini_logo = ''; if ($admin_ui_logo_type == 'image_logo') { if (isset($light_mode['mini_admin_ui_light_logo']['url']) && $light_mode['mini_admin_ui_light_logo']['url']) { $light_mini_logo = $light_mode['mini_admin_ui_light_logo']['url']; } else { $light_mini_logo = PXLBSADMINIFY_ASSETS_IMAGE . 'logos/mini-logo-light.svg'; } // Logo Image if (!empty($light_mode['admin_ui_light_logo']['url'])) { $light_logo = $light_mode['admin_ui_light_logo']['url']; } else { $light_logo = PXLBSADMINIFY_ASSETS_IMAGE . 'logos/logo-text-light.svg'; } } elseif ($admin_ui_logo_type == 'text_logo') { // Text Logo if ($this->options['light_dark_mode']['admin_ui_mode'] == 'light') { $text_logo = $light_mode['admin_ui_light_logo_text']; } } // Logo Size $light_width = !empty($light_mode['light_logo_size']['width']) ? $light_mode['light_logo_size']['width'] : '120'; $light_height = !empty($light_mode['light_logo_size']['height']) ? $light_mode['light_logo_size']['height'] : '32'; // Dark Logo $dark_mode = !empty($this->options['light_dark_mode']['admin_ui_dark_mode']) ? $this->options['light_dark_mode']['admin_ui_dark_mode'] : ''; $dark_logo = ''; $dark_mini_logo = ''; if ($admin_ui_logo_type == 'image_logo') { if (isset($dark_mode['mini_admin_ui_dark_logo']['url']) && $dark_mode['mini_admin_ui_dark_logo']['url']) { $dark_mini_logo = $dark_mode['mini_admin_ui_dark_logo']['url']; } else { $dark_mini_logo = PXLBSADMINIFY_ASSETS_IMAGE . 'logos/mini-logo-dark.svg'; } // Dark Logo Image if (isset($dark_mode['admin_ui_dark_logo']['url']) && $dark_mode['admin_ui_dark_logo']['url']) { $dark_logo = $dark_mode['admin_ui_dark_logo']['url']; } else { $dark_logo = PXLBSADMINIFY_ASSETS_IMAGE . 'logos/logo-text-dark.svg'; } } elseif ($admin_ui_logo_type == 'text_logo') { // Text Logo if ($this->options['light_dark_mode']['admin_ui_mode'] == 'dark') { $text_logo = $dark_mode['admin_ui_dark_logo_text']; } } // Dark Logo Size $dark_width = !empty($dark_mode['dark_logo_size']['width']) ? $dark_mode['dark_logo_size']['width'] : '120'; $dark_height = !empty($dark_mode['dark_logo_size']['height']) ? $dark_mode['dark_logo_size']['height'] : '32'; ?> remove_menu('wp-logo'); $wp_admin_bar->remove_menu('site-name'); $wp_admin_bar->remove_menu('updates'); $wp_admin_bar->remove_menu('menu-toggle'); } }