Skip to content

Commit a4d9cc7

Browse files
authored
Merge branch 'develop' into fix/1142-amp-dev-mode
2 parents 5422198 + ddcd425 commit a4d9cc7

24 files changed

+638
-396
lines changed

includes/Core/Authentication/Authentication.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,27 +149,14 @@ public function __construct(
149149
User_Options $user_options = null,
150150
Transients $transients = null
151151
) {
152-
$this->context = $context;
153-
154-
if ( ! $options ) {
155-
$options = new Options( $this->context );
156-
}
157-
$this->options = $options;
158-
159-
if ( ! $user_options ) {
160-
$user_options = new User_Options( $this->context );
161-
}
162-
$this->user_options = $user_options;
163-
164-
if ( ! $transients ) {
165-
$transients = new Transients( $this->context );
166-
}
167-
$this->transients = $transients;
168-
152+
$this->context = $context;
153+
$this->options = $options ?: new Options( $this->context );
154+
$this->user_options = $user_options ?: new User_Options( $this->context );
155+
$this->transients = $transients ?: new Transients( $this->context );
169156
$this->google_proxy = new Google_Proxy( $this->context );
170157
$this->credentials = new Credentials( new Encrypted_Options( $this->options ) );
171158
$this->verification = new Verification( $this->user_options );
172-
$this->verification_meta = new Verification_Meta( $this->user_options, $this->transients );
159+
$this->verification_meta = new Verification_Meta( $this->user_options );
173160
$this->verification_file = new Verification_File( $this->user_options );
174161
$this->profile = new Profile( $this->user_options );
175162
$this->first_admin = new First_Admin( $this->options );
@@ -181,7 +168,10 @@ public function __construct(
181168
* @since 1.0.0
182169
*/
183170
public function register() {
184-
$this->credentials->register();
171+
$this->credentials()->register();
172+
$this->verification()->register();
173+
$this->verification_file()->register();
174+
$this->verification_meta()->register();
185175

186176
add_action(
187177
'init',

includes/Core/Authentication/Verification.php

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Google\Site_Kit\Core\Authentication;
1212

13-
use Google\Site_Kit\Core\Storage\User_Options;
13+
use Google\Site_Kit\Core\Storage\User_Setting;
1414

1515
/**
1616
* Class representing the status of whether a user is verified as an owner of the site.
@@ -19,41 +19,22 @@
1919
* @access private
2020
* @ignore
2121
*/
22-
final class Verification {
22+
final class Verification extends User_Setting {
2323

2424
/**
2525
* User option key.
2626
*/
2727
const OPTION = 'googlesitekit_site_verified_meta';
2828

2929
/**
30-
* User_Options object.
30+
* Gets the value of the setting.
3131
*
32-
* @since 1.0.0
33-
* @var User_Options
34-
*/
35-
private $user_options;
36-
37-
/**
38-
* Constructor.
39-
*
40-
* @since 1.0.0
32+
* @since n.e.x.t
4133
*
42-
* @param User_Options $user_options User Options instance.
43-
*/
44-
public function __construct( User_Options $user_options ) {
45-
$this->user_options = $user_options;
46-
}
47-
48-
/**
49-
* Retrieves the user verification tag.
50-
*
51-
* @since 1.0.0
52-
*
53-
* @return bool True if the user is verified, or false otherwise.
34+
* @return mixed Value set for the option, or default if not set.
5435
*/
5536
public function get() {
56-
return (bool) $this->user_options->get( self::OPTION );
37+
return (bool) parent::get();
5738
}
5839

5940
/**
@@ -66,21 +47,33 @@ public function get() {
6647
*/
6748
public function set( $verified ) {
6849
if ( ! $verified ) {
69-
return $this->user_options->delete( self::OPTION );
50+
return $this->delete();
7051
}
7152

72-
return $this->user_options->set( self::OPTION, 'verified' );
53+
return parent::set( '1' );
7354
}
7455

7556
/**
76-
* Checks whether the user is verified.
57+
* Gets the expected value type.
7758
*
78-
* @since 1.0.0
59+
* @since n.e.x.t
60+
*
61+
* @return string The type name.
62+
*/
63+
protected function get_type() {
64+
return 'boolean';
65+
}
66+
67+
/**
68+
* Gets the default value.
69+
*
70+
* Returns an empty string by default for consistency with get_user_meta.
71+
*
72+
* @since n.e.x.t
7973
*
80-
* @return bool True if verified, false otherwise.
74+
* @return mixed The default value.
8175
*/
82-
public function has() {
83-
// Kind of redundant, but here for consistency.
84-
return $this->get();
76+
protected function get_default() {
77+
return false;
8578
}
8679
}

includes/Core/Authentication/Verification_File.php

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Google\Site_Kit\Core\Authentication;
1212

13-
use Google\Site_Kit\Core\Storage\User_Options;
13+
use Google\Site_Kit\Core\Storage\User_Setting;
1414

1515
/**
1616
* Class representing the site verification file token for a user.
@@ -19,63 +19,10 @@
1919
* @access private
2020
* @ignore
2121
*/
22-
final class Verification_File {
22+
final class Verification_File extends User_Setting {
2323

2424
/**
2525
* User option key.
2626
*/
2727
const OPTION = 'googlesitekit_site_verification_file';
28-
29-
/**
30-
* User_Options object.
31-
*
32-
* @since 1.1.0
33-
* @var User_Options
34-
*/
35-
private $user_options;
36-
37-
/**
38-
* Constructor.
39-
*
40-
* @since 1.1.0
41-
*
42-
* @param User_Options $user_options User Options instance.
43-
*/
44-
public function __construct( User_Options $user_options ) {
45-
$this->user_options = $user_options;
46-
}
47-
48-
/**
49-
* Retrieves the user verification file token.
50-
*
51-
* @since 1.1.0
52-
*
53-
* @return string|bool Verification file token, or false if not set.
54-
*/
55-
public function get() {
56-
return $this->user_options->get( self::OPTION );
57-
}
58-
59-
/**
60-
* Saves the user verification file token.
61-
*
62-
* @since 1.1.0
63-
* @param string $token Token portion of file name to store.
64-
*
65-
* @return bool True on success, false on failure.
66-
*/
67-
public function set( $token ) {
68-
return $this->user_options->set( self::OPTION, $token );
69-
}
70-
71-
/**
72-
* Checks whether a verification file token for the user is present.
73-
*
74-
* @since 1.1.0
75-
*
76-
* @return bool True if verification file token is set, false otherwise.
77-
*/
78-
public function has() {
79-
return (bool) $this->get();
80-
}
8128
}

includes/Core/Authentication/Verification_Meta.php

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
namespace Google\Site_Kit\Core\Authentication;
1212

13-
use Google\Site_Kit\Core\Storage\User_Options;
14-
use Google\Site_Kit\Core\Storage\Transients;
13+
use Google\Site_Kit\Core\Storage\User_Setting;
1514

1615
/**
1716
* Class representing the site verification meta tag for a user.
@@ -20,105 +19,10 @@
2019
* @access private
2120
* @ignore
2221
*/
23-
final class Verification_Meta {
22+
final class Verification_Meta extends User_Setting {
2423

2524
/**
2625
* User option key.
2726
*/
2827
const OPTION = 'googlesitekit_site_verification_meta';
29-
30-
/**
31-
* User_Options object.
32-
*
33-
* @since 1.0.0
34-
* @var User_Options
35-
*/
36-
private $user_options;
37-
38-
/**
39-
* Transients object.
40-
*
41-
* @since 1.0.0
42-
* @var Transients
43-
*/
44-
private $transients;
45-
46-
/**
47-
* Constructor.
48-
*
49-
* @since 1.0.0
50-
*
51-
* @param User_Options $user_options User Options instance.
52-
* @param Transients $transients Transients instance.
53-
*/
54-
public function __construct( User_Options $user_options, Transients $transients ) {
55-
$this->user_options = $user_options;
56-
$this->transients = $transients;
57-
}
58-
59-
/**
60-
* Retrieves the user verification tag.
61-
*
62-
* @since 1.0.0
63-
*
64-
* @return string|bool Verification tag, or false if not set.
65-
*/
66-
public function get() {
67-
return $this->user_options->get( self::OPTION );
68-
}
69-
70-
/**
71-
* Saves the user verification tag.
72-
*
73-
* @since 1.0.0
74-
*
75-
* @param string $meta_tag Meta tag to store.
76-
* @return bool True on success, false on failure.
77-
*/
78-
public function set( $meta_tag ) {
79-
$status = $this->user_options->set( self::OPTION, $meta_tag );
80-
if ( $status ) {
81-
$this->transients->delete( 'googlesitekit_verification_meta_tags' );
82-
}
83-
return $status;
84-
}
85-
86-
/**
87-
* Checks whether a verification tag for the user is present.
88-
*
89-
* @since 1.0.0
90-
*
91-
* @return bool True if verification meta tag is set, false otherwise.
92-
*/
93-
public function has() {
94-
$meta_tag = (string) $this->get();
95-
return ! empty( $meta_tag );
96-
}
97-
98-
/**
99-
* Gets all available verification tags for all users.
100-
*
101-
* This is a special method needed for printing all meta tags in the frontend.
102-
*
103-
* @since 1.0.0
104-
*
105-
* @return array List of verification meta tags.
106-
*/
107-
public function get_all() {
108-
global $wpdb;
109-
110-
$meta_tags = $this->transients->get( 'googlesitekit_verification_meta_tags' );
111-
112-
if ( false === $meta_tags ) {
113-
$meta_key = self::OPTION;
114-
if ( ! \Google\Site_Kit\Plugin::instance()->context()->is_network_mode() ) {
115-
$meta_key = $wpdb->get_blog_prefix() . $meta_key;
116-
}
117-
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
118-
$meta_tags = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", $meta_key ) );
119-
$this->transients->set( 'googlesitekit_verification_meta_tags', $meta_tags );
120-
}
121-
122-
return (array) $meta_tags;
123-
}
12428
}

includes/Core/Modules/Module.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,11 @@ public function __construct(
119119
User_Options $user_options = null,
120120
Authentication $authentication = null
121121
) {
122-
$this->context = $context;
123-
124-
if ( ! $options ) {
125-
$options = new Options( $this->context );
126-
}
127-
$this->options = $options;
128-
129-
if ( ! $user_options ) {
130-
$user_options = new User_Options( $this->context );
131-
}
132-
$this->user_options = $user_options;
133-
134-
if ( ! $authentication ) {
135-
$authentication = new Authentication( $this->context, $this->options, $this->user_options );
136-
}
137-
$this->authentication = $authentication;
138-
139-
$this->info = $this->parse_info( (array) $this->setup_info() );
122+
$this->context = $context;
123+
$this->options = $options ?: new Options( $this->context );
124+
$this->user_options = $user_options ?: new User_Options( $this->context );
125+
$this->authentication = $authentication ?: new Authentication( $this->context, $this->options, $this->user_options );
126+
$this->info = $this->parse_info( (array) $this->setup_info() );
140127
}
141128

142129
/**

0 commit comments

Comments
 (0)