| @@ -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(); |
| @@ -299,15 +312,39 @@ | ||
| 299 | 312 | return; |
| 300 | 313 | } |
| 301 | 314 | |
| 302 | 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. | |
| 303 | 317 | // phpcs:ignore WordPress.WP.CapitalPDangit |
| 304 | - if ( ( 'wordpress' !== $id_source ) && is_user_logged_in() ) { | |
| 305 | - /** This filter is already documented in core/wp-includes/comment-functions.php */ | |
| 306 | - $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); | |
| 307 | - setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true ); | |
| 308 | - setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true ); | |
| 309 | - 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 | |
| 310 | 347 | } |
| 311 | 348 | } |
| 312 | 349 | |
| 313 | 350 | /** |