Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
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% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| Automattic\Jetpack\PremiumAnalytics\store_dashboard_first_visit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | store_dashboard_first_visit(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Stores the current time as the first dashboard load, unless one is already stored. |
| 43 | * |
| 44 | * @since 0.19.0 |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | function store_dashboard_first_visit() { |
| 49 | // add_option() is a no-op once the option exists. |
| 50 | add_option( DASHBOARD_FIRST_VISIT_OPTION, time(), '', false ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * The Unix time of the site's first dashboard load. |
| 55 | * |
| 56 | * @since 0.14.0 |
| 57 | * |
| 58 | * @return int|null Null until the dashboard has loaded once. |
| 59 | */ |
| 60 | function get_dashboard_first_visit() { |
| 61 | $first_visit = (int) get_option( DASHBOARD_FIRST_VISIT_OPTION ); |
| 62 | |
| 63 | return $first_visit > 0 ? $first_visit : null; |
| 64 | } |