SG Optimizer - Version 7.0.9

Version Description

Download this release

Release Info

Developer elenachavdarova
Plugin Icon 128x128 SG Optimizer
Version 7.0.9
Comparing to
See all releases

Code changes from version 7.0.8 to 7.0.9

core/File_Cacher/Cache.php CHANGED
@@ -8,7 +8,6 @@
8
 
9
  namespace SiteGround_Optimizer\File_Cacher;
10
 
11
- use SiteGround_Optimizer\Helper\Helper;
12
  use SiteGround_Optimizer\Helper\File_Cacher_Trait;
13
  /**
14
  * SG File Cacher main class
@@ -106,86 +105,7 @@ class Cache {
106
  * @return boolean True if the user is logged in, false otherwise.
107
  */
108
  public function is_logged_in() {
109
- // Bail, if user not logged in.
110
- if ( ! in_array( $this->logged_in_cookie, array_keys( $_COOKIE ), true ) ) {
111
- return false;
112
- }
113
-
114
- // Include class, since we are performing those checks before the plugin is loaded.
115
- require_once dirname( __DIR__ ) . '/Helper/Helper.php';
116
-
117
- // Get the active plugins.
118
- $active_plugins = Helper::sg_get_db_entry( 'options', 'option_value', 'option_name', 'active_plugins' );
119
-
120
- // Bail if we do not fetch the active plugins.
121
- if ( empty( $active_plugins ) ) {
122
- return true;
123
- }
124
-
125
- // Bail if the SG-Security is not enabled.
126
- if( ! preg_match( '~sg-security\/sg-security.php~', $active_plugins[0]['option_value'] ) ) {
127
- return true;
128
- }
129
-
130
- $sg_2fa_option = Helper::sg_get_db_entry( 'options', 'option_value', 'option_name', 'sg_security_sg2fa' );
131
-
132
- // Check if 2fa option is enabled.
133
- if ( empty( $sg_2fa_option ) ) {
134
- return true;
135
- }
136
-
137
- // Bail if the option is disabled.
138
- if ( 0 === (int) $sg_2fa_option[0]['option_value'] ) {
139
- return true;
140
- }
141
-
142
- // Get the user data.
143
- $user_data = Helper::sg_get_db_entry( 'users', 'ID', 'user_login', $this->get_user_login() );
144
-
145
- // Bail if no user data is found.
146
- if ( empty( $user_data ) ) {
147
- return false;
148
- }
149
-
150
- // Get the user ID.
151
- $user_id = $user_data[0]['ID'];
152
-
153
- // Get all 2fa users' ids.
154
- $users_with_2fa = Helper::sg_get_2fa_users();
155
-
156
- // Check if current user's ID is in the array.
157
- if ( ! in_array( $user_id, array_column( $users_with_2fa, 'ID' ), true ) ) {
158
- return true;
159
- }
160
-
161
- // Get the cookie name for this user.
162
- $cookie = 'sg_security_2fa_' . $user_id . '_cookie';
163
-
164
- // Bail if cookie is not set.
165
- if ( ! isset( $_COOKIE[ $cookie ] ) ) {
166
- return false;
167
- }
168
-
169
- // Get the 2FA cookie data.
170
- $token = Helper::sg_get_user_meta( $user_id, 'sg_security_2fa_secret' );
171
-
172
- // Bail, if secret is not set.
173
- if ( false === $token ) {
174
- return false;
175
- }
176
-
177
- // Require the Helper class so we can use the sgs_decrypt from the SG-Security plugin.
178
- require_once preg_replace( '~sg-cachepress~', 'sg-security', dirname( __DIR__ ) . '/Helper/Helper.php' );
179
-
180
- // Decrypt the user's 2fa cookie.
181
- $data = \SG_Security\Helper\Helper::sgs_decrypt( $_COOKIE[ $cookie ], md5( $token ) ); // phpcs:ignore
182
-
183
- // Return true if the cookie is valid.
184
- if ( $data[0] === $this->get_user_login() ) {
185
- return true;
186
- }
187
-
188
- return false;
189
  }
190
 
191
  /**
8
 
9
  namespace SiteGround_Optimizer\File_Cacher;
10
 
 
11
  use SiteGround_Optimizer\Helper\File_Cacher_Trait;
12
  /**
13
  * SG File Cacher main class
105
  * @return boolean True if the user is logged in, false otherwise.
106
  */
