Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
8 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
n/a
0 / 0
wpcom_launchpad_is_past_no_guidance_cutoff
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
wpcom_launchpad_is_no_guidance
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2/**
3 * No-guidance launchpad state.
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8use Automattic\Jetpack\Constants;
9
10if ( ! function_exists( 'wpcom_launchpad_is_past_no_guidance_cutoff' ) ) {
11    /**
12     * Whether a WordPress.com blog ID belongs to a site created after new sites stopped getting setup guidance.
13     *
14     * The cutoff is the WPCOM_LAUNCHPAD_NO_GUIDANCE_CUTOFF_BLOG_ID constant; without it, no site is past it.
15     *
16     * @param int $blog_id WordPress.com blog ID.
17     * @return bool
18     */
19    function wpcom_launchpad_is_past_no_guidance_cutoff( $blog_id ) {
20        $cutoff = (int) Constants::get_constant( 'WPCOM_LAUNCHPAD_NO_GUIDANCE_CUTOFF_BLOG_ID' );
21
22        return $cutoff > 0 && (int) $blog_id >= $cutoff;
23    }
24}
25
26if ( ! function_exists( 'wpcom_launchpad_is_no_guidance' ) ) {
27    /**
28     * Whether the site gets no setup guidance: no My Home, Site Setup, or launchpad widget.
29     *
30     * `wpcom_ai_launchpad_no_guidance` forces it. Otherwise an AI Launchpad site has no guidance once it skips Site
31     * Setup, and any other site has none when it was created past the cutoff.
32     *
33     * @return bool
34     */
35    function wpcom_launchpad_is_no_guidance() {
36        if ( get_option( 'wpcom_ai_launchpad_no_guidance' ) ) {
37            return true;
38        }
39
40        if ( get_option( 'wpcom_ai_launchpad_enabled' ) ) {
41            return (bool) get_option( 'wpcom_ai_launchpad_dismissed' );
42        }
43
44        // get_wpcom_blog_id() is false outside Simple and Atomic, so self-hosted Jetpack sites never reach the cutoff.
45        $blog_id = function_exists( 'get_wpcom_blog_id' ) ? get_wpcom_blog_id() : false;
46
47        return $blog_id && wpcom_launchpad_is_past_no_guidance_cutoff( $blog_id );
48    }
49}