Filter: wpd_ai_localized_report_builder_variables
Filter the JavaScript variables passed to the React report builder (localized as wpd_alpha_insights).
Description
The report builder localizes a script with configuration and data for the React dashboard (e.g. report list, filters, nonces, API URLs). This filter receives the full array of localized variables so you can add or change keys that the frontend expects. Use it to inject custom config, feature flags, or overrides for the report builder UI.
Location
File: includes/classes/WPDAI_Report_Builder.php
Context: Before wp_localize_script() is called for the report builder script.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $localized_variables | array | Associative array of keys and values passed to the React app (e.g. reports, filters, nonces, strings) |
Return
Type: array
The (possibly modified) array of localized variables. Only scalar and array values are safe for JSON encoding; avoid passing objects or closures.
Example Usage
Add a custom config flag
add_filter( 'wpd_ai_localized_report_builder_variables', 'add_report_builder_custom_config' );
function add_report_builder_custom_config( $localized_variables ) {
$localized_variables['customFeatureEnabled'] = true;
$localized_variables['myApiBase'] = rest_url( 'my-plugin/v1/' );
return $localized_variables;
}
Override report limit
add_filter( 'wpd_ai_localized_report_builder_variables', 'override_report_limit' );
function override_report_limit( $localized_variables ) {
if ( isset( $localized_variables['config'] ) && is_array( $localized_variables['config'] ) ) {
$localized_variables['config']['maxReports'] = 50;
}
return $localized_variables;
}
Related
- Developers → Classes → WPDAI_Data_Warehouse – Data fetching for reports
- Developers → Custom Data Sources – Data available to reports