/** * Attach a purchase log to our customer profile * * @access private * @since 3.8.14 */ function _wpsc_set_purchase_log_customer_id($wpsc_purchase_log) { do_action('_wpsc_set_purchase_log_customer_id', $wpsc_purchase_log); // if there is a purchase log for this user we don't want to delete the // user id, even if the transaction isn't successful. there may be useful // information in the customer profile related to the transaction wpsc_delete_customer_meta('temporary_profile'); // connect the purchase to the visitor id wpsc_update_purchase_meta($wpsc_purchase_log->get('id'), 'visitor_id', wpsc_get_current_customer_id(), true); // connect the visitor to purchase wpsc_add_visitor_meta(wpsc_get_current_customer_id(), 'purchase_id', $wpsc_purchase_log->get('id'), false); }
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); }