Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Canonical_Urls
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 init
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 is_enabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 load_module
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Archive canonical tags on WordPress.com Simple.
4 *
5 * Elsewhere Jetpack loads the `canonical-urls` module itself. Simple runs no modules, so its
6 * switch is a plain option and the package loads the module file when it is on.
7 *
8 * @package automattic/jetpack-seo-package
9 */
10
11namespace Automattic\Jetpack\SEO;
12
13use Automattic\Jetpack\Constants;
14use Automattic\Jetpack\Status\Host;
15
16/**
17 * Loads the Jetpack `canonical-urls` module on Simple sites that switched it on.
18 */
19class Canonical_Urls {
20
21    /**
22     * Simple's on/off switch; missing means off. WordPress.com maps it to the
23     * `canonical-urls` module when a site moves to Atomic, so keep the name.
24     *
25     * @var string
26     */
27    const OPTION = 'jetpack_canonical_urls_enabled';
28
29    /**
30     * On Simple with the switch on, load the module on the hook Jetpack loads modules on.
31     *
32     * @return void
33     */
34    public static function init() {
35        if ( ( new Host() )->is_wpcom_simple() && self::is_enabled() ) {
36            add_action( 'after_setup_theme', array( __CLASS__, 'load_module' ) );
37        }
38    }
39
40    /**
41     * Whether Simple's switch is on.
42     *
43     * @return bool
44     */
45    public static function is_enabled() {
46        return (bool) get_option( self::OPTION, false );
47    }
48
49    /**
50     * Load the module file, which prints the tag and applies its own conflict filter.
51     *
52     * @return void
53     */
54    public static function load_module() {
55        $dir = Constants::get_constant( 'JETPACK__PLUGIN_DIR' );
56        if ( $dir ) {
57            require_once $dir . 'modules/canonical-urls.php';
58        }
59    }
60}