diff --git a/includes/event/event-date.php b/includes/event/event-date.php index 75032d8b..f5d20550 100644 --- a/includes/event/event-date.php +++ b/includes/event/event-date.php @@ -17,7 +17,7 @@ */ abstract class Event_Date extends DateTimeImmutable { protected $event_timezone; - public function __construct( string $date, DateTimeZone $timezone = null ) { + public function __construct( string $date, ?DateTimeZone $timezone = null ) { if ( ! $timezone ) { $timezone = new DateTimeZone( 'UTC' ); } diff --git a/includes/event/event.php b/includes/event/event.php index 42879155..c013ccf1 100644 --- a/includes/event/event.php +++ b/includes/event/event.php @@ -9,25 +9,25 @@ use Wporg\TranslationEvents\Translation_Events; class InvalidTimeZone extends Exception { - public function __construct( Throwable $previous = null ) { + public function __construct( ?Throwable $previous = null ) { parent::__construct( 'Event time zone is invalid', 0, $previous ); } } class InvalidStart extends Exception { - public function __construct( Throwable $previous = null ) { + public function __construct( ?Throwable $previous = null ) { parent::__construct( 'Event start is invalid', 0, $previous ); } } class InvalidEnd extends Exception { - public function __construct( Throwable $previous = null ) { + public function __construct( ?Throwable $previous = null ) { parent::__construct( 'Event end is invalid', 0, $previous ); } } class InvalidStatus extends Exception { - public function __construct( Throwable $previous = null ) { + public function __construct( ?Throwable $previous = null ) { parent::__construct( 'Event status is invalid', 0, $previous ); } } @@ -58,7 +58,7 @@ public function __construct( string $status, string $title, string $description, - DateTimeImmutable $updated_at = null, + ?DateTimeImmutable $updated_at = null, string $attendance_mode = 'onsite' ) { $this->author_id = $author_id; @@ -184,7 +184,7 @@ public function set_description( string $description ): void { $this->description = $description; } - public function set_updated_at( DateTimeImmutable $updated_at = null ): void { + public function set_updated_at( ?DateTimeImmutable $updated_at = null ): void { $this->updated_at = $updated_at ?? Translation_Events::now(); } diff --git a/includes/routes/user/attend-event.php b/includes/routes/user/attend-event.php index a739601b..313811d2 100644 --- a/includes/routes/user/attend-event.php +++ b/includes/routes/user/attend-event.php @@ -38,11 +38,10 @@ public function handle( int $event_id ): void { $this->die_with_error( esc_html__( 'You are not authorized to change the attendance mode of this attendee', 'gp-translation-events' ), 403 ); } } - $user = wp_get_current_user(); - if ( ! $user ) { + $user_id = get_current_user_id(); + if ( ! $user_id ) { $this->die_with_error( esc_html__( 'Only logged-in users can attend events', 'gp-translation-events' ), 403 ); } - $user_id = $user->ID; $event = $this->event_repository->get_event( $event_id ); if ( ! $event ) {