Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\PremiumAnalytics\configure_dashboard_first_visit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| Automattic\Jetpack\PremiumAnalytics\record_dashboard_first_visit | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| Automattic\Jetpack\PremiumAnalytics\get_dashboard_first_visit | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * When the site first opened the dashboard, so notices can wait until the site has been on it a while. |
| 4 | * |
| 5 | * @package automattic/jetpack-premium-analytics |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\PremiumAnalytics; |
| 9 | |
| 10 | /** |
| 11 | * Option holding the Unix time of the site's first dashboard load. |
| 12 | * |
| 13 | * @var string |
| 14 | */ |
| 15 | const DASHBOARD_FIRST_VISIT_OPTION = 'jetpack_premium_analytics_first_visit'; |
| 16 | |
| 17 | /** |
| 18 | * Configures the first-visit record. |
| 19 | * |
| 20 | * @since 0.14.0 |
| 21 | * |
| 22 | * @return void |
| 23 | */ |
| 24 | function configure_dashboard_first_visit() { |
| 25 | add_action( 'admin_init', __NAMESPACE__ . '\\record_dashboard_first_visit' ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Stores the time of the first dashboard load, once per site. |
| 30 | * |
| 31 | * @since 0.14.0 |
| 32 | * |
| 33 | * @return void |
| 34 | */ |
| 35 | function record_dashboard_first_visit() { |
| 36 | if ( ! Analytics::is_dashboard_request() ) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | // add_option() is a no-op once the option exists. |
| 41 | add_option( DASHBOARD_FIRST_VISIT_OPTION, time(), '', false ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * The Unix time of the site's first dashboard load. |
| 46 | * |
| 47 | * @since 0.14.0 |
| 48 | * |
| 49 | * @return int|null Null until the dashboard has loaded once. |
| 50 | */ |
| 51 | function get_dashboard_first_visit() { |
| 52 | $first_visit = (int) get_option( DASHBOARD_FIRST_VISIT_OPTION ); |
| 53 | |
| 54 | return $first_visit > 0 ? $first_visit : null; |
| 55 | } |