107
  public function is_logged_in() {
108
+ return in_array( $this->logged_in_cookie, array_keys( $_COOKIE ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  }
110
 
111
  /**
core/Helper/Helper.php CHANGED
@@ -187,86 +187,4 @@ class Helper {
187
 
188
  return preg_match( '/<\?xml version="/', $xml_part );
189
  }
190
-
191
- /**
192
- * Get all matching DB entries from a table.
193
- *
194
- * @since 7.0.8
195
- *
196
- * @param string $table Table to choose from.
197
- * @param string $get_column Column to retrieve.
198
- * @param string $from_column Column to search from.
199
- * @param string $value Value of the searched item.
200
- *
201
- * @return array Array of all found items.
202
- */
203
- public static function sg_get_db_entry( $table, $get_column, $from_column, $value ) {
204
- $query = 'SELECT `' . $get_column . '` FROM ' . $GLOBALS['table_prefix'] . $table . ' WHERE `' . $from_column . "` = '" . $value . "'";
205
- $result = self::sg_sql_query( $query ); // phpcs:ignore
206
-
207
- if ( false === $result ) {
208
- return array();
209
- }
210
-
211
- return mysqli_fetch_all( $result, MYSQLI_ASSOC ); // phpcs:ignore
212
- }
213
-
214
- /**
215
- * Get all users using 2fa.
216
- *
217
- * @since 7.0.8
218
- *
219
- * @return array All users that have 2fa enabled.
220
- */
221
- public static function sg_get_2fa_users() {
222
- $query = 'SELECT u.ID FROM ' . $GLOBALS['table_prefix'] . 'users u
223
- INNER JOIN ' . $GLOBALS['table_prefix'] . "usermeta m ON m.user_id = u.ID
224
- WHERE m.meta_key = 'sg_security_2fa_configured'
225
- AND m.meta_value = 1";
226
-
227
- $result = self::sg_sql_query( $query ); // phpcs:ignore
228
-
229
- if ( false === $result ) {
230
- return array();
231
- }
232
- return mysqli_fetch_all( $result, MYSQLI_ASSOC ); // phpcs:ignore
233
- }
234
-
235
- /**
236
- * Get user meta by user_id and meta_key
237
- *
238
- * @since 7.0.8
239
- *
240
- * @param string|int $user_id The user's ID.
241
- * @param string $meta_key Meta key to be searched for.
242
- *
243
- * @return string|int|bool Meta value for that specific key and user, false if not found.
244
- */
245
- public static function sg_get_user_meta( $user_id, $meta_key ) {
246
- $query = "SELECT meta_value FROM " . $GLOBALS['table_prefix'] . "usermeta m WHERE m.meta_key = '" . $meta_key . "' AND m.user_id = " . $user_id;
247
- $result = self::sg_sql_query( $query ); // phpcs:ignore
248
-
249
- if ( false === $result ) {
250
- return false;
251
- }
252
-
253
- return mysqli_fetch_object( $result )->meta_value; // phpcs:ignore
254
- }
255
-
256
- /**
257
- * Custom mysql query.
258
- *
259
- * @since 7.0.8
260
- *
261
- * @param string $query The query to be executed.
262
- * @return object|bool False on failure, if successful - returns a mysqli_result object.
263
- */
264
- public static function sg_sql_query( $query ) {
265
- // Bail if empty.
266
- if ( empty( $query ) ) {
267
- return false;
268
- }
269
-
270
- return mysqli_query( new \mysqli( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME ), $query ); // phpcs:ignore
271
- }
272
  }
187
 
188
  return preg_match( '/<\?xml version="/', $xml_part );
189
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
readme.txt CHANGED
@@ -328,6 +328,11 @@ Our plugin uses a cookie in order to function properly. It does not store person
328
 
329
  == Changelog ==
330
 
 
 
 
 
 
331
  = Version 7.0.8 =
332
  Release Date: April 6th, 2022
333
 
328
 
329
  == Changelog ==
330
 
331
+ = Version 7.0.9 =
332
+ Release Date: April 7th, 2022
333
+
334
+ * Improved SG Security plugin support
335
+
336
  = Version 7.0.8 =
337
  Release Date: April 6th, 2022
338
 
sg-cachepress.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: SiteGround Optimizer
11
  * Plugin URI: https://siteground.com
12
  * Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
13
- * Version: 7.0.8
14
  * Author: SiteGround
15
  * Author URI: https://www.siteground.com
16
  * Text Domain: sg-cachepress
@@ -32,7 +32,7 @@ if ( ! defined( 'WPINC' ) ) {
32
 
33
  // Define version constant.
34
  if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
35
- define( __NAMESPACE__ . '\VERSION', '7.0.8' );
36
  }
37
 
38
  // Define slug constant.
10
  * Plugin Name: SiteGround Optimizer
11
  * Plugin URI: https://siteground.com
12
  * Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
13
+ * Version: 7.0.9
14
  * Author: SiteGround
15
  * Author URI: https://www.siteground.com
16
  * Text Domain: sg-cachepress
32
 
33
  // Define version constant.
34
  if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
35
+ define( __NAMESPACE__ . '\VERSION', '7.0.9' );
36
  }
37
 
38
  // Define slug constant.