guard( 'manage_options', 'manage_woocommerce' ); if ( $check ) { return $check; } try { $params = [ 'per_page' => min( 50, max( 1, (int) ( $per_page ?? 20 ) ) ), 'paged' => max( 1, (int) ( $paged ?? 1 ) ), ]; if ( ! empty( $search ) ) { $params['search'] = $search; } $request = new \WP_REST_Request( 'GET', '/wpcafe/v2/locations' ); $request->set_query_params( $params ); $controller = new \WpCafe\Location\Controllers\Location_Controller(); $result = $this->extract_response( $controller->get_items( $request ), 'Failed to retrieve locations.' ); if ( isset( $result['error'] ) ) { return $result; } $shaped = $this->shape_paginated( $result, fn( $location ) => [ 'id' => $location['term_id'] ?? null, 'restaurant_name' => $location['restaurant_name'] ?? '', 'location' => $location['location'] ?? '', 'status' => $location['status'] ?? '', 'enable_pickup' => $location['enable_pickup'] ?? '', 'enable_delivery' => $location['enable_delivery'] ?? '', 'enable_reservation' => $location['enable_reservation'] ?? '', 'delivery_fee' => $location['delivery_fee'] ?? 0, 'reservation_minimum_guest' => $location['reservation_minimum_guest'] ?? 0, 'reservation_maximum_guest' => $location['reservation_maximum_guest'] ?? 0, ] ); return $shaped; } catch ( \Throwable $e ) { Log::error( 'Wpcafe_List_Locations_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to retrieve locations: ' . $e->getMessage() ]; } } }