get_data(); $visible = array_values( array_filter( $operations, [ $this, 'currentUserCanReadOperation' ] ) ); // parent::index() already set X-WP-Total/X-WP-TotalPages from the // unfiltered platform count. Shrink them by however many operations // this page hid, so the pagination footer stays consistent with the // rows actually returned (best-effort — the platform total may still // include hidden operations on other pages). $hidden = count( $operations ) - count( $visible ); if ( $hidden ) { $headers = $response->get_headers(); $total = max( 0, (int) ( $headers['X-WP-Total'] ?? 0 ) - $hidden ); $per_page = (int) $request->get_param( 'per_page' ) ?: max( 1, count( $operations ) ); $response->header( 'X-WP-Total', $total ); $response->header( 'X-WP-TotalPages', (int) ceil( $total / $per_page ) ); } $response->set_data( $visible ); return $response; } /** * Find a single batch operation, applying the same per-operation gate. * * @param \WP_REST_Request $request Rest Request. * * @return \SureCart\Models\BatchOperation|\WP_REST_Response|\WP_Error */ public function find( \WP_REST_Request $request ) { $operation = parent::find( $request ); if ( is_wp_error( $operation ) ) { return $operation; } if ( ! $this->currentUserCanReadOperation( $operation ) ) { return new \WP_Error( 'rest_forbidden', __( 'You are not allowed to view this batch operation.', 'surecart' ), [ 'status' => 403 ] ); } return $operation; } }