• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / fe4d74ae81b231d2986738b4e4648c24370c79ea

26 Feb 2025 02:54PM UTC coverage: 45.177% (-5.5%) from 50.712%
fe4d74ae81b231d2986738b4e4648c24370c79ea

push

github

enricobattocchi
Drop compatibility with PHP 7.2 and 7.3

15990 of 35394 relevant lines covered (45.18%)

4.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/dashboard/infrastructure/integrations/site-kit.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
namespace Yoast\WP\SEO\Dashboard\Infrastructure\Integrations;
4

5
use Yoast\WP\SEO\Conditionals\Google_Site_Kit_Feature_Conditional;
6
use Yoast\WP\SEO\Dashboard\Infrastructure\Analytics_4\Site_Kit_Analytics_4_Adapter;
7
use Yoast\WP\SEO\Dashboard\Infrastructure\Configuration\Permanently_Dismissed_Site_Kit_Configuration_Repository_Interface as Configuration_Repository;
8
use Yoast\WP\SEO\Dashboard\Infrastructure\Configuration\Site_Kit_Consent_Repository_Interface;
9
use Yoast\WP\SEO\Editors\Domain\Integrations\Integration_Data_Provider_Interface;
10

11
/**
12
 * Describes if the Site kit integration is enabled and configured.
13
 */
14
class Site_Kit implements Integration_Data_Provider_Interface {
15

16
        private const SITE_KIT_FILE = 'google-site-kit/google-site-kit.php';
17

18
        /**
19
         * The Site Kit consent repository.
20
         *
21
         * @var Site_Kit_Consent_Repository_Interface
22
         */
23
        private $site_kit_consent_repository;
24

25
        /**
26
         * The Site Kit consent repository.
27
         *
28
         * @var Configuration_Repository
29
         */
30
        private $permanently_dismissed_site_kit_configuration_repository;
31

32
        /**
33
         * The Site Kit adapter.
34
         *
35
         * @var Site_Kit_Analytics_4_Adapter
36
         */
37
        private $site_kit_analytics_4_adapter;
38

39
        /**
40
         * The constructor.
41
         *
42
         * @param Site_Kit_Consent_Repository_Interface $site_kit_consent_repository  The Site Kit consent repository.
43
         * @param Configuration_Repository              $configuration_repository     The Site Kit permanently dismissed
44
         *                                                                            configuration repository.
45
         * @param Site_Kit_Analytics_4_Adapter          $site_kit_analytics_4_adapter The Site Kit adapter. Used to
46
         *                                                                            determine if the setup is completed.
47
         */
48
        public function __construct(
×
49
                Site_Kit_Consent_Repository_Interface $site_kit_consent_repository,
50
                Configuration_Repository $configuration_repository,
51
                Site_Kit_Analytics_4_Adapter $site_kit_analytics_4_adapter
52
        ) {
53
                $this->site_kit_consent_repository                             = $site_kit_consent_repository;
×
54
                $this->permanently_dismissed_site_kit_configuration_repository = $configuration_repository;
×
55
                $this->site_kit_analytics_4_adapter                            = $site_kit_analytics_4_adapter;
×
56
        }
57

58
        /**
59
         * If the integration is activated.
60
         *
61
         * @return bool If the integration is activated.
62
         */
63
        public function is_enabled(): bool {
×
64
                return \is_plugin_active( self::SITE_KIT_FILE );
×
65
        }
66

67
        /**
68
         * If the Google site kit setup has been completed.
69
         *
70
         * @return bool If the Google site kit setup has been completed.
71
         */
72
        private function is_setup_completed() {
×
73
                return \get_option( 'googlesitekit_has_connected_admins', false ) === '1';
×
74
        }
75

76
        /**
77
         * If consent has been granted.
78
         *
79
         * @return bool If consent has been granted.
80
         */
81
        private function is_connected() {
×
82
                return $this->site_kit_consent_repository->is_consent_granted();
×
83
        }
84

85
        /**
86
         * If Google analytics is connected.
87
         *
88
         * @return bool If Google analytics is connected.
89
         */
90
        public function is_ga_connected() {
×
91
                return $this->site_kit_analytics_4_adapter->is_connected();
×
92
        }
93

94
        /**
95
         * If the Site Kit plugin is installed. This is needed since we cannot check with `is_plugin_active` in rest requests. `Plugin.php` is only loaded on admin pages.
96
         *
97
         * @return bool If the Site Kit plugin is installed.
98
         */
99
        private function is_site_kit_installed() {
×
100
                return \class_exists( 'Google\Site_Kit\Plugin' );
×
101
        }
102

103
        /**
104
         * If the entire onboarding has been completed.
105
         *
106
         * @return bool If the entire onboarding has been completed.
107
         */
108
        public function is_onboarded() {
×
109
                return ( $this->is_site_kit_installed() && $this->is_setup_completed() && $this->is_connected() );
×
110
        }
111

112
        /**
113
         * Return this object represented by a key value array.
114
         *
115
         * @return array<string,bool> Returns the name and if the feature is enabled.
116
         */
117
        public function to_array(): array {
×
118
                $site_kit_activate_url = \html_entity_decode(
×
119
                        \wp_nonce_url(
×
120
                                \self_admin_url( 'plugins.php?action=activate&plugin=' . self::SITE_KIT_FILE ),
×
121
                                'activate-plugin_' . self::SITE_KIT_FILE
×
122
                        )
×
123
                );
×
124

125
                $site_kit_install_url = \html_entity_decode(
×
126
                        \wp_nonce_url(
×
127
                                \self_admin_url( 'update.php?action=install-plugin&plugin=google-site-kit' ),
×
128
                                'install-plugin_google-site-kit'
×
129
                        )
×
130
                );
×
131

132
                $site_kit_setup_url = \self_admin_url( 'admin.php?page=googlesitekit-splash' );
×
133

134
                return [
×
135
                        'isInstalled'              => \file_exists( \WP_PLUGIN_DIR . '/' . self::SITE_KIT_FILE ),
×
136
                        'isActive'                 => $this->is_enabled(),
×
137
                        'isSetupCompleted'         => $this->is_setup_completed(),
×
138
                        'isConnected'              => $this->is_connected(),
×
139
                        'isGAConnected'            => $this->is_ga_connected(),
×
140
                        'isFeatureEnabled'         => ( new Google_Site_Kit_Feature_Conditional() )->is_met(),
×
141
                        'installUrl'               => $site_kit_install_url,
×
142
                        'activateUrl'              => $site_kit_activate_url,
×
143
                        'setupUrl'                 => $site_kit_setup_url,
×
144
                        'isConfigurationDismissed' => $this->permanently_dismissed_site_kit_configuration_repository->is_site_kit_configuration_dismissed(),
×
145
                ];
×
146
        }
147

148
        /**
149
         * Return this object represented by a key value array.
150
         *
151
         * @return array<string,bool> Returns the name and if the feature is enabled.
152
         */
153
        public function to_legacy_array(): array {
×
154
                return $this->to_array();
×
155
        }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc