| 1 |
<?php |
| 2 |
/** |
| 3 |
* CSV export script-data wiring. |
| 4 |
* |
| 5 |
* @package automattic/jetpack-premium-analytics |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\PremiumAnalytics; |
| 9 |
|
| 10 |
/** |
| 11 |
* Filter controlling whether CSV export controls are shown. |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
const CSV_EXPORTS_ENABLED_FILTER = 'jetpack_premium_analytics_csv_exports_enabled'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Configures CSV export script data. |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
function 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 |
*/ |
| 32 |
function 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 |
} |
| 48 |
|