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

Yoast / wordpress-seo / 1471b9e2737fa22c239111a2d7ba7f4ffbf6578a

04 Mar 2025 03:10PM UTC coverage: 42.445%. First build
1471b9e2737fa22c239111a2d7ba7f4ffbf6578a

Pull #22073

github

web-flow
Merge d3b6b1ce0 into e63516006
Pull Request #22073: Add Organic Sessions widget

1995 of 7731 branches covered (25.81%)

Branch coverage included in aggregate %.

83 of 93 new or added lines in 12 files covered. (89.25%)

21049 of 46560 relevant lines covered (45.21%)

4.44 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

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

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

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

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

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

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

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

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

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

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

93
        /**
94
         * If the Site Kit plugin is installed. This is needed since we cannot check with `is_plugin_active` in rest
95
         * 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(),
×
NEW
139
                        'isAnalyticsConnected'     => $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