/home/techb158/public_html/wp-content/plugins/kirki/libraries/framework/Wordpress
NameSizeModeActions
Constants/-0755rm
Contracts/-0755rm
Hooks/-0755rm
Models/-0755rm
BaseHook.php16910644editdlrm
HookServiceProvider.php34650644editdlrm
Menu.php33050644editdlrm
User.php111180644editdlrm
UserMeta.php45320644editdlrm
Edit: /home/techb158/public_html/wp-content/plugins/kirki/libraries/framework/Wordpress/User.php (11118B)
user = \get_user_by('id', $user_id); } else { $this->user = \wp_get_current_user(); } } /** * Sync the user by provided user id. * * @param int $user_id The user id. * * @return static * * @since 1.0.0 */ public function sync(int $user_id) { $this->user = \get_user_by('id', $user_id); return $this; } /** * Get the current user instance * * @return WP_User|null * * @since 1.0.0 */ public function get() { return $this->user; } /** * Get the data. * * @return mixed * * @since 1.0.0 */ public function get_data() { return ['id' => $this->get_id(), 'email' => $this->get_email(), 'first_name' => $this->get_first_name(), 'last_name' => $this->get_last_name(), 'display_name' => $this->get_display_name(), 'avatar' => $this->get_avatar(), 'active_role' => $this->get_active_role()]; } /** * Get the current user meta data * * @param string $key The key. * * @return array * * @since 1.0.0 */ public function get_user_meta(string $key = '') { return \get_user_meta($this->get_id(), with_prefix($key), !empty($key)); } /** * Get the current user ID * * @return int * * @since 1.0.0 */ public function get_id() { return $this->user->ID ?? 0; } /** * Get the current user email * * @return string * * @since 1.0.0 */ public function get_email() { return $this->user->user_email ?? ''; } /** * Get the username * * @return string * * @since 1.0.0 */ public function get_username() { return $this->user->user_login ?? ''; } /** * Get the current user avatar * * @return string * * @since 1.0.0 */ public function get_avatar() { return \get_avatar_url($this->get_id()); } /** * Get the current user display name * * @return string * * @since 1.0.0 */ public function get_display_name() { return $this->user->display_name ?? ''; } /** * Get the current user first name * * @return string * * @since 1.0.0 */ public function get_first_name() { if (!empty($this->user->first_name)) { return $this->user->first_name; } $display_name = $this->get_display_name(); return \explode(' ', $display_name)[0] ?? ''; } /** * Get the current user last name * * @return string * * @since 1.0.0 */ public function get_last_name() { if (!empty($this->user->last_name)) { return $this->user->last_name; } $display_name = \explode(' ', $this->get_display_name()); if (\count($display_name) > 1) { return \array_shift($display_name); } return ''; } /** * Get the current user roles * * @return array * * @since 1.0.0 */ public function get_roles() { return $this->user->roles ?? []; } /** * Set the current user role * * @param mixed $role The role. * * @return bool * * @since 1.0.0 */ public function set_role($role) { return $this->user->set_role($role); } /** * Check if the current user has a specific role * * @param string $role The role. * * @return bool * * @since 1.0.0 */ public function has_role(string $role) { return \in_array($role, $this->get_roles(), \true); } /** * Check if the current user is logged in * * @return bool * * @since 1.0.0 */ public function is_logged_in() { return \is_user_logged_in(); } /** * Get the current user meta * * @param string $key The key. * @param mixed $default The default. * * @return mixed * * @since 1.0.0 */ public function get_meta(string $key, $default = null) { return UserMeta::get($this->get_id(), $key) ?: $default; } /** * Check if the user can perform an action on a model * * @param mixed $ability The ability. * @param mixed $model The model instance. * * @return bool * * @since 1.0.0 */ public function can($ability, $model = null) { return \is_null($model) ? current_user_can($ability) : Guard::allows($ability, $model); } /** * Check if the user cannot perform an action on a model * * @param mixed $ability The ability. * @param mixed $model The model instance. * * @return bool * * @since 1.0.0 */ public function cannot($ability, $model = null) { return !$this->can($ability, $model); } /** * Magic method to handle dynamic capability checks. * Allows calling methods like can_edit_posts(), can_manage_options(), etc. * The method name must start with 'can_' followed by a valid capability from Capabilities class. * * @param string $name The method name being called * @param array $arguments Arguments passed to the method (unused) * * @return bool Whether the user has the requested capability * * @throws \Exception * * @since 1.0.0 */ public function __call($name, $arguments = []) { if (!str_starts_with($name, 'can_')) { throw new Exception(\sprintf('Method %s does not exist', $name)); } $action = \preg_replace('/^can_/', '', $name); return $this->can($action, $arguments); } }