Skip to content

Commit

Permalink
Do not set user instead of defaulting to “anonymous”
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Jul 12, 2024
1 parent 85aa672 commit b785964
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/class-wp-sentry-php-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public function on_init(): void {
*/
public function on_set_current_user(): void {
$this->get_client()->configureScope( function ( Scope $scope ) {
$scope->setUser( $this->get_current_user_info() );
$user = $this->get_current_user_info();

if ( $user !== null ) {
$scope->setUser( $user );
}
} );
}

Expand Down
7 changes: 2 additions & 5 deletions src/trait-wp-sentry-resolves-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ trait WP_Sentry_Resolve_User {
protected function get_current_user_info(): ?array {
$current_user = wp_get_current_user();

if ( $current_user === null ) {
if ( ! $current_user instanceof WP_User || ! $current_user->exists() ) {
return null;
}

// Determine whether the user is logged in assign their details.
$user_context = $current_user instanceof WP_User && $current_user->exists() ? [
$user_context = [
'id' => $current_user->ID,
'name' => $current_user->display_name,
'email' => $current_user->user_email,
'username' => $current_user->user_login,
] : [
'id' => 0,
'name' => 'anonymous',
];

// Filter the user context so that plugins that manage users on their own
Expand Down

0 comments on commit b785964

Please sign in to comment.