Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Apr 18, 2024
1 parent 3d2bab7 commit 5a63d8c
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions includes/event/event-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,7 @@ private function has_cap( string $cap, array $args, WP_User $user ): bool {
case self::CREATE:
return $this->has_create( $user );
case self::VIEW:
if ( ! isset( $args[2] ) || ! is_int( $args[2] ) ) {
return false;
}
$event = $this->event_repository->get_event( $args[2] );
if ( ! $event ) {
return false;
}
return $this->has_view( $user, $event );
case self::EDIT:
if ( ! isset( $args[2] ) || ! is_int( $args[2] ) ) {
return false;
}
$event = $this->event_repository->get_event( $args[2] );
if ( ! $event ) {
return false;
}
return $this->has_edit( $user, $event );
case self::DELETE:
if ( ! isset( $args[2] ) || ! is_int( $args[2] ) ) {
return false;
Expand All @@ -76,7 +60,15 @@ private function has_cap( string $cap, array $args, WP_User $user ): bool {
if ( ! $event ) {
return false;
}
return $this->has_delete( $user, $event );

if ( self::VIEW === $cap ) {
return $this->has_view( $user, $event );
} elseif ( self::EDIT === $cap ) {
return $this->has_edit( $user, $event );
} elseif ( self::DELETE === $cap ) {
return $this->has_delete( $user, $event );
}
break;
}

return false;
Expand Down

0 comments on commit 5a63d8c

Please sign in to comment.