options = (array) AdminSettings::get_instance()->get( 'admin_bar_settings' );
$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',
] );
// Check Adminify Setup Wizard Page
if ( !empty($_GET['page']) && 'wp-adminify-setup-wizard' == $_GET['page'] ) {
return;
}
add_action( 'plugins_loaded', [ $this, 'initialize' ] );
add_action( 'wp_admin_bar_class', [ $this, 'load_wp_admin_bar_class' ] );
add_action( 'adminify/before/secondary_menu', [ $this, 'before_secondary_menu' ] );
}
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' ) {
add_action( 'admin_init', [ $this, 'jltwp_adminify_add_admin_bar' ] );
}
// Remove Unnecessary Menus from Admin bar
// add_action('wp_before_admin_bar_render', [$this, 'jltma_adminify_remove_admin_bar_menus'], 0);
add_filter( 'admin_body_class', [ $this, 'admin_bar_body_class' ] );
add_action( 'admin_head', [ $this, 'jltwp_adminify_admin_bar_css' ], 999 );
add_action( 'wp_ajax_adminify_all_search', [ $this, 'adminify_all_search' ] );
add_action( 'wp_ajax_wp_adminify_color_mode', [ $this, 'wp_adminify_color_mode' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'jltwp_adminify_admin_scripts' ], 100 );
// Screen Option and Help Tab
add_action(
'admin_head',
[ $this, 'jltwp_adminify_remove_screen_options' ],
10,
3
);
add_action( 'admin_head', [ $this, 'jltwp_adminify_remove_help_tab' ] );
} else {
// Admin bar Frontend settings
$frontend_admin = ( !empty($this->options['admin_bar_hide_frontend']) ? $this->options['admin_bar_hide_frontend'] : 'show' );
$this->jltwp_adminify_front_bar();
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()
{
if ( !empty($this->options['admin_bar_search']) ) {
?>
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 jltwp_adminify_admin_scripts()
{
global $pagenow ;
if ( !is_user_logged_in() && $pagenow != 'wp-login.php' ) {
return;
}
if ( is_admin_bar_showing() ) {
}
wp_enqueue_style( 'wp-adminify-admin-bar' );
wp_localize_script( 'wp-adminify-admin', 'WPAdminify', $this->adminify_create_admin_bar_js_object() );
$this->admin_topbar_loader_css();
// wp_enqueue_style('wp-adminify-admin-bar', WP_ADMINIFY_ASSETS . 'css/admin-bar.css', false, WP_ADMINIFY_VER);
// wp_enqueue_script('wp-adminify-admin', WP_ADMINIFY_ASSETS . 'js/wp-adminify.js', ['jquery'], WP_ADMINIFY_VER, true);
// wp_localize_script('wp-adminify-admin', 'WPAdminify', $this->adminify_create_admin_bar_js_object());
}
public function adminify_create_admin_bar_js_object()
{
return [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'security_nonce' => wp_create_nonce( 'adminify-admin-bar-security-nonce' ),
'notice_nonce' => wp_create_nonce( 'adminify-notice-nonce' ),
];
}
/**
* Preloader
*
* @return void
*/
public function admin_topbar_loader_css()
{
$output_css = '';
$topbar_wireframe_img = WP_ADMINIFY_ASSETS_IMAGE . 'topbar-wireframe.svg';
$output_css .= '.js .wp-adminify-topbar-loader{background: url(' . esc_url( $topbar_wireframe_img ) . '); }';
echo '' ;
}
/**
* Save Color Mode by Ajax
*
* @return void
*/
public function wp_adminify_color_mode()
{
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && check_ajax_referer( 'adminify-admin-bar-security-nonce', 'security' ) > 0 ) {
$admin_bar_mode = AdminSettings::get_instance()->get();
if ( !empty($_POST['key']) ) {
$key = sanitize_key( $_POST['key'] );
$value = Utils::clean_ajax_input( wp_unslash( $_POST['value'] ) );
if ( $key == '' ) {
$message = __( 'No Color Mode supplied to save', 'adminify' );
echo Utils::ajax_error_message( $message ) ;
die;
}
}
// Light/Dark Mode
if ( $key === 'color_mode' ) {
$admin_bar_mode['admin_bar_mode'] = $value;
$admin_bar_mode['enable_schedule_dark_mode'] = false;
update_option( '_wpadminify', $admin_bar_mode );
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, '_wpadminify_preferences', true );
if ( is_array( $current ) ) {
$current[$key] = $value;
} else {
$current = [];
$current[$key] = $value;
}
$state = update_user_meta( $userid, '_wpadminify_preferences', $current );
if ( $state ) {
$returndata = [];
$returndata['success'] = true;
$returndata['message'] = __( 'Preferences saved', 'adminify' );
echo json_encode( $returndata ) ;
} else {
$message = __( 'Unable to save user preferences', 'adminify' );
echo Utils::ajax_error_message( $message ) ;
die;
}
}
}
}
/**
* Search Everything
*
* @return void
*/
public function adminify_all_search()
{
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && check_ajax_referer( 'adminify-admin-bar-security-nonce', 'security' ) > 0 ) {
if ( !empty($_POST['search']) ) {
$term = sanitize_text_field( wp_unslash( $_POST['search'] ) );
}
// Search Arguments
$args = [
'numberposts' => -1,
's' => $term,
'post_status' => [
'publish',
'pending',
'draft',
'future',
'private',
'inherit'
],
];
// 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
$all_comments = get_comments();
// Get All Users
$all_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
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);
// }
ob_start();
?>
s found' ) ;
?>
get();
$admin_bar_mode = ( !empty($admin_bar_mode['admin_bar_mode']) ? $admin_bar_mode['admin_bar_mode'] : '' );
$output_css = '';
$output_css .= '';
echo Utils::wp_kses_custom( $output_css ) ;
}
// 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 jltwp_adminify_add_admin_bar()
{
// For Testing Admin Bar on Setup Wizard
// add_action('admin_head', [$this, 'jltwp_adminify_render_admin_bar']);
add_action( 'in_admin_header', [ $this, 'jltwp_adminify_render_admin_bar' ], -999999999 );
// on frontend area
add_action( 'wp_head', [ $this, 'jltwp_adminify_render_admin_bar' ] );
}
public function jltwp_adminify_render_admin_bar()
{
global $pagenow ;
if ( !is_user_logged_in() && $pagenow != 'wp-login.php' ) {
return;
}
if ( !is_admin_bar_showing() ) {
return false;
}
global $wp_admin_bar ;
if ( empty($wp_admin_bar) ) {
return false;
}
$admin_bar_mode = AdminSettings::get_instance()->get();
$admin_bar_mode = ( empty($admin_bar_mode['admin_bar_mode']) ? 'light' : $admin_bar_mode['admin_bar_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']) === 'top' ) {
$admin_bar_position = 'top_bar';
} elseif ( !empty($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
//
?>
options['admin_bar_user_offcanvas_menu']) ) {
?>
get();
$menu_layout = (array) $admin_bar_mode['menu_layout_settings'];
// Menu Layouts
$menu_layout = ( !empty($admin_bar_mode['menu_layout_settings']) ? $admin_bar_mode['menu_layout_settings'] : '' );
$menu_mode = ( !empty($menu_layout['menu_mode']) ? $menu_layout['menu_mode'] : 'classic' );
$menu_layout = ( !empty($menu_layout['layout_type']) ? $menu_layout['layout_type'] : 'vertical' );
$admin_bar_logo_type = ( !empty($admin_bar_mode['admin_bar_logo_type']) ? $admin_bar_mode['admin_bar_logo_type'] : 'image_logo' );
$light_mode = ( !empty($admin_bar_mode['admin_bar_light_mode']) ? $admin_bar_mode['admin_bar_light_mode'] : '' );
if ( $admin_bar_logo_type == 'image_logo' ) {
// Logo Image
if ( !empty($light_mode['admin_bar_light_logo']['url']) ) {
$light_logo = $light_mode['admin_bar_light_logo']['url'];
} else {
if ( $menu_layout == 'vertical' && $menu_mode == 'icon_menu' ) {
$light_logo = WP_ADMINIFY_ASSETS_IMAGE . 'logos/logo-text-light.svg';
} else {
$light_logo = WP_ADMINIFY_ASSETS_IMAGE . 'logos/logo-text-light.svg';
}
}
} elseif ( $admin_bar_logo_type == 'text_logo' ) {
// Text Logo
if ( $admin_bar_mode['admin_bar_mode'] == 'light' ) {
$text_logo = $light_mode['admin_bar_light_logo_text'];
}
}
// Logo Size
$light_width = ( isset( $light_mode['light_logo_size']['width'] ) ? $light_mode['light_logo_size']['width'] : '150' );
$light_height = ( isset( $light_mode['light_logo_size']['height'] ) ? $light_mode['light_logo_size']['height'] : '45' );
// Dark Logo
$dark_mode = ( !empty($admin_bar_mode['admin_bar_dark_mode']) ? $admin_bar_mode['admin_bar_dark_mode'] : '' );
if ( $admin_bar_logo_type == 'image_logo' ) {
// Dark Logo Image
if ( isset( $dark_mode['admin_bar_dark_logo']['url'] ) && $dark_mode['admin_bar_dark_logo']['url'] ) {
$dark_logo = $dark_mode['admin_bar_dark_logo']['url'];
} else {
if ( $menu_layout == 'vertical' && $menu_mode === 'icon_menu' ) {
$dark_logo = WP_ADMINIFY_ASSETS_IMAGE . 'logos/logo-text-dark.svg';
} else {
$dark_logo = WP_ADMINIFY_ASSETS_IMAGE . 'logos/logo-text-dark.svg';
}
}
} elseif ( $admin_bar_logo_type == 'text_logo' ) {
// Text Logo
if ( $admin_bar_mode['admin_bar_mode'] == 'dark' ) {
$text_logo = $dark_mode['admin_bar_dark_logo_text'];
}
}
// Dark Logo Size
$dark_width = ( isset( $dark_mode['dark_logo_size']['width'] ) ? $dark_mode['dark_logo_size']['width'] : '150' );
$dark_height = ( isset( $dark_mode['dark_logo_size']['height'] ) ? $dark_mode['dark_logo_size']['height'] : '45' );
?>
options['admin_bar_new_button_user_roles']) ? $this->options['admin_bar_new_button_user_roles'] : '' );
if ( $restricted_user ) {
if ( Utils::restrict_for( $this->options['admin_bar_new_button_user_roles'] ) ) {
$wp_admin_bar->remove_menu( 'new-content' );
return;
}
}
$wp_admin_bar->remove_menu( 'wp-logo' );
$wp_admin_bar->remove_menu( 'site-name' );
$wp_admin_bar->remove_menu( 'updates' );
$wp_admin_bar->remove_menu( 'menu-toggle' );
}
}