PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 All 503 releases
← All changes | modules/comments/base.php +47 -13 12.7.316.2 View file →
@@ -10,10 +10,23 @@
10 10 /**
11 11 * All the code shared between WP.com Highlander and Jetpack Highlander
12 12 */
13 13 class Highlander_Comments_Base {
14 + /**
15 + * ID sources.
16 + *
17 + * @var array
18 + */
19 + public $id_sources;
14 20
15 21 /**
22 + * The default comment scheme, if set.
23 + *
24 + * @var ?string
25 + */
26 + public $default_color_scheme;
27 +
28 + /**
16 29 * Constructor
17 30 */
18 31 public function __construct() {
19 32 $this->setup_globals();
@@ -159,13 +172,9 @@
159 172 * @param object $b The second comment to compare dates with.
160 173 * @return int
161 174 */
162 175 public function sort_comments_by_comment_date_gmt( $a, $b ) {
163 - if ( $a->comment_date_gmt === $b->comment_date_gmt ) {
164 - return 0;
165 - }
166 -
167 - return $a->comment_date_gmt < $b->comment_date_gmt ? -1 : 1;
176 + return $a->comment_date_gmt <=> $b->comment_date_gmt;
168 177 }
169 178
170 179 /**
171 180 * Get the current commenter's information from their cookie
@@ -200,15 +209,16 @@
200 209 return compact( 'comment_author', 'comment_author_email', 'comment_author_url', 'user_id' );
201 210 }
202 211
203 212 /**
204 - * Allows a logged out user to leave a comment as a facebook credentialed user.
213 + * Allows a logged out user to leave a comment as a facebook/wp.com credentialed user.
205 214 * Overrides WordPress' core comment_registration option to treat these commenters as "registered" (verified) users.
206 215 *
207 216 * @since 1.4
208 217 */
209 218 public function allow_logged_out_user_to_comment_as_external() {
210 - if ( ! $this->is_highlander_comment_post( 'facebook' ) ) {
219 + // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText
220 + if ( ! $this->is_highlander_comment_post( 'facebook', 'wordpress' ) ) {
211 221 return;
212 222 }
213 223
214 224 add_filter( 'pre_option_comment_registration', '__return_zero' );
@@ -302,15 +312,39 @@
302 312 return;
303 313 }
304 314
305 315 // Set comment author cookies.
316 + // We don't set the cookies if they are logged in with WordPress.com because they already have a cookie set.
306 317 // phpcs:ignore WordPress.WP.CapitalPDangit
307 - if ( ( 'wordpress' !== $id_source ) && is_user_logged_in() ) {
308 - /** This filter is already documented in core/wp-includes/comment-functions.php */
309 - $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
310 - setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );
311 - setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );
312 - setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );
318 + if ( 'wordpress' !== $id_source ) {
319 + // phpcs:disable WordPress.Security.NonceVerification -- Nonce verification should happen in Jetpack_Comments::pre_comment_on_post().
320 + $is_consenting_to_cookies = ( isset( $_POST['wp-comment-cookies-consent'] ) );
321 +
322 + $cookie_options = array(
323 + 'expires' => time() + apply_filters( 'comment_cookie_lifetime', YEAR_IN_SECONDS ),
324 + 'path' => COOKIEPATH,
325 + 'domain' => COOKIE_DOMAIN,
326 + 'secure' => is_ssl(),
327 + 'httponly' => true,
328 + );
329 +
330 + // If there is no consent, remove any cookies that may have been set.
331 + if ( ( 'guest' === $id_source ) && ! $is_consenting_to_cookies ) {
332 + $cookie_options['expires'] = time() - YEAR_IN_SECONDS;
333 + }
334 +
335 + // Set samesite to None if the request is from Jetpack iframe.
336 + // This is needed because it is considered third party.
337 + if ( isset( $_REQUEST['for'] ) && 'jetpack' === $_REQUEST['for'] ) {
338 + $cookie_options['samesite'] = 'None';
339 + }
340 + // phpcs:enable WordPress.Security.NonceVerification
341 +
342 + // phpcs:disable Jetpack.Functions.SetCookie.MissingTrueHTTPOnly
343 + isset( $comment->comment_author ) ? setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, $cookie_options ) : null;
344 + isset( $comment->comment_author_email ) ? setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $cookie_options ) : null;
345 + isset( $comment->comment_author_url ) ? setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), $cookie_options ) : null;
346 + // phpcs:enable Jetpack.Functions.SetCookie.MissingTrueHTTPOnly
313 347 }
314 348 }
315 349
316 350 /**