## Filter: wpd_ai_report_filters_allowed_keys_for_query_parameter_values

Modify the allowed query parameter keys that can be used in report filter URLs.

### Description

This filter controls which URL query parameters are allowed when filtering reports. It's a security feature that prevents arbitrary parameters from being processed. Use this filter to add custom query parameters for your custom report filters.

#### Location

File: `includes/classes/WPDAI_Report_Filters.php`

Method: `WPDAI_Report_Filters::__construct()`

Line: ~65

### Parameters

Parameter | Type | Description
--- | --- | ---
$allowed_keys | array | Array of allowed query parameter keys

#### Return

Type: array

Description: Modified array of allowed query parameter keys

### Default Allowed Keys

By default, Alpha Insights allows these query parameters:

- `date_range` - Date range filter
- `start_date` - Custom start date
- `end_date` - Custom end date
- `traffic_source` - Traffic source filter
- `product_id` - Product ID filter
- `category` - Product category filter
- `order_status` - Order status filter
- `customer_id` - Customer filter

### Example Usage

### Add Custom Location Filter

    add_filter( 'wpd_ai_report_filters_allowed_keys_for_query_parameter_values', 'add_location_filter' );
    function add_location_filter( $allowed_keys )
    {
        // Add custom location parameters
        $allowed_keys[] = 'country';
        $allowed_keys[] = 'state';
        $allowed_keys[] = 'city';
        return $allowed_keys;
    }

### Add Payment Method Filter

    add_filter( 'wpd_ai_report_filters_allowed_keys_for_query_parameter_values', 'add_payment_filter' );
    function add_payment_filter( $allowed_keys )
    {
        $allowed_keys[] = 'payment_method';
        $allowed_keys[] = 'payment_gateway';
        return $allowed_keys;
    }

### Add Shipping Method Filter

    add_filter( 'wpd_ai_report_filters_allowed_keys_for_query_parameter_values', 'add_shipping_filter' );
    function add_shipping_filter( $allowed_keys )
    {
        $allowed_keys[] = 'shipping_method';
        $allowed_keys[] = 'shipping_zone';
        return $allowed_keys;
    }

### Add Custom Tags Filter

    add_filter( 'wpd_ai_report_filters_allowed_keys_for_query_parameter_values', 'add_tags_filter' );
    function add_tags_filter( $allowed_keys )
    {
        $allowed_keys[] = 'product_tag';
        $allowed_keys[] = 'order_tag';
        $allowed_keys[] = 'custom_taxonomy';
        return $allowed_keys;
    }

### Best Practices

- Use descriptive, lowercase parameter names
- Use underscores for multi-word parameters (e.g., 'payment_method')
- Don't remove existing keys unless absolutely necessary
- Sanitize and validate these parameters when processing them
- Document your custom parameters for other developers

### Important Notes

- Only parameters in this array will be processed by report filters
- This is a security feature to prevent parameter injection
- You still need to implement the actual filtering logic for custom parameters
- Parameters not in this list are ignored by the report system

### Security Considerations

- Always sanitize custom parameter values when using them
- Validate parameter values against expected formats
- Use WordPress sanitization functions (sanitize_text_field, absint, etc.)
- Don't add parameters that could expose sensitive data

### Processing Custom Parameters

After adding a parameter to the allowed list, you need to handle it in your report query:

    // Add the parameter to allowed list
    add_filter( 'wpd_ai_report_filters_allowed_keys_for_query_parameter_values', 'add_country_filter' );
    function add_country_filter( $allowed_keys )
    {
        $allowed_keys[] = 'country';
        return $allowed_keys;
    }
    // Process the parameter in your report
    add_filter( 'wpd_ai_report_query_args', 'filter_by_country', 10, 2 );
    function filter_by_country( $args, $filters )
    {
        if ( isset( $_GET['country'] ) )
        {
            $country = sanitize_text_field( $_GET['country'] );
            // Add to your query args
            $args['meta_query'][] = array(
                'key' => '_billing_country',
                'value' => $country,
                'compare' => '='
            );
        }
        return $args;
    }

### URL Example

After adding custom parameters:

    /wp-admin/admin.php?page=alpha-insights-reports&date_range=last_30_days&country=US&payment_method=stripe

### Debugging

    add_filter( 'wpd_ai_report_filters_allowed_keys_for_query_parameter_values', 'debug_allowed_keys' );
    function debug_allowed_keys( $allowed_keys )
    {
        error_log( 'Allowed Report Filter Keys: ' . implode( ', ', $allowed_keys ) );
        return $allowed_keys;
    }

### Related Filters

- wpd_ai_report_filters_is_transient_enabled - Control report caching

### Related Classes

- `WPDAI_Report_Filters` - Report filtering system
- `WPDAI_Reporting_API` - Report data API