Plugin Directory

Changeset 1948140


Ignore:
Timestamp:
09/27/2018 04:08:56 PM (8 years ago)
Author:
norcross
Message:

updating storage and retrieval methods for cookies.

Location:
woo-cart-expiration
Files:
26 added
3 edited

Legend:

Unmodified
Added
Removed
  • woo-cart-expiration/trunk/includes/cookies.php

    r1939994 r1948140  
    2323function build_cookie_args( $timer_expire = 0, $cart_key = '' ) {
    2424
    25     // Now create a JSON encoded array so we can check stuff later.
    26     $setup  = array( 'expire' => absint( $timer_expire ), 'cart' => $cart_key );
     25    // Smash together the two pieces with a delimiter.
     26    $setup  = absint( $timer_expire ) . '|' . sanitize_key( $cart_key );
    2727
    2828    // Return the base64 string.
    29     return base64_encode( maybe_serialize( $setup ) );
     29    return base64_encode( $setup );
    3030}
    3131
     
    105105    }
    106106
    107     // Decode and unserialize the cookie.
    108     $cookie = maybe_unserialize( base64_decode( $_COOKIE[ Core\COOKIE_NAME ] ) );
     107    // First decode our cookie value.
     108    $decode = base64_decode( $_COOKIE[ Core\COOKIE_NAME ] );
    109109
    110     // Bail without a set of data or an expire time.
    111     if ( ! $cookie || empty( $cookie['expire'] ) ) {
     110    // Bail if we have no resulting value or it isn't serialized.
     111    if ( empty( $decode ) ) {
     112        return;
     113    }
     114
     115    // Convert back to an array.
     116    $pieces = explode( '|', $decode );
     117
     118    // Make sure it worked and that each one exists before moving.
     119    if ( empty( $pieces ) || ! is_array( $pieces ) || empty( $pieces[0] ) || empty( $pieces[1] ) ) {
    112120        return false;
    113121    }
     
    115123    // If we requested the data, send it.
    116124    if ( $data ) {
    117         return $cookie;
     125        return array( 'expire' => absint( $pieces[0] ), 'cart' => sanitize_key( $pieces[1] ) );
    118126    }
    119127
     
    122130
    123131    // Return true / false for expired.
    124     return absint( $cookie['expire'] ) >= absint( $current_time ) ? true : false;
     132    return absint( $pieces[0] ) >= absint( $current_time ) ? true : false;
    125133}
  • woo-cart-expiration/trunk/readme.txt

    r1939994 r1948140  
    44Requires at least: 4.8
    55Tested up to: 4.9.8
    6 Stable tag: 0.1.0
     6Stable tag: 0.2.0
    77License: MIT
    88License URI: https://opensource.org/licenses/MIT
     
    4242== Changelog ==
    4343
    44 = 0.1.0 =
     44= 0.2.0  09/27/2018 =
     45* Updating storage and retrieval methods for cookies.
     46
     47= 0.1.0  09/25/2018 =
    4548* Initial release
    4649
  • woo-cart-expiration/trunk/woo-cart-expiration.php

    r1939994 r1948140  
    44 * Plugin URI:  https://github.com/liquidweb/woo-cart-expiration
    55 * Description: Set a time limit on a customer checking out.
    6  * Version:     0.1.0
     6 * Version:     0.2.0
    77 * Author:      Liquid Web
    88 * Author URI:  https://www.liquidweb.com
     
    2323
    2424// Define our plugin version.
    25 define( __NAMESPACE__ . '\VERS', '0.1.0' );
     25define( __NAMESPACE__ . '\VERS', '0.2.0' );
    2626
    2727// Plugin root file.
Note: See TracChangeset for help on using the changeset viewer.