Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
54.55% covered (warning)
54.55%
6 / 11
66.67% covered (warning)
66.67%
2 / 3
CRAP
n/a
0 / 0
wpcom_premium_analytics_site_has_videopress
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
wpcom_premium_analytics_register_videopress_widget_types
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
wpcom_premium_analytics_seed_videopress_default_layout
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * The Top videos widget of the Premium Analytics dashboard on the WordPress.com platform.
4 *
5 * Simple runs no Jetpack plugin, and on Atomic the VideoPress module is routinely off while the plan
6 * includes VideoPress, so the plan feature decides here and the package registrant skips the platform.
7 * The widget comes from the jetpack-videopress package, which the Jetpack plugin bundles: WordPress.com
8 * loads that copy, so this package does not.
9 *
10 * @package automattic/jetpack-mu-wpcom
11 */
12
13use Automattic\Jetpack\VideoPress\Analytics_Dashboard;
14
15/**
16 * Whether the site's plan includes VideoPress, and the package that owns the widget is here.
17 *
18 * @since $$next-version$$
19 *
20 * @return bool
21 */
22function wpcom_premium_analytics_site_has_videopress() {
23    return function_exists( 'wpcom_site_has_feature' )
24        && wpcom_site_has_feature( 'videopress' )
25        && class_exists( Analytics_Dashboard::class );
26}
27
28/**
29 * Register the Top videos widget type on a site whose plan includes VideoPress.
30 *
31 * @since $$next-version$$
32 *
33 * @param \Automattic\Jetpack\PremiumAnalytics\Widget_Type_Registry $registry The registry being hydrated.
34 * @return void
35 */
36function wpcom_premium_analytics_register_videopress_widget_types( $registry ) {
37    if ( ! wpcom_premium_analytics_site_has_videopress() ) {
38        return;
39    }
40
41    Analytics_Dashboard::register_widget_types( $registry );
42}
43
44/**
45 * Seed the Top videos instance into the Traffic default layout on a site whose plan includes VideoPress.
46 *
47 * @since $$next-version$$
48 *
49 * @param array  $layout     The section's default widget instances.
50 * @param string $section_id Namespaced section identifier.
51 * @return array
52 */
53function wpcom_premium_analytics_seed_videopress_default_layout( $layout, $section_id ) {
54    if ( ! wpcom_premium_analytics_site_has_videopress() ) {
55        return $layout;
56    }
57
58    return Analytics_Dashboard::add_default_layout_instance( $layout, $section_id );
59}
60
61// After the package's own registrant (priority 10); the seed runs before the dashboard's policy at 100.
62add_action( 'jetpack_premium_analytics_register_widget_types', 'wpcom_premium_analytics_register_videopress_widget_types', 20 );
63add_filter( 'jetpack_premium_analytics_dashboard_default_layout', 'wpcom_premium_analytics_seed_videopress_default_layout', 10, 2 );