Changeset 836741
- Timestamp:
- 01/11/2014 04:36:28 PM (12 years ago)
- Location:
- wp-e-commerce/branches/branch-3.8.13
- Files:
-
- 6 edited
-
readme.txt (modified) (2 diffs)
-
wp-shopping-cart.php (modified) (1 diff)
-
wpsc-core/wpsc-constants.php (modified) (2 diffs)
-
wpsc-includes/cron.php (modified) (4 diffs)
-
wpsc-includes/customer.php (modified) (7 diffs)
-
wpsc-includes/wpsc-meta-init.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-e-commerce/branches/branch-3.8.13/readme.txt
r826442 r836741 5 5 Requires at least: 3.7 6 6 Tested up to: 3.8 7 Stable tag: 3.8.13 7 Stable tag: 3.8.13.2 8 8 9 9 WP e-Commerce is a free WordPress Shopping Cart Plugin that lets customers buy your products, services and digital downloads online. … … 146 146 147 147 == Changelog == 148 149 = 3.8.13.2 = 150 * Fix: Anonymous customers should not be visible in admin UI. 151 * Fix: Cronjob to purge anonymous customers doesn't work due to memory issues. 152 * Fix: Anonymous cart items will be lost after signing in. 153 154 = 3.8.13.1 = 155 * Security and maintenance release 148 156 149 157 = 3.8.13 = -
wp-e-commerce/branches/branch-3.8.13/wp-shopping-cart.php
r826442 r836741 4 4 * Plugin URI: http://getshopped.org/ 5 5 * Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="http://getshopped.org/forums/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a> 6 * Version: 3.8.13 6 * Version: 3.8.13.2 7 7 * Author: Instinct Entertainment 8 8 * Author URI: http://getshopped.org/ -
wp-e-commerce/branches/branch-3.8.13/wpsc-core/wpsc-constants.php
r826442 r836741 30 30 31 31 // Define Plugin version 32 define( 'WPSC_VERSION' , '3.8.13 ' );33 define( 'WPSC_MINOR_VERSION' , ' e8a508c011' );34 define( 'WPSC_PRESENTABLE_VERSION', '3.8.13 ' );32 define( 'WPSC_VERSION' , '3.8.13.2' ); 33 define( 'WPSC_MINOR_VERSION' , 'b0ef2e3' ); 34 define( 'WPSC_PRESENTABLE_VERSION', '3.8.13.2' ); 35 35 define( 'WPSC_DB_VERSION' , 8 ); 36 36 … … 257 257 add_filter( 'the_content', 'wpsc_shopping_cart', 14 ); 258 258 259 $cart = maybe_unserialize( base64_decode( wpsc_get_customer_meta( 'cart' ) ) ); 260 261 if ( is_object( $cart ) && ! is_wp_error( $cart ) ) 262 $GLOBALS['wpsc_cart'] = $cart; 263 else 264 $GLOBALS['wpsc_cart'] = new wpsc_cart(); 259 $GLOBALS['wpsc_cart'] = wpsc_get_customer_cart(); 265 260 } 266 261 -
wp-e-commerce/branches/branch-3.8.13/wpsc-includes/cron.php
r826442 r836741 4 4 5 5 /** 6 * wpsc_clear_stock_claims, clears the stock claims, runs using wp-cron and when editing purchase log statuses via the dashboard 6 * Clears the stock claims, runs on hourly WP_Cron event and when editing purchase log statuses. 7 * 8 * @since 3.8.9 9 * @access public 10 * 11 * @return void 7 12 */ 8 13 function wpsc_clear_stock_claims() { 9 14 global $wpdb; 10 15 11 $time = (float) get_option( 'wpsc_stock_keeping_time', 1 );16 $time = (float) get_option( 'wpsc_stock_keeping_time', 1 ); 12 17 $interval = get_option( 'wpsc_stock_keeping_interval', 'day' ); 13 18 … … 19 24 ); 20 25 21 $seconds = floor( $time * $convert[ $interval] );26 $seconds = floor( $time * $convert[ $interval ] ); 22 27 23 28 $sql = $wpdb->prepare( "DELETE FROM " . WPSC_TABLE_CLAIMED_STOCK . " WHERE last_activity < UTC_TIMESTAMP() - INTERVAL %d SECOND", $seconds ); … … 25 30 } 26 31 32 /** 33 * Purges customer meta that is older than WPSC_CUSTOMER_DATA_EXPIRATION on an hourly WP_Cron event. 34 * 35 * @since 3.8.9.2 36 * @access public 37 * 38 * @return void 39 */ 27 40 function _wpsc_clear_customer_meta() { 28 41 global $wpdb; 29 42 30 43 require_once( ABSPATH . 'wp-admin/includes/user.php' ); 44 45 $purge_count = 200; 31 46 32 47 $sql = " … … 36 51 meta_key = '_wpsc_last_active' 37 52 AND meta_value < UNIX_TIMESTAMP() - " . WPSC_CUSTOMER_DATA_EXPIRATION . " 53 LIMIT {$purge_count} 38 54 "; 39 55 40 $ids = $wpdb->get_col( $sql ); 41 foreach ( $ids as $id ) { 42 wp_delete_user( $id ); 43 } 56 /* Do this in batches of 200 to avoid memory issues when there are too many anonymous users */ 57 @set_time_limit( 0 ); // no time limit 58 59 do { 60 $ids = $wpdb->get_col( $sql ); 61 foreach ( $ids as $id ) { 62 wp_delete_user( $id ); 63 } 64 } while ( count( $ids ) == $purge_count ); 44 65 } -
wp-e-commerce/branches/branch-3.8.13/wpsc-includes/customer.php
r826442 r836741 5 5 add_action( 'wpsc_before_submit_checkout', '_wpsc_action_update_customer_last_active' ); 6 6 add_action( 'wp_login' , '_wpsc_action_setup_customer' ); 7 add_action( 'load-users.php' , '_wpsc_action_load_users' ); 8 add_filter( 'views_users' , '_wpsc_filter_views_users' ); 9 add_filter( 'editable_roles' , '_wpsc_filter_editable_roles' ); 7 10 8 11 /** … … 124 127 */ 125 128 function _wpsc_validate_customer_cookie() { 126 if ( is_admin() || ! isset( $_COOKIE[ WPSC_CUSTOMER_COOKIE ] ) ) 127 return; 129 130 if ( is_admin() || ! isset( $_COOKIE[ WPSC_CUSTOMER_COOKIE ] ) ) { 131 return false; 132 } 128 133 129 134 $cookie = $_COOKIE[ WPSC_CUSTOMER_COOKIE ]; … … 134 139 135 140 // invalid ID 136 if ( ! $id ) 141 if ( ! $id ) { 137 142 return false; 143 } 138 144 139 145 $user = get_user_by( 'id', $id ); 140 146 141 147 // no user found 142 if ( $user === false ) 148 if ( $user === false ) { 143 149 return false; 150 } 144 151 145 152 $pass_frag = substr( $user->user_pass, 8, 4 ); … … 148 155 149 156 // integrity check 150 if ( $hmac == $hash ) 157 if ( $hmac == $hash ) { 151 158 return $id; 159 } 152 160 153 161 _wpsc_set_customer_cookie( '', time() - 3600 ); … … 193 201 */ 194 202 function _wpsc_action_setup_customer() { 195 // if the user is logged in and the cookie is still there, delete the cookie196 if ( is_user_logged_in() && isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) )197 _wpsc_set_customer_cookie( '', time() - 3600 );198 199 203 // if the customer cookie is invalid, unset it 200 _wpsc_validate_customer_cookie(); 204 $id = _wpsc_validate_customer_cookie(); 205 206 // if a valid ID is present in the cookie, and the user is logged in, 207 // it's time to merge the carts 208 if ( isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) && is_user_logged_in() ) { 209 // merging cart requires the taxonomies to have been initialized 210 if ( did_action( 'wpsc_register_taxonomies_after' ) ) { 211 _wpsc_merge_cart(); 212 } 213 else { 214 add_action( 'wpsc_register_taxonomies_after', '_wpsc_merge_cart', 1 ); 215 } 216 } 201 217 202 218 // if this request is by a bot, prevent multiple account creation … … 210 226 211 227 do_action( 'wpsc_setup_customer' ); 228 } 229 230 function _wpsc_merge_cart() { 231 $old_id = _wpsc_validate_customer_cookie(); 232 233 if ( ! $old_id ) { 234 return; 235 } 236 237 $new_id = get_current_user_id(); 238 239 $old_cart = wpsc_get_customer_cart( $old_id ); 240 $items = $old_cart->get_items(); 241 242 $new_cart = wpsc_get_customer_cart( $new_id ); 243 244 // first of all empty the old cart so that the claimed stock and related 245 // hooks are released 246 $old_cart->empty_cart(); 247 248 // add each item to the new cart 249 foreach ( $items as $item ) { 250 $new_cart->set_item( $item->product_id, array( 251 'quantity' => $item->quantity, 252 'variation_values' => $item->variation_values, 253 'custom_message' => $item->custom_message, 254 'provided_price' => $item->provided_price, 255 'time_requested' => $item->time_requested, 256 'custom_file' => $item->custom_file, 257 'is_customisable' => $item->is_customisable, 258 'meta' => $item->meta 259 ) ); 260 } 261 262 require_once( ABSPATH . 'wp-admin/includes/user.php' ); 263 wp_delete_user( $old_id ); 264 265 _wpsc_set_customer_cookie( '', time() - 3600 ); 266 } 267 268 function wpsc_get_customer_cart( $id = false ) { 269 global $wpsc_cart; 270 271 if ( ! empty( $wpsc_cart ) && ( ! $id || $id == wpsc_get_current_customer_id() ) ) 272 return $wpsc_cart; 273 274 $cart = maybe_unserialize( base64_decode( wpsc_get_customer_meta( 'cart', $id ) ) ); 275 if ( empty( $cart ) || ! $cart instanceof wpsc_cart ) 276 $cart = new wpsc_cart(); 277 278 return $cart; 279 } 280 281 function wpsc_update_customer_cart( $cart, $id = false ) { 282 if ( ! $id || $id == wpsc_get_current_customer_id() ) 283 return wpsc_serialize_shopping_cart(); 284 285 return wpsc_update_customer_meta( 'cart', base64_encode( serialize( $wpsc_cart ) ), $id ); 212 286 } 213 287 … … 476 550 return false; 477 551 } 552 553 /** 554 * Given a users.php view's HTML code, this function returns the user count displayed 555 * in the view. 556 * 557 * If `count_users()` had implented caching, we could have just called that function again 558 * instead of using this hack. 559 * 560 * @access private 561 * @since 3.8.13.2 562 * @param string $view 563 * @return int 564 */ 565 function _wpsc_extract_user_count( $view ) { 566 if ( preg_match( '/class="count">\((\d+)\)/', $view, $matches ) ) { 567 return absint( $matches[1] ); 568 } 569 570 return 0; 571 } 572 573 /** 574 * Filter the user views so that Anonymous role is not displayed 575 * 576 * @since 3.8.13.2 577 * @access private 578 * @param array $views 579 * @return array 580 */ 581 function _wpsc_filter_views_users( $views ) { 582 if ( isset( $views['wpsc_anonymous'] ) ) { 583 // ugly hack to make the anonymous users not count towards "All" 584 // really wish WordPress had a filter in count_users(), but in the mean time 585 // this will do 586 $anon_count = _wpsc_extract_user_count( $views['wpsc_anonymous'] ); 587 $all_count = _wpsc_extract_user_count( $views['all'] ); 588 $new_count = $all_count - $anon_count; 589 $views['all'] = str_replace( "(${all_count})", "(${new_count})", $views['all'] ); 590 } 591 592 unset( $views['wpsc_anonymous'] ); 593 return $views; 594 } 595 596 /** 597 * Add the action necessary to filter out anonymous users 598 * 599 * @since 3.8.13.2 600 * @access private 601 */ 602 function _wpsc_action_load_users() { 603 add_action( 'pre_user_query', '_wpsc_action_pre_user_query', 10, 1 ); 604 } 605 606 /** 607 * Filter out anonymous users in "All" view 608 * 609 * @since 3.8.13.2 610 * @access private 611 * @param WP_User_Query $query 612 */ 613 function _wpsc_action_pre_user_query( $query ) { 614 global $wpdb; 615 616 // only do this when we're viewing all users 617 if ( ! empty( $query->query_vars['role'] ) ) 618 return; 619 620 // if the site is multisite, a JOIN is already done 621 if ( is_multisite() ) { 622 $query->query_where .= " AND CAST($wpdb->usermeta.meta_value AS CHAR) NOT LIKE '%" . like_escape( '"wpsc_anonymous"' ) . "%'"; 623 return; 624 } 625 626 $cap_meta_query = array( 627 array( 628 'key' => $wpdb->get_blog_prefix( $query->query_vars['blog_id'] ) . 'capabilities', 629 'value' => '"wpsc_anonymous"', 630 'compare' => 'not like', 631 ) 632 ); 633 634 $meta_query = new WP_Meta_Query( $cap_meta_query ); 635 $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $query ); 636 637 $query->query_from .= $clauses['join']; 638 $query->query_where .= $clauses['where']; 639 } 640 641 /** 642 * Make sure Anonymous role not editable 643 * 644 * @since 3.8.13.2 645 * @param array $editable_roles 646 * @return array 647 */ 648 function _wpsc_filter_editable_roles( $editable_roles ) { 649 unset( $editable_roles['wpsc_anonymous'] ); 650 return $editable_roles; 651 } -
wp-e-commerce/branches/branch-3.8.13/wpsc-includes/wpsc-meta-init.php
r826442 r836741 123 123 foreach ( $old_meta_rows as $old_meta_row ) { 124 124 $meta_data = maybe_unserialize( $old_meta_row->meta_value ); 125 add_metadata( $meta_object_type, $old_meta_row->object_id, $old_meta_row->meta_key, $meta_data, false );125 add_metadata( 'wpsc_' . $meta_object_type, $old_meta_row->object_id, $old_meta_row->meta_key, $meta_data, false ); 126 126 } 127 127 }
Note: See TracChangeset
for help on using the changeset viewer.