guard( 'etn_manage_schedule' ); if ( $check ) { return $check; } try { if ( $schedule_id <= 0 ) { return [ 'error' => 'schedule_id must be a positive integer.' ]; } $post = get_post( $schedule_id ); if ( ! $post || 'etn-schedule' !== $post->post_type ) { return [ 'error' => "No Eventin schedule found with ID {$schedule_id}." ]; } $request = new \WP_REST_Request( 'GET' ); $request->set_param( 'id', $schedule_id ); $response = ( new \Eventin\Schedule\Api\ScheduleController() )->get_item( $request ); if ( is_wp_error( $response ) ) { return [ 'error' => $response->get_error_message() ]; } $schedule = $response->get_data(); return [ 'schedule' => $schedule ]; // \Throwable, not \Exception: a missing ScheduleController class raises \Error. } catch ( \Throwable $e ) { Log::error( 'Eventin_Get_Schedule_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to retrieve schedule: ' . $e->getMessage() ]; } } }