예제 #1
0
/**
 * Get current customer ID.
 *
 * If the user is logged in, return the user ID. Otherwise return the ID associated
 * with the customer's cookie.
 *
 * Implement your own system by hooking into 'wpsc_get_current_customer_id' filter.
 *
 * @access public
 * @since 3.8.9
 * @return mixed        User ID (if logged in) or customer cookie ID
 */
function wpsc_get_current_customer_id($visitor_id_to_set = false)
{
    $id = apply_filters('wpsc_get_current_customer_id', null);
    if (!empty($id)) {
        return $id;
    }
    // once we determine the current customer id it will remain in effect for
    // the remainder of the current request.  This helps performance, but also
    // makes it possible to manipulate the visitor database and cookie without
    // causing code dependent on the valid visitor id to fail.   It's probably
    // also a security benefit to not allow the current user to be changed
    // midway through the HTTP request processing
    static $visitor_id = false;
    if ($visitor_id_to_set) {
        $visitor_id = $visitor_id_to_set;
    }
    if ($visitor_id !== false) {
        return $visitor_id;
    }
    if (_wpsc_is_bot_user()) {
        $visitor_id = WPSC_BOT_VISITOR_ID;
    }
    if (!$visitor_id && is_user_logged_in()) {
        // if the user is logged in we use the user id
        $visitor_id = _wpsc_get_wp_user_visitor_id();
        if ($visitor_id == WPSC_BOT_VISITOR_ID) {
            // it is not allowed to have the bot visitor id
            $visitor_id = false;
        }
    }
    if (!$visitor_id && isset($_COOKIE[WPSC_CUSTOMER_COOKIE])) {
        list($id, $expire, $hash) = explode('|', $_COOKIE[WPSC_CUSTOMER_COOKIE]);
        $visitor_id = $id;
    }
    // get the last active time to validate the visitor exists
    if (!($visitor_id && wpsc_get_visitor_last_active($visitor_id))) {
        $visitor_id = _wpsc_create_customer_id();
    }
    return $visitor_id;
}
예제 #2
0
/**
 * Create a new visitor account for the current visitor and store its ID
 * in a cookie
 *
 * @access public
 * @since 3.8.9
 * @return string Customer ID
 */
function _wpsc_create_customer_id()
{
    // only allow one customer id per request
    static $customer_id = false;
    if ($customer_id) {
        return $customer_id;
    }
    do_action('_wpsc_create_customer_id');
    if (_wpsc_is_bot_user()) {
        $customer_id = WPSC_BOT_VISITOR_ID;
        wpsc_get_current_customer_id($customer_id);
    } else {
        $fake_setting_cookie = false;
        $args = array();
        if (is_user_logged_in()) {
            $args['user_id'] = get_current_user_id();
        }
        $customer_id = wpsc_create_visitor($args);
        if (!$customer_id) {
            // can't create a new visitor, just use the BOT visitor id
            $customer_id = WPSC_BOT_VISITOR_ID;
            $fake_setting_cookie = true;
        }
        wpsc_get_current_customer_id($customer_id);
        _wpsc_create_customer_id_cookie($customer_id, $fake_setting_cookie);
        do_action('wpsc_create_customer', $customer_id);
    }
    return $customer_id;
}
예제 #3
0
/**
 * Create a new visitor account for the current visitor and store its ID
 * in a cookie
 *
 * @access public
 * @since 3.8.9
 * @return string Customer ID
 */
function _wpsc_create_customer_id()
{
    do_action('_wpsc_create_customer_id');
    if (_wpsc_is_bot_user()) {
        $visitor_id = WPSC_BOT_VISITOR_ID;
        wpsc_get_current_customer_id($visitor_id);
        $fake_setting_cookie = true;
    } else {
        $fake_setting_cookie = false;
        $args = array();
        if (is_user_logged_in()) {
            $args['user_id'] = get_current_user_id();
        }
        $visitor_id = wpsc_create_visitor($args);
        if ($visitor_id === false) {
            // can't create a new visitor, just use the BOT visitor id
            $visitor_id = WPSC_BOT_VISITOR_ID;
            $fake_setting_cookie = true;
        }
        wpsc_get_current_customer_id($visitor_id);
        _wpsc_create_customer_id_cookie($visitor_id, $fake_setting_cookie);
        do_action('wpsc_create_customer', $visitor_id);
    }
    return $visitor_id;
}