Filter the JavaScript variables passed to the React report builder (localized as wpd_alpha_insights).
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.
File: includes/classes/WPDAI_Report_Builder.php
Context: Before wp_localize_script() is called for the report builder script.
| Parameter | Type | Description |
|---|---|---|
| $localized_variables | array | Associative array of keys and values passed to the React app (e.g. reports, filters, nonces, strings) |
Type: array
The (possibly modified) array of localized variables. Only scalar and array values are safe for JSON encoding; avoid passing objects or closures.
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;
}
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;
}