Skip to content

Commit 7148bf9

Browse files
authored
fix: move $instance creation before /stream route to fix non-static permission callback (#513)
check_chat_permission() is a non-static instance method but was being called statically via [__CLASS__, 'check_chat_permission'], causing a fatal TypeError on every chat request. Move $instance = new self() before the /stream route registration and use [$instance, 'check_chat_permission'] for the permission_callback. The /run route reuses the same $instance (no duplicate instantiation). Closes #509
1 parent e922f79 commit 7148bf9

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

includes/REST/RestController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ public static function register_routes(): void {
9090
// Resale API endpoints.
9191
ResaleApiController::register_routes();
9292

93+
$instance = new self();
9394
register_rest_route(
9495
self::NAMESPACE,
9596
'/stream',
9697
[
9798
'methods' => WP_REST_Server::CREATABLE,
9899
'callback' => [ __CLASS__, 'handle_stream' ],
99-
'permission_callback' => [ __CLASS__, 'check_chat_permission' ],
100+
'permission_callback' => [ $instance, 'check_chat_permission' ],
100101
'args' => [
101102
'message' => [
102103
'required' => true,
@@ -149,7 +150,6 @@ public static function register_routes(): void {
149150
]
150151
);
151152

152-
$instance = new self();
153153
register_rest_route(
154154
self::NAMESPACE,
155155
'/run',

0 commit comments

Comments
 (0)