Skip to:
Content

Changeset 6399


Ignore:
Timestamp:
04/18/2017 10:11:18 AM (13 months ago)
Author:
johnjamesjacoby
Message:

Anonymous: Clean-up bbp_set_current_anonymous_user_data():

  • Make sure cookies are secure when SSL
  • Only call time() once to avoid potential delays
  • Cast cookie lifetime to int after filtering
  • Inline docs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/users/functions.php

    r6390 r6399  
    125125 */
    126126function bbp_set_current_anonymous_user_data( $anonymous_data = array() ) {
     127
     128    //  Bail if empty or not an array
    127129    if ( empty( $anonymous_data ) || ! is_array( $anonymous_data ) ) {
    128130        return;
    129131    }
    130132
    131     $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
    132 
    133     setcookie( 'comment_author_'       . COOKIEHASH, $anonymous_data['bbp_anonymous_name'],    time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN );
    134     setcookie( 'comment_author_email_' . COOKIEHASH, $anonymous_data['bbp_anonymous_email'],   time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN );
    135     setcookie( 'comment_author_url_'   . COOKIEHASH, $anonymous_data['bbp_anonymous_website'], time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN );
     133    // Setup cookie expiration
     134    $lifetime = (int) apply_filters( 'comment_cookie_lifetime', 30000000 );
     135    $expiry   = time() + $lifetime;
     136    $secure   = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
     137
     138    // Set the cookies
     139    setcookie( 'comment_author_'       . COOKIEHASH, $anonymous_data['bbp_anonymous_name'],    $expiry, COOKIEPATH, COOKIE_DOMAIN, $secure );
     140    setcookie( 'comment_author_email_' . COOKIEHASH, $anonymous_data['bbp_anonymous_email'],   $expiry, COOKIEPATH, COOKIE_DOMAIN, $secure );
     141    setcookie( 'comment_author_url_'   . COOKIEHASH, $anonymous_data['bbp_anonymous_website'], $expiry, COOKIEPATH, COOKIE_DOMAIN, $secure );
    136142}
    137143
Note: See TracChangeset for help on using the changeset viewer.