Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
86.67% covered (warning)
86.67%
26 / 30
66.67% covered (warning)
66.67%
2 / 3
CRAP
n/a
0 / 0
Automattic\Jetpack\PremiumAnalytics\get_video_single_report_page_default_layout
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
Automattic\Jetpack\PremiumAnalytics\is_video_single_report_page_available
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
Automattic\Jetpack\PremiumAnalytics\register_default_single_report_pages
94.74% covered (success)
94.74%
18 / 19
0.00% covered (danger)
0.00%
0 / 1
4.00
1<?php
2/**
3 * The package's own single-report pages, registered through the single-report page API.
4 *
5 * @package automattic/jetpack-premium-analytics
6 */
7
8namespace Automattic\Jetpack\PremiumAnalytics;
9
10require_once __DIR__ . '/single-report-pages.php';
11require_once __DIR__ . '/videopress-availability.php';
12
13/**
14 * The video page's fixed composition: the performance chart full width, then the player beside the embeds list.
15 *
16 * @return array
17 */
18function get_video_single_report_page_default_layout() {
19    return array(
20        get_dashboard_default_widget_instance( 'video-detail-views-performance', 'jpa/video-detail-views-performance', 10, 'full', 2, array( 'chartType' => 'bar' ) ),
21        get_dashboard_default_widget_instance( 'videopress-video-player', 'videopress/video-player', 20, 1, 2 ),
22        get_dashboard_default_widget_instance( 'video-detail-embeds', 'jpa/video-detail-embeds', 30, 'fill', 2 ),
23    );
24}
25
26/**
27 * Whether the video page is available: VideoPress is there and the reader may view Stats.
28 *
29 * @return bool
30 */
31function is_video_single_report_page_available() {
32    if ( ! Capabilities::current_user_can_view_stats() ) {
33        return false;
34    }
35
36    return is_videopress_available();
37}
38
39/**
40 * Registers the package's own single-report pages into the registry being hydrated.
41 *
42 * @param Single_Report_Page_Registry|null $registry The registry the action hands over.
43 */
44function register_default_single_report_pages( $registry = null ) {
45    if ( ! $registry instanceof Single_Report_Page_Registry ) {
46        $registry = Single_Report_Page_Registry::get_instance();
47    }
48
49    $pages = array(
50        'analytics/video' => array(
51            'path'              => 'video',
52            'label'             => __( 'Video', 'jetpack-premium-analytics-pkg' ),
53            'dashboard_section' => 'traffic',
54            'is_available'      => __NAMESPACE__ . '\\is_video_single_report_page_available',
55            'feature'           => 'videos',
56            'scope_param'       => 'post_id',
57            'icon'              => 'jpa/video',
58            'reports_page'      => 'videos',
59            'default_layout'    => __NAMESPACE__ . '\\get_video_single_report_page_default_layout',
60            'preferences_scope' => 'jetpack-premium-analytics/video-detail',
61        ),
62    );
63
64    foreach ( $pages as $id => $args ) {
65        if ( ! $registry->is_registered( DASHBOARD_NAME, $id ) ) {
66            $registry->register( DASHBOARD_NAME, $id, $args );
67        }
68    }
69}
70
71add_action( Single_Report_Page_Registry::REGISTER_ACTION, __NAMESPACE__ . '\\register_default_single_report_pages' );