PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.4
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / dashboard / infrastructure / connection / site-kit-is-connected-call.php

site-kit-is-connected-call.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.4, at src/dashboard/infrastructure/connection/site-kit-is-connected-call.php

62 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 // phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
5 namespace Yoast\WP\SEO\Dashboard\Infrastructure\Connection;
6
7 use Google\Site_Kit\Core\REST_API\REST_Routes;
8 use WP_REST_Request;
9
10 /**
11 * Class that hold the code to do the REST call to the Site Kit api.
12 *
13 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
14 */
15 class Site_Kit_Is_Connected_Call {
16
17 /**
18 * Runs the internal REST api call.
19 *
20 * @return bool
21 */
22 public function is_setup_completed(): bool {
23 if ( ! \class_exists( REST_Routes::class ) ) {
24 return false;
25 }
26
27 $request = new WP_REST_Request( 'GET', '/' . REST_Routes::REST_ROOT . '/core/site/data/connection' );
28
29 $response = \rest_do_request( $request );
30
31 if ( $response->is_error() ) {
32 return false;
33 }
34 return $response->get_data()['setupCompleted'];
35 }
36
37 /**
38 * Runs the internal REST api call.
39 *
40 * @return bool
41 */
42 public function is_ga_connected(): bool {
43 if ( ! \class_exists( REST_Routes::class ) ) {
44 return false;
45 }
46 $request = new WP_REST_Request( 'GET', '/' . REST_Routes::REST_ROOT . '/core/modules/data/list' );
47 $response = \rest_do_request( $request );
48
49 if ( $response->is_error() ) {
50 return false;
51 }
52 $connected = false;
53 foreach ( $response->get_data() as $module ) {
54 if ( $module['slug'] === 'analytics-4' ) {
55 $connected = $module['connected'];
56 }
57 }
58
59 return $connected;
60 }
61 }
62