options_repository = $options_repository; } /** * Check if current user can manage plugin settings, logs and bulk operations. * * @since 1.0.0 * @return bool True if user can manage settings. */ public function can_manage_settings(): bool { return current_user_can('manage_options'); } /** * Check if current user can use the selector and manage hiding rules. * * @since 1.0.0 * @return bool True if user can use selector. */ public function can_use_selector(): bool { if (!current_user_can('edit_posts')) { return false; } $user = wp_get_current_user(); if (!$user || !$user->exists()) { return false; } return !empty(array_intersect($this->get_allowed_roles(), (array) $user->roles)); } /** * Check if the admin bar button should be shown for the current user. * * @since 1.0.0 * @return bool True if button should be shown. */ public function should_show_admin_bar_button(): bool { if (!$this->options_repository->get_option('ui.show_admin_bar_button', true)) { return false; } return $this->can_use_selector(); } /** * Get allowed roles for plugin functionality. * * @since 1.0.0 * @return array Array of allowed role names. */ public function get_allowed_roles(): array { $allowed_roles = $this->options_repository->get_option('access.roles_allowed', ['administrator']); if (!is_array($allowed_roles) || empty($allowed_roles)) { return ['administrator']; } return array_values(array_unique(array_map('strval', $allowed_roles))); } }