Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
n/a
0 / 0
Automattic\Jetpack\PremiumAnalytics\configure_csv_exports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Automattic\Jetpack\PremiumAnalytics\inject_csv_exports_script_data
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * CSV export script-data wiring.
4 *
5 * @package automattic/jetpack-premium-analytics
6 */
7
8namespace Automattic\Jetpack\PremiumAnalytics;
9
10/**
11 * Filter controlling whether CSV export controls are shown.
12 *
13 * @var string
14 */
15const CSV_EXPORTS_ENABLED_FILTER = 'jetpack_premium_analytics_csv_exports_enabled';
16
17/**
18 * Configures CSV export script data.
19 *
20 * @return void
21 */
22function configure_csv_exports() {
23    add_filter( 'jetpack_admin_js_script_data', __NAMESPACE__ . '\\inject_csv_exports_script_data', 20 );
24}
25
26/**
27 * Injects the CSV export flag into JetpackScriptData.
28 *
29 * @param array $data The script data passed by the assets package.
30 * @return array
31 */
32function inject_csv_exports_script_data( array $data ): array {
33    if ( ! isset( $data['premium_analytics'] ) || ! is_array( $data['premium_analytics'] ) ) {
34        $data['premium_analytics'] = array();
35    }
36
37    /**
38     * Filters whether Premium Analytics should show CSV export controls.
39     *
40     * CSV exports are enabled by default. Return false to disable them.
41     *
42     * @param bool $enabled Whether to show CSV export controls.
43     */
44    $data['premium_analytics']['csv_exports_enabled'] = (bool) apply_filters( CSV_EXPORTS_ENABLED_FILTER, true );
45
46    return $data;
47}