Version Description
Download this release
Release Info
Developer | flixos90 |
Plugin | Site Kit by Google |
Version | 1.8.1 |
Comparing to | |
See all releases |
Code changes from version 1.8.0 to 1.8.1
- google-site-kit.php +2 -2
- includes/Core/Authentication/Authentication.php +11 -6
- includes/Core/Authentication/Clients/OAuth_Client.php +15 -2
- includes/Core/Authentication/Verification_File.php +1 -1
- includes/Core/Authentication/Verification_Meta.php +1 -1
- includes/Core/Permissions/Permissions.php +2 -2
- includes/Core/Util/Migration_1_5_0.php +0 -96
- includes/Core/Util/Migration_1_8_1.php +257 -0
- includes/Modules/Site_Verification.php +1 -1
- includes/Plugin.php +2 -1
- includes/vendor/composer/autoload_classmap.php +1 -1
- readme.txt +1 -1
google-site-kit.php
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
* Plugin Name: Site Kit by Google
|
12 |
* Plugin URI: https://sitekit.withgoogle.com
|
13 |
* Description: Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
|
14 |
-
* Version: 1.8.
|
15 |
* Author: Google
|
16 |
* Author URI: https://opensource.google.com
|
17 |
* License: Apache License 2.0
|
@@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
24 |
}
|
25 |
|
26 |
// Define most essential constants.
|
27 |
-
define( 'GOOGLESITEKIT_VERSION', '1.8.
|
28 |
define( 'GOOGLESITEKIT_PLUGIN_MAIN_FILE', __FILE__ );
|
29 |
define( 'GOOGLESITEKIT_PHP_MINIMUM', '5.6.0' );
|
30 |
|
11 |
* Plugin Name: Site Kit by Google
|
12 |
* Plugin URI: https://sitekit.withgoogle.com
|
13 |
* Description: Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
|
14 |
+
* Version: 1.8.1
|
15 |
* Author: Google
|
16 |
* Author URI: https://opensource.google.com
|
17 |
* License: Apache License 2.0
|
24 |
}
|
25 |
|
26 |
// Define most essential constants.
|
27 |
+
define( 'GOOGLESITEKIT_VERSION', '1.8.1' );
|
28 |
define( 'GOOGLESITEKIT_PLUGIN_MAIN_FILE', __FILE__ );
|
29 |
define( 'GOOGLESITEKIT_PHP_MINIMUM', '5.6.0' );
|
30 |
|
includes/Core/Authentication/Authentication.php
CHANGED
@@ -376,10 +376,7 @@ final class Authentication {
|
|
376 |
|
377 |
// Delete all user data.
|
378 |
$user_id = $this->user_options->get_user_id();
|
379 |
-
$prefix = 'googlesitekit\_%';
|
380 |
-
if ( ! $this->context->is_network_mode() ) {
|
381 |
-
$prefix = $wpdb->get_blog_prefix() . $prefix;
|
382 |
-
}
|
383 |
|
384 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
385 |
$wpdb->query(
|
@@ -480,6 +477,10 @@ final class Authentication {
|
|
480 |
|
481 |
// Handles Direct OAuth client request.
|
482 |
if ( $input->filter( INPUT_GET, 'oauth2callback' ) ) {
|
|
|
|
|
|
|
|
|
483 |
$auth_client->authorize_user();
|
484 |
}
|
485 |
|
@@ -494,7 +495,7 @@ final class Authentication {
|
|
494 |
}
|
495 |
|
496 |
if ( ! current_user_can( Permissions::AUTHENTICATE ) ) {
|
497 |
-
wp_die( esc_html__( 'You don\'t have permissions to
|
498 |
}
|
499 |
|
500 |
$this->disconnect();
|
@@ -517,7 +518,7 @@ final class Authentication {
|
|
517 |
}
|
518 |
|
519 |
if ( ! current_user_can( Permissions::AUTHENTICATE ) ) {
|
520 |
-
wp_die( esc_html__( 'You don\'t have permissions to
|
521 |
}
|
522 |
|
523 |
$redirect_url = $input->filter( INPUT_GET, 'redirect', FILTER_VALIDATE_URL );
|
@@ -930,6 +931,10 @@ final class Authentication {
|
|
930 |
return;
|
931 |
}
|
932 |
|
|
|
|
|
|
|
|
|
933 |
try {
|
934 |
$data = $this->google_proxy->exchange_site_code( $site_code, $code );
|
935 |
|
376 |
|
377 |
// Delete all user data.
|
378 |
$user_id = $this->user_options->get_user_id();
|
379 |
+
$prefix = $this->user_options->get_meta_key( 'googlesitekit\_%' );
|
|
|
|
|
|
|
380 |
|
381 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
382 |
$wpdb->query(
|
477 |
|
478 |
// Handles Direct OAuth client request.
|
479 |
if ( $input->filter( INPUT_GET, 'oauth2callback' ) ) {
|
480 |
+
if ( ! current_user_can( Permissions::AUTHENTICATE ) ) {
|
481 |
+
wp_die( esc_html__( 'You don\'t have permissions to authenticate with Site Kit.', 'google-site-kit' ), 403 );
|
482 |
+
}
|
483 |
+
|
484 |
$auth_client->authorize_user();
|
485 |
}
|
486 |
|
495 |
}
|
496 |
|
497 |
if ( ! current_user_can( Permissions::AUTHENTICATE ) ) {
|
498 |
+
wp_die( esc_html__( 'You don\'t have permissions to authenticate with Site Kit.', 'google-site-kit' ), 403 );
|
499 |
}
|
500 |
|
501 |
$this->disconnect();
|
518 |
}
|
519 |
|
520 |
if ( ! current_user_can( Permissions::AUTHENTICATE ) ) {
|
521 |
+
wp_die( esc_html__( 'You don\'t have permissions to authenticate with Site Kit.', 'google-site-kit' ), 403 );
|
522 |
}
|
523 |
|
524 |
$redirect_url = $input->filter( INPUT_GET, 'redirect', FILTER_VALIDATE_URL );
|
931 |
return;
|
932 |
}
|
933 |
|
934 |
+
if ( ! current_user_can( Permissions::SETUP ) ) {
|
935 |
+
wp_die( esc_html__( 'You don\'t have permissions to set up Site Kit.', 'google-site-kit' ), 403 );
|
936 |
+
}
|
937 |
+
|
938 |
try {
|
939 |
$data = $this->google_proxy->exchange_site_code( $site_code, $code );
|
940 |
|
includes/Core/Authentication/Clients/OAuth_Client.php
CHANGED
@@ -213,7 +213,7 @@ final class OAuth_Client {
|
|
213 |
$client = new Google_Site_Kit_Client();
|
214 |
}
|
215 |
|
216 |
-
$application_name =
|
217 |
// The application name is included in the Google client's user-agent for requests to Google APIs.
|
218 |
$client->setApplicationName( $application_name );
|
219 |
// Override the default user-agent for the Guzzle client. This is used for oauth/token requests.
|
@@ -746,7 +746,7 @@ final class OAuth_Client {
|
|
746 |
$site_fields = array_map( 'rawurlencode', $this->google_proxy->get_site_fields() );
|
747 |
$query_params = array_merge( $query_params, $site_fields );
|
748 |
}
|
749 |
-
|
750 |
return add_query_arg( $query_params, $this->google_proxy->url( Google_Proxy::SETUP_URI ) );
|
751 |
}
|
752 |
|
@@ -808,9 +808,22 @@ final class OAuth_Client {
|
|
808 |
$query_args['site_id'] = $credentials->web->client_id;
|
809 |
}
|
810 |
|
|
|
|
|
811 |
return add_query_arg( $query_args, $this->google_proxy->url( Google_Proxy::PERMISSIONS_URI ) );
|
812 |
}
|
813 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
814 |
/**
|
815 |
* Converts the given error code to a user-facing message.
|
816 |
*
|
213 |
$client = new Google_Site_Kit_Client();
|
214 |
}
|
215 |
|
216 |
+
$application_name = $this->get_application_name();
|
217 |
// The application name is included in the Google client's user-agent for requests to Google APIs.
|
218 |
$client->setApplicationName( $application_name );
|
219 |
// Override the default user-agent for the Guzzle client. This is used for oauth/token requests.
|
746 |
$site_fields = array_map( 'rawurlencode', $this->google_proxy->get_site_fields() );
|
747 |
$query_params = array_merge( $query_params, $site_fields );
|
748 |
}
|
749 |
+
$query_params['application_name'] = rawurlencode( $this->get_application_name() );
|
750 |
return add_query_arg( $query_params, $this->google_proxy->url( Google_Proxy::SETUP_URI ) );
|
751 |
}
|
752 |
|
808 |
$query_args['site_id'] = $credentials->web->client_id;
|
809 |
}
|
810 |
|
811 |
+
$query_args['application_name'] = rawurlencode( $this->get_application_name() );
|
812 |
+
|
813 |
return add_query_arg( $query_args, $this->google_proxy->url( Google_Proxy::PERMISSIONS_URI ) );
|
814 |
}
|
815 |
|
816 |
+
/**
|
817 |
+
* Returns the application name: a combination of the namespace and version.
|
818 |
+
*
|
819 |
+
* @since 1.8.1
|
820 |
+
*
|
821 |
+
* @return string The application name.
|
822 |
+
*/
|
823 |
+
private function get_application_name() {
|
824 |
+
return 'wordpress/google-site-kit/' . GOOGLESITEKIT_VERSION;
|
825 |
+
}
|
826 |
+
|
827 |
/**
|
828 |
* Converts the given error code to a user-facing message.
|
829 |
*
|
includes/Core/Authentication/Verification_File.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Class Verification_File
|
4 |
*
|
5 |
* @package Google\Site_Kit
|
6 |
* @copyright 2019 Google LLC
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Class Google\Site_Kit\Core\Authentication\Verification_File
|
4 |
*
|
5 |
* @package Google\Site_Kit
|
6 |
* @copyright 2019 Google LLC
|
includes/Core/Authentication/Verification_Meta.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Class Verification_Meta
|
4 |
*
|
5 |
* @package Google\Site_Kit
|
6 |
* @copyright 2019 Google LLC
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Class Google\Site_Kit\Core\Authentication\Verification_Meta
|
4 |
*
|
5 |
* @package Google\Site_Kit
|
6 |
* @copyright 2019 Google LLC
|
includes/Core/Permissions/Permissions.php
CHANGED
@@ -213,8 +213,8 @@ final class Permissions {
|
|
213 |
// Special setup and authentication rules.
|
214 |
if ( ( isset( $this->primitive_to_core[ $cap ] ) || isset( $this->meta_to_core[ $cap ] ) ) ) {
|
215 |
// If setup has not yet been completed, require administrator capabilities for everything.
|
216 |
-
if ( self::
|
217 |
-
$caps[] = self::
|
218 |
}
|
219 |
|
220 |
if ( ! in_array( $cap, array( self::AUTHENTICATE, self::SETUP ), true ) ) {
|
213 |
// Special setup and authentication rules.
|
214 |
if ( ( isset( $this->primitive_to_core[ $cap ] ) || isset( $this->meta_to_core[ $cap ] ) ) ) {
|
215 |
// If setup has not yet been completed, require administrator capabilities for everything.
|
216 |
+
if ( self::SETUP !== $cap && ! $this->authentication->is_setup_completed() ) {
|
217 |
+
$caps[] = self::SETUP;
|
218 |
}
|
219 |
|
220 |
if ( ! in_array( $cap, array( self::AUTHENTICATE, self::SETUP ), true ) ) {
|
includes/Core/Util/Migration_1_5_0.php
DELETED
@@ -1,96 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Class Google\Site_Kit\Core\Util\Migration_1_5_0
|
4 |
-
*
|
5 |
-
* @package Google\Site_Kit\Core\Util
|
6 |
-
* @copyright 2020 Google LLC
|
7 |
-
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
8 |
-
* @link https://sitekit.withgoogle.com
|
9 |
-
*/
|
10 |
-
|
11 |
-
namespace Google\Site_Kit\Core\Util;
|
12 |
-
|
13 |
-
use Google\Site_Kit\Context;
|
14 |
-
use Google\Site_Kit\Core\Storage\Options;
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Class Migration_1_5_0
|
18 |
-
*
|
19 |
-
* @since 1.5.0
|
20 |
-
* @access private
|
21 |
-
* @ignore
|
22 |
-
* @property-read string $db_version
|
23 |
-
*/
|
24 |
-
class Migration_1_5_0 /* phpcs:ignore PEAR.NamingConventions.ValidClassName.Invalid */ {
|
25 |
-
/**
|
26 |
-
* Target DB version.
|
27 |
-
*
|
28 |
-
* @var string
|
29 |
-
*/
|
30 |
-
protected $db_version = '1.5.0';
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Context instance.
|
34 |
-
*
|
35 |
-
* @var Context
|
36 |
-
*/
|
37 |
-
protected $context;
|
38 |
-
|
39 |
-
/**
|
40 |
-
* Options instance.
|
41 |
-
*
|
42 |
-
* @var Options
|
43 |
-
*/
|
44 |
-
protected $options;
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Constructor.
|
48 |
-
*
|
49 |
-
* @since 1.5.0
|
50 |
-
*
|
51 |
-
* @param Context $context Plugin context instance.
|
52 |
-
* @param Options $options Optional. Options instance.
|
53 |
-
*/
|
54 |
-
public function __construct( Context $context, Options $options = null ) {
|
55 |
-
$this->context = $context;
|
56 |
-
$this->options = $options ?: new Options( $context );
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Registers hooks.
|
61 |
-
*
|
62 |
-
* @since 1.5.0
|
63 |
-
*/
|
64 |
-
public function register() {
|
65 |
-
add_action( 'admin_init', array( $this, 'migrate' ) );
|
66 |
-
}
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Migrates the DB.
|
70 |
-
*
|
71 |
-
* @since 1.5.0
|
72 |
-
*/
|
73 |
-
public function migrate() {
|
74 |
-
$db_version = $this->options->get( 'googlesitekit_db_version' );
|
75 |
-
|
76 |
-
if ( ! $db_version || version_compare( $db_version, $this->db_version, '<' ) ) {
|
77 |
-
$this->options->set( 'googlesitekit_db_version', $this->db_version );
|
78 |
-
}
|
79 |
-
}
|
80 |
-
|
81 |
-
/**
|
82 |
-
* Gets protected properties.
|
83 |
-
*
|
84 |
-
* @since 1.5.0
|
85 |
-
*
|
86 |
-
* @param string $name Property name.
|
87 |
-
*
|
88 |
-
* @return mixed
|
89 |
-
*/
|
90 |
-
public function __get( $name ) {
|
91 |
-
if ( 'db_version' === $name ) {
|
92 |
-
return $this->db_version;
|
93 |
-
}
|
94 |
-
return null;
|
95 |
-
}
|
96 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/Core/Util/Migration_1_8_1.php
ADDED
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Migration for 1.8.1
|
4 |
+
*
|
5 |
+
* @package Google\Site_Kit\Core\Util
|
6 |
+
* @copyright 2020 Google LLC
|
7 |
+
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
8 |
+
* @link https://sitekit.withgoogle.com
|
9 |
+
*/
|
10 |
+
|
11 |
+
namespace Google\Site_Kit\Core\Util;
|
12 |
+
|
13 |
+
use Google\Site_Kit\Context;
|
14 |
+
use Google\Site_Kit\Core\Authentication\Authentication;
|
15 |
+
use Google\Site_Kit\Core\Authentication\Google_Proxy;
|
16 |
+
use Google\Site_Kit\Core\Authentication\Profile;
|
17 |
+
use Google\Site_Kit\Core\Authentication\Verification_File;
|
18 |
+
use Google\Site_Kit\Core\Authentication\Verification_Meta;
|
19 |
+
use Google\Site_Kit\Core\Permissions\Permissions;
|
20 |
+
use Google\Site_Kit\Core\Storage\Options;
|
21 |
+
use Google\Site_Kit\Core\Storage\User_Options;
|
22 |
+
use WP_User;
|
23 |
+
use WP_Error;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Class Migration_1_8_1
|
27 |
+
*
|
28 |
+
* @since 1.8.1
|
29 |
+
* @access private
|
30 |
+
* @ignore
|
31 |
+
*/
|
32 |
+
class Migration_1_8_1 {
|
33 |
+
/**
|
34 |
+
* Target DB version.
|
35 |
+
*/
|
36 |
+
const DB_VERSION = '1.8.1';
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Context instance.
|
40 |
+
*
|
41 |
+
* @since 1.8.1
|
42 |
+
* @var Context
|
43 |
+
*/
|
44 |
+
protected $context;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Options instance.
|
48 |
+
*
|
49 |
+
* @since 1.8.1
|
50 |
+
* @var Options
|
51 |
+
*/
|
52 |
+
protected $options;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* User_Options instance.
|
56 |
+
*
|
57 |
+
* @since 1.8.1
|
58 |
+
* @var User_Options
|
59 |
+
*/
|
60 |
+
protected $user_options;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Authentication instance.
|
64 |
+
*
|
65 |
+
* @since 1.8.1
|
66 |
+
* @var Authentication
|
67 |
+
*/
|
68 |
+
protected $authentication;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Constructor.
|
72 |
+
*
|
73 |
+
* @since 1.8.1
|
74 |
+
*
|
75 |
+
* @param Context $context Plugin context instance.
|
76 |
+
* @param Options $options Optional. Options instance.
|
77 |
+
* @param User_Options $user_options Optional. User_Options instance.
|
78 |
+
* @param Authentication $authentication Optional. Authentication instance. Default is a new instance.
|
79 |
+
*/
|
80 |
+
public function __construct(
|
81 |
+
Context $context,
|
82 |
+
Options $options = null,
|
83 |
+
User_Options $user_options = null,
|
84 |
+
Authentication $authentication = null
|
85 |
+
) {
|
86 |
+
$this->context = $context;
|
87 |
+
$this->options = $options ?: new Options( $this->context );
|
88 |
+
$this->user_options = $user_options ?: new User_Options( $this->context );
|
89 |
+
$this->authentication = $authentication ?: new Authentication( $this->context, $this->options, $this->user_options );
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Registers hooks.
|
94 |
+
*
|
95 |
+
* @since 1.8.1
|
96 |
+
*/
|
97 |
+
public function register() {
|
98 |
+
add_action( 'admin_init', array( $this, 'migrate' ) );
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Migrates the DB.
|
103 |
+
*
|
104 |
+
* @since 1.8.1
|
105 |
+
*/
|
106 |
+
public function migrate() {
|
107 |
+
$db_version = $this->options->get( 'googlesitekit_db_version' );
|
108 |
+
|
109 |
+
// Do not run if database version already updated.
|
110 |
+
if ( $db_version && version_compare( $db_version, self::DB_VERSION, '>=' ) ) {
|
111 |
+
return;
|
112 |
+
}
|
113 |
+
|
114 |
+
// Only run routine if using the authentication service, otherwise it
|
115 |
+
// is irrelevant.
|
116 |
+
if ( ! $this->authentication->get_oauth_client()->using_proxy() ) {
|
117 |
+
return;
|
118 |
+
}
|
119 |
+
|
120 |
+
// Only run routine once site credentials present, otherwise it is not
|
121 |
+
// possible to connect to the authentication service.
|
122 |
+
if ( ! $this->authentication->credentials()->has() ) {
|
123 |
+
return;
|
124 |
+
}
|
125 |
+
|
126 |
+
$this->clear_and_flag_unauthorized_verified_users();
|
127 |
+
|
128 |
+
// Update database version.
|
129 |
+
$this->options->set( 'googlesitekit_db_version', self::DB_VERSION );
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Checks whether there are any users that are verified without proper
|
134 |
+
* authorization, clear their Site Kit data, and flag them on the
|
135 |
+
* authentication service.
|
136 |
+
*
|
137 |
+
* @since 1.8.1
|
138 |
+
*
|
139 |
+
* @return boolean|WP_Error True on success, WP_Error on failure.
|
140 |
+
*/
|
141 |
+
private function clear_and_flag_unauthorized_verified_users() {
|
142 |
+
// Detect all unauthorized verified users and clean their Site Kit data.
|
143 |
+
$unauthorized_identifiers = $this->clear_unauthorized_verified_users();
|
144 |
+
|
145 |
+
// If no unauthorized verified users found, all is well, no need to
|
146 |
+
// show a notification.
|
147 |
+
if ( empty( $unauthorized_identifiers ) ) {
|
148 |
+
return true;
|
149 |
+
}
|
150 |
+
|
151 |
+
// Flag site as affected so that the notification to inform and explain
|
152 |
+
// steps to resolve will be shown.
|
153 |
+
$credentials = $this->authentication->credentials()->get();
|
154 |
+
$google_proxy = new Google_Proxy( $this->context );
|
155 |
+
$response = wp_remote_post(
|
156 |
+
$google_proxy->url( '/notifications/mark/' ),
|
157 |
+
array(
|
158 |
+
'body' => array(
|
159 |
+
'site_id' => $credentials['oauth2_client_id'],
|
160 |
+
'site_secret' => $credentials['oauth2_client_secret'],
|
161 |
+
'notification_id' => 'verification_leak',
|
162 |
+
'notification_state' => 'required',
|
163 |
+
// This is a special parameter only supported for this
|
164 |
+
// particular notification.
|
165 |
+
'identifiers' => implode( ',', $unauthorized_identifiers ),
|
166 |
+
),
|
167 |
+
)
|
168 |
+
);
|
169 |
+
|
170 |
+
if ( is_wp_error( $response ) ) {
|
171 |
+
return $response;
|
172 |
+
}
|
173 |
+
|
174 |
+
$response_code = wp_remote_retrieve_response_code( $response );
|
175 |
+
if ( 200 !== $response_code ) {
|
176 |
+
$body = wp_remote_retrieve_body( $response );
|
177 |
+
$decoded = json_decode( $body, true );
|
178 |
+
return new WP_Error( $response_code, ! empty( $decoded['error'] ) ? $decoded['error'] : $body );
|
179 |
+
}
|
180 |
+
return true;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Checks for any users that are verified without proper authorization and
|
185 |
+
* clears all their Site Kit data.
|
186 |
+
*
|
187 |
+
* @since 1.8.1
|
188 |
+
*
|
189 |
+
* @return array List of email addresses for the unauthorized users.
|
190 |
+
*/
|
191 |
+
private function clear_unauthorized_verified_users() {
|
192 |
+
global $wpdb;
|
193 |
+
|
194 |
+
$unauthorized_identifiers = array();
|
195 |
+
$profile = new Profile( $this->user_options );
|
196 |
+
|
197 |
+
// Store original user ID to switch back later.
|
198 |
+
$backup_user_id = $this->user_options->get_user_id();
|
199 |
+
|
200 |
+
// Iterate through all users verified via Site Kit.
|
201 |
+
foreach ( $this->get_verified_users() as $user ) {
|
202 |
+
$user_id = (int) $user->ID;
|
203 |
+
$this->user_options->switch_user( $user_id );
|
204 |
+
|
205 |
+
// If the user has setup access, there is no problem.
|
206 |
+
if ( user_can( $user_id, Permissions::SETUP ) ) {
|
207 |
+
continue;
|
208 |
+
}
|
209 |
+
|
210 |
+
// Try to get profile email, otherwise fall back to WP email.
|
211 |
+
if ( $this->authentication->profile()->has() ) {
|
212 |
+
$unauthorized_identifiers[] = $this->authentication->profile()->get()['email'];
|
213 |
+
} else {
|
214 |
+
$unauthorized_identifiers[] = $user->user_email;
|
215 |
+
}
|
216 |
+
|
217 |
+
$prefix = $this->user_options->get_meta_key( 'googlesitekit\_%' );
|
218 |
+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
219 |
+
$wpdb->query(
|
220 |
+
$wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key LIKE %s", $user_id, $prefix )
|
221 |
+
);
|
222 |
+
wp_cache_delete( $user_id, 'user_meta' );
|
223 |
+
}
|
224 |
+
|
225 |
+
// Restore original user ID.
|
226 |
+
$this->user_options->switch_user( $backup_user_id );
|
227 |
+
|
228 |
+
return $unauthorized_identifiers;
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Gets all users that are verified via Site Kit.
|
233 |
+
*
|
234 |
+
* @since 1.8.1
|
235 |
+
*
|
236 |
+
* @return WP_User[] User objects of verified users. Maximum of 20.
|
237 |
+
*/
|
238 |
+
private function get_verified_users() {
|
239 |
+
return get_users(
|
240 |
+
array(
|
241 |
+
'number' => 20,
|
242 |
+
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery
|
243 |
+
'relation' => 'OR',
|
244 |
+
array(
|
245 |
+
'key' => $this->user_options->get_meta_key( Verification_File::OPTION ),
|
246 |
+
'compare' => 'EXISTS',
|
247 |
+
),
|
248 |
+
array(
|
249 |
+
'key' => $this->user_options->get_meta_key( Verification_Meta::OPTION ),
|
250 |
+
'compare' => 'EXISTS',
|
251 |
+
),
|
252 |
+
),
|
253 |
+
)
|
254 |
+
);
|
255 |
+
}
|
256 |
+
|
257 |
+
}
|
includes/Modules/Site_Verification.php
CHANGED
@@ -398,7 +398,7 @@ final class Site_Verification extends Module implements Module_With_Scopes {
|
|
398 |
}
|
399 |
|
400 |
if ( ! current_user_can( Permissions::SETUP ) ) {
|
401 |
-
wp_die( esc_html__( '
|
402 |
}
|
403 |
|
404 |
switch ( $verification_type ) {
|
398 |
}
|
399 |
|
400 |
if ( ! current_user_can( Permissions::SETUP ) ) {
|
401 |
+
wp_die( esc_html__( 'You don\'t have permissions to set up Site Kit.', 'google-site-kit' ), 403 );
|
402 |
}
|
403 |
|
404 |
switch ( $verification_type ) {
|
includes/Plugin.php
CHANGED
@@ -158,6 +158,8 @@ final class Plugin {
|
|
158 |
( new Core\Notifications\Notifications( $this->context, $options, $authentication ) )->register();
|
159 |
( new Core\Util\Debug_Data( $this->context, $options, $user_options, $authentication, $modules ) )->register();
|
160 |
( new Core\Admin\Standalone( $this->context ) )->register();
|
|
|
|
|
161 |
|
162 |
// If a login is happening (runs after 'init'), update current user in dependency chain.
|
163 |
add_action(
|
@@ -189,7 +191,6 @@ final class Plugin {
|
|
189 |
);
|
190 |
|
191 |
( new Core\Util\Activation( $this->context, $options, $assets ) )->register();
|
192 |
-
( new Core\Util\Migration_1_3_0( $this->context, $options ) )->register();
|
193 |
( new Core\Util\Reset( $this->context ) )->register();
|
194 |
( new Core\Util\Developer_Plugin_Installer( $this->context ) )->register();
|
195 |
}
|
158 |
( new Core\Notifications\Notifications( $this->context, $options, $authentication ) )->register();
|
159 |
( new Core\Util\Debug_Data( $this->context, $options, $user_options, $authentication, $modules ) )->register();
|
160 |
( new Core\Admin\Standalone( $this->context ) )->register();
|
161 |
+
( new Core\Util\Migration_1_3_0( $this->context, $options, $user_options ) )->register();
|
162 |
+
( new Core\Util\Migration_1_8_1( $this->context, $options, $user_options, $authentication ) )->register();
|
163 |
|
164 |
// If a login is happening (runs after 'init'), update current user in dependency chain.
|
165 |
add_action(
|
191 |
);
|
192 |
|
193 |
( new Core\Util\Activation( $this->context, $options, $assets ) )->register();
|
|
|
194 |
( new Core\Util\Reset( $this->context ) )->register();
|
195 |
( new Core\Util\Developer_Plugin_Installer( $this->context ) )->register();
|
196 |
}
|
includes/vendor/composer/autoload_classmap.php
CHANGED
@@ -73,7 +73,7 @@ return array(
|
|
73 |
'Google\\Site_Kit\\Core\\Util\\Input' => $baseDir . '/Core/Util/Input.php',
|
74 |
'Google\\Site_Kit\\Core\\Util\\Migrate_Legacy_Keys' => $baseDir . '/Core/Util/Migrate_Legacy_Keys.php',
|
75 |
'Google\\Site_Kit\\Core\\Util\\Migration_1_3_0' => $baseDir . '/Core/Util/Migration_1_3_0.php',
|
76 |
-
'Google\\Site_Kit\\Core\\Util\\
|
77 |
'Google\\Site_Kit\\Core\\Util\\Requires_Javascript_Trait' => $baseDir . '/Core/Util/Requires_Javascript_Trait.php',
|
78 |
'Google\\Site_Kit\\Core\\Util\\Reset' => $baseDir . '/Core/Util/Reset.php',
|
79 |
'Google\\Site_Kit\\Core\\Util\\Tracking' => $baseDir . '/Core/Util/Tracking.php',
|
73 |
'Google\\Site_Kit\\Core\\Util\\Input' => $baseDir . '/Core/Util/Input.php',
|
74 |
'Google\\Site_Kit\\Core\\Util\\Migrate_Legacy_Keys' => $baseDir . '/Core/Util/Migrate_Legacy_Keys.php',
|
75 |
'Google\\Site_Kit\\Core\\Util\\Migration_1_3_0' => $baseDir . '/Core/Util/Migration_1_3_0.php',
|
76 |
+
'Google\\Site_Kit\\Core\\Util\\Migration_1_8_1' => $baseDir . '/Core/Util/Migration_1_8_1.php',
|
77 |
'Google\\Site_Kit\\Core\\Util\\Requires_Javascript_Trait' => $baseDir . '/Core/Util/Requires_Javascript_Trait.php',
|
78 |
'Google\\Site_Kit\\Core\\Util\\Reset' => $baseDir . '/Core/Util/Reset.php',
|
79 |
'Google\\Site_Kit\\Core\\Util\\Tracking' => $baseDir . '/Core/Util/Tracking.php',
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Contributors: google
|
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 5.4
|
6 |
Requires PHP: 5.6
|
7 |
-
Stable tag: 1.8.
|
8 |
License: Apache License 2.0
|
9 |
License URI: https://www.apache.org/licenses/LICENSE-2.0
|
10 |
Tags: google, search-console, analytics, adsense, pagespeed-insights, optimize, tag-manager, site-kit
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 5.4
|
6 |
Requires PHP: 5.6
|
7 |
+
Stable tag: 1.8.1
|
8 |
License: Apache License 2.0
|
9 |
License URI: https://www.apache.org/licenses/LICENSE-2.0
|
10 |
Tags: google, search-console, analytics, adsense, pagespeed-insights, optimize, tag-manager, site-kit
|