PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-premium-analytics / src / dashboard-policy.php

dashboard-policy.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.3, at jetpack_vendor/automattic/jetpack-premium-analytics/src/dashboard-policy.php

69 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Dashboard policy: the composition feature flag and its script-data bridge.
4 *
5 * @package automattic/jetpack-premium-analytics
6 */
7
8 namespace Automattic\Jetpack\PremiumAnalytics;
9
10 use Automattic\Jetpack\Feature_Flags\Feature_Flags;
11
12 /**
13 * Name of the feature flag that offers adding, removing and resetting widgets.
14 */
15 const DASHBOARD_COMPOSITION_FLAG = 'premium-analytics-dashboard-composition';
16
17 /**
18 * Registers the dashboard feature flags.
19 *
20 * Runs on every request so the flag stays discoverable wherever flags are read or
21 * toggled: REST, WP-CLI and the WordPress.com control screen included.
22 *
23 * @return void
24 */
25 function register_dashboard_feature_flags() {
26 Feature_Flags::register(
27 DASHBOARD_COMPOSITION_FLAG,
28 array(
29 'default' => false,
30 'description' => 'Offer adding, removing and resetting widgets on the analytics dashboard, on top of moving and resizing them.',
31 'owner' => 'jetpack-premium-analytics',
32 )
33 );
34 }
35
36 /**
37 * Whether the dashboard offers adding, removing and resetting widgets.
38 *
39 * @return bool
40 */
41 function is_dashboard_composition_enabled() {
42 return Feature_Flags::is_enabled( DASHBOARD_COMPOSITION_FLAG );
43 }
44
45 /**
46 * Configures the dashboard policy script data.
47 *
48 * @return void
49 */
50 function configure_dashboard_policy() {
51 add_filter( 'jetpack_admin_js_script_data', __NAMESPACE__ . '\\inject_dashboard_policy_script_data', 20 );
52 }
53
54 /**
55 * Injects the flag's answer into JetpackScriptData for the dashboard policy.
56 *
57 * @param array $data The script data passed by the assets package.
58 * @return array
59 */
60 function inject_dashboard_policy_script_data( array $data ): array {
61 if ( ! isset( $data['premium_analytics'] ) || ! is_array( $data['premium_analytics'] ) ) {
62 $data['premium_analytics'] = array();
63 }
64
65 $data['premium_analytics']['dashboard_composition_enabled'] = is_dashboard_composition_enabled();
66
67 return $data;
68 }
69