settings = SettingsManager::get_instance(); $this->init_hooks(); } private function init_hooks() { // Admin Bar add_action('wp_before_admin_bar_render', [$this, 'customize_admin_bar']); add_action('wp_enqueue_scripts', [$this, 'enqueue_hide_admin_bar_css']); add_action('admin_enqueue_scripts', [$this, 'enqueue_hide_admin_bar_css']); // Footer add_filter('admin_footer_text', [$this, 'customize_footer_text']); add_filter('update_footer', [$this, 'customize_version_footer'], 999); // Admin Notices if ($this->get_setting('hide_admin_notices')) { add_action('admin_enqueue_scripts', [$this, 'hide_notices_css']); } } private function get_setting($key, $default = '') { return $this->settings->get('interface_control', $key, $default); } public function customize_admin_bar() { global $wp_admin_bar; // Remove WP Logo if ($this->get_setting('remove_wp_logo')) { $wp_admin_bar->remove_menu('wp-logo'); } // Remove Comments if ($this->get_setting('remove_comments_menu')) { $wp_admin_bar->remove_menu('comments'); } // Remove Updates if ($this->get_setting('remove_updates_menu')) { $wp_admin_bar->remove_menu('updates'); } // Custom Items removal $items_to_remove = $this->get_setting('admin_bar_remove_items', []); if (is_array($items_to_remove)) { foreach ($items_to_remove as $item) { $wp_admin_bar->remove_menu($item); } } } public function enqueue_hide_admin_bar_css() { $hide_frontend = $this->get_setting('hide_admin_bar_frontend'); $hide_backend = $this->get_setting('hide_admin_bar_backend'); $should_hide = false; if (!is_admin() && $hide_frontend) { $should_hide = true; } elseif (is_admin() && $hide_backend) { $should_hide = true; } // Role based check (simplified) // If specific roles are set, we check against them // TODO: Implement sophisticated role checking logic if ($should_hide) { echo ''; } } public function customize_footer_text($text) { $custom_text = $this->get_setting('footer_text'); if (!empty($custom_text)) { return wp_kses_post($custom_text); } return $text; } public function customize_version_footer($text) { if ($this->get_setting('hide_wp_version')) { return ''; } return $text; } public function hide_notices_css() { echo ''; } public function render_settings() { // This function will render the HTML for the settings tab for this module // We will make it simple. $settings = [ 'hide_admin_bar_frontend' => ['type' => 'checkbox', 'label' => __('Hide Admin Bar on Frontend', 'admin-menu-optimizer')], 'hide_admin_bar_backend' => ['type' => 'checkbox', 'label' => __('Hide Admin Bar on Backend', 'admin-menu-optimizer')], 'remove_wp_logo' => ['type' => 'checkbox', 'label' => __('Remove WordPress Logo from Admin Bar', 'admin-menu-optimizer')], 'remove_comments_menu' => ['type' => 'checkbox', 'label' => __('Remove Comments from Admin Bar', 'admin-menu-optimizer')], 'remove_updates_menu' => ['type' => 'checkbox', 'label' => __('Remove Updates from Admin Bar', 'admin-menu-optimizer')], 'hide_admin_notices' => ['type' => 'checkbox', 'label' => __('Hide All Admin Notices', 'admin-menu-optimizer')], 'hide_wp_version' => ['type' => 'checkbox', 'label' => __('Hide WordPress Version in Footer', 'admin-menu-optimizer')], 'footer_text' => ['type' => 'text', 'label' => __('Custom Footer Text', 'admin-menu-optimizer')], ]; echo ''; foreach ($settings as $key => $field) { $value = $this->get_setting($key); echo ''; echo ''; echo ''; echo ''; } echo ''; } }