find( $id ); if ( null !== $reservation ) { $this->post( 'reservation.created', $reservation ); } } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed -- the hook passes it. public function on_status_changed( int $id, mixed $reservation, string $old_status = '' ): void { if ( $reservation instanceof Reservation ) { $this->post( 'reservation.status_changed', $reservation, [ 'previous_status' => $old_status ] ); } } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed -- the hook passes it. public function on_moved( int $id, mixed $reservation, mixed $before = null ): void { if ( ! $reservation instanceof Reservation ) { return; } $extra = $before instanceof Reservation ? [ 'previous' => [ 'date' => $before->date, 'time' => $before->time, ], ] : []; $this->post( 'reservation.moved', $reservation, $extra ); } /** * @param array $extra */ private function post( string $event, Reservation $reservation, array $extra = [] ): void { $url = (string) Settings::get( 'webhook_url', '' ); if ( '' === $url ) { return; } $payload = [ 'event' => $event, 'reservation' => $reservation->to_array(), ] + $extra; wp_safe_remote_post( $url, [ 'timeout' => 5, 'blocking' => false, 'headers' => [ 'Content-Type' => 'application/json' ], 'body' => (string) wp_json_encode( $payload ), ] ); } }