From 5a63d8c4c8501ed1d84ebf35e797d707f69a6c4c Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 18 Apr 2024 17:23:21 +0100 Subject: [PATCH] Simplify logic --- includes/event/event-capabilities.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/includes/event/event-capabilities.php b/includes/event/event-capabilities.php index aa6236c8..be4875d9 100644 --- a/includes/event/event-capabilities.php +++ b/includes/event/event-capabilities.php @@ -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; @@ -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;