Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.32% covered (success)
90.32%
28 / 31
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
Automattic\Jetpack\PremiumAnalytics\register_default_reports_pages
96.55% covered (success)
96.55%
28 / 29
0.00% covered (danger)
0.00%
0 / 1
4
1<?php
2/**
3 * The package's own reports pages, registered through the reports page API.
4 *
5 * @package automattic/jetpack-premium-analytics
6 */
7
8namespace Automattic\Jetpack\PremiumAnalytics;
9
10require_once __DIR__ . '/reports-pages.php';
11
12/**
13 * Rows a reports page's table tile spans.
14 */
15const REPORTS_PAGE_TABLE_TILE = 4;
16
17/**
18 * Registers the package's own reports pages into the registry being hydrated.
19 *
20 * @param Reports_Page_Registry|null $registry The registry the action hands over.
21 */
22function register_default_reports_pages( $registry = null ) {
23    if ( ! $registry instanceof Reports_Page_Registry ) {
24        $registry = Reports_Page_Registry::get_instance();
25    }
26
27    $pages = array(
28        'analytics/posts' => array(
29            'path'              => 'posts',
30            'label'             => __( 'All pages', 'jetpack-premium-analytics-pkg' ),
31            'dashboard_section' => 'traffic',
32            'feature'           => 'top-posts',
33            'sections'          => array(
34                array(
35                    'slug'           => 'posts-pages',
36                    'label'          => __( 'Posts & Pages', 'jetpack-premium-analytics-pkg' ),
37                    'default_layout' => array(
38                        get_dashboard_default_widget_instance( 'posts-table', 'jpa/posts-table', 1, 'full', REPORTS_PAGE_TABLE_TILE ),
39                    ),
40                ),
41                array(
42                    'slug'           => 'archives',
43                    'label'          => __( 'Archives', 'jetpack-premium-analytics-pkg' ),
44                    'default_layout' => array(
45                        get_dashboard_default_widget_instance( 'archives-table', 'jpa/archives-table', 1, 'full', REPORTS_PAGE_TABLE_TILE ),
46                    ),
47                ),
48            ),
49        ),
50    );
51
52    foreach ( $pages as $id => $args ) {
53        if ( ! $registry->is_registered( DASHBOARD_NAME, $id ) ) {
54            $registry->register( DASHBOARD_NAME, $id, $args );
55        }
56    }
57}
58
59add_action( Reports_Page_Registry::REGISTER_ACTION, __NAMESPACE__ . '\\register_default_reports_pages' );