From bf1271ff8923311bfb00e64644600885d6c0f3dc Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 9 Mar 2026 14:54:57 +1000 Subject: [PATCH 1/2] Fix fatal error when non-logged-in user attends an event wp_get_current_user() always returns a WP_User object (with ID=0 for guests), so the check `! $user` never triggered. This allowed user_id=0 to reach the Attendee constructor, which throws "invalid user id". Use get_current_user_id() and check for a falsy value instead. Co-Authored-By: Claude Opus 4.6 --- includes/routes/user/attend-event.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 ) { From b6b4bd324009425edd02195d56af1e74a7138ce7 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 9 Mar 2026 14:55:02 +1000 Subject: [PATCH 2/2] Fix PHP 8.4 implicit nullable type deprecations PHP 8.4 deprecates implicit nullable types (e.g. Type $param = null). Updated all instances to use explicit nullable syntax (?Type $param = null) in event.php and event-date.php. Co-Authored-By: Claude Opus 4.6 --- includes/event/event-date.php | 2 +- includes/event/event.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) 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(); }