guard( 'manage_pointics', 'manage_options' ); if ( $check ) { return $check; } $ready = $this->pointics_tables_ready(); if ( $ready ) { return $this->steer( $ready ); } $raw_per_page = $per_page; $page = max( 1, (int) ( $page ?? 1 ) ); $per_page = min( 100, max( 1, (int) ( $per_page ?? 20 ) ) ); $clamped = null !== $raw_per_page && $raw_per_page > 100; try { $request = new \WP_REST_Request( 'GET' ); $request->set_param( 'page', $page ); $request->set_param( 'per_page', $per_page ); foreach ( [ 'is_active', 'trigger', 'integration', 'type' ] as $key ) { $value = 'is_active' === $key ? $is_active : ( 'trigger' === $key ? $trigger : ( 'integration' === $key ? $integration : $type ) ); if ( null !== $value ) { $request->set_param( $key, $value ); } } $controller = pointics_container()->make( \Pointics\Api\Controllers\Channels_Controller::class ); $data = $this->extract_response( $controller->list_channels( $request ), __( 'Failed to list Pointics channels.', 'aisentic' ), 'pointics-list-channels' ); if ( $this->is_error( $data ) ) { return $data; } $result = $this->shape_paginated( $data, fn( array $item ): array => $this->with_admin_url( $this->pluck( $item, [ 'id', 'name', 'trigger', 'integration', 'type', 'calc_type', 'frequency', 'is_active' ] ), 'points-program' ) ); if ( $clamped ) { $result['note'] = __( 'per_page was bounded to the maximum of 100.', 'aisentic' ); } return $result; } catch ( \Throwable $e ) { Log::error( 'Pointics_List_Channels_Tool error', [ 'error' => $e->getMessage() ] ); return $this->steer( [ 'error' => __( 'Failed to list Pointics channels.', 'aisentic' ), 'code' => 'internal', 'status' => null, ] ); } } }