/** * Sets the last active time for a visitor * * @since 3.8.14 * @param $visitor_id int visitor id to check * @return last active timestamp, or false on failure. */ function wpsc_set_visitor_last_active($visitor_id, $timestamp = null) { if (!_wpsc_visitor_database_ready()) { return false; } global $wpdb; // if are explicitly setting the last active to a fixed time that's all we need to do, if we are setting it to the // current time also change the visitor profile expiration if (!empty($timestamp)) { if (is_numeric($timestamp)) { $last_active = date('Y-m-d H:i:s', $timestamp); } else { $last_active = $timestamp; } $wpdb->query('UPDATE ' . $wpdb->wpsc_visitors . ' SET last_active = "' . $timestamp . '" WHERE id = ' . $visitor_id); if ($wpdb->rows_affected !== 1) { $last_active = false; } } else { wpsc_set_visitor_expiration($visitor_id, 2 * DAY_IN_SECONDS); $last_active = date('Y-m-d H:i:s', $timestamp); } return $last_active; }
/** * Update the current customer's last active time * * @access private * @since 3.8.13 */ function _wpsc_action_customer_used_cart() { do_action('_wpsc_action_customer_used_cart'); // get the current users id $id = wpsc_get_current_customer_id(); // go through the common update routine that allows any users last active time to be changed wpsc_set_visitor_expiration($id, DAY_IN_SECONDS * 2); // also extend cookie expiration _wpsc_create_customer_id_cookie($id); }
function _wpsc_meta_migrate_anonymous_user_worker() { global $wpdb; $blog_prefix = is_multisite() ? $wpdb->get_blog_prefix() : ''; $key_pattern = "{$blog_prefix}_wpsc_"; wp_suspend_cache_addition(true); $sql = 'SELECT ID FROM ' . $wpdb->users . ' WHERE user_login LIKE "\\_%" AND user_email = "" AND user_login = user_nicename AND user_login = display_name LIMIT 100'; $user_ids = $wpdb->get_col($sql, 0); // Create an array to store users to be removed. $bin = array(); foreach ($user_ids as $user_id) { $wpdb->query('INSERT INTO ' . $wpdb->wpsc_visitors . '(`id`) VALUES ( ' . $user_id . ' )'); wpsc_set_visitor_expiration($user_id, DAY_IN_SECONDS); $meta = get_user_meta($user_id); foreach ($meta as $key => $value) { if (strpos($key, $key_pattern) === FALSE) { continue; } $short_key = str_replace($key_pattern, '', $key); if ($short_key !== 'cart') { wpsc_add_visitor_meta($user_id, $short_key, $value[0]); } else { $wpsc_user_cart = maybe_unserialize(base64_decode($value[0])); if (!$wpsc_user_cart instanceof wpsc_cart) { $wpsc_user_cart = new wpsc_cart(); } else { continue; } } } $comment_count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments . ' WHERE user_id = ' . $user_id); if (!count_user_posts($user_id) && !$comment_count) { //wp_delete_user( $user_id ); // Add user to bin. $bin[] = $user_id; } } // Remove users. if (!empty($bin)) { // Convert $bin to string. $bin = implode(',', $bin); $wpdb->query('DELETE FROM ' . $wpdb->users . ' WHERE ID IN (' . $bin . ')'); $wpdb->query('DELETE FROM ' . $wpdb->usermeta . ' WHERE user_id IN (' . $bin . ')'); } wp_suspend_cache_addition(false); exit(0); }