Ticket #24921: 24921.3.patch
| File 24921.3.patch, 7.0 KB (added by , 12 years ago) |
|---|
-
wp-includes/option.php
540 540 if ( defined('DOING_AJAX') ) 541 541 return; 542 542 543 if ( ! $user = wp_get_current_user() )543 if ( ! $user_id = get_current_user_id() ) 544 544 return; 545 545 546 if ( is_super_admin( $user->ID ) && 547 ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user->ID ) ) ) 548 ) 546 if ( is_super_admin() && ! is_user_member_of_blog() ) 549 547 return; 550 548 551 $settings = get_user_option( 'user-settings', $user->ID);549 $settings = (string) get_user_option( 'user-settings', $user_id ); 552 550 553 if ( isset( $_COOKIE['wp-settings-' . $user ->ID] ) ) {554 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user ->ID] );551 if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) { 552 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] ); 555 553 556 if ( ! empty( $cookie ) && strpos( $cookie, '=' ) ) {557 if ( $cookie == $settings )558 return;554 // No change or both empty 555 if ( $cookie == $settings ) 556 return; 559 557 560 $last_time = (int) get_user_option( 'user-settings-time', $user->ID);561 $saved = isset( $_COOKIE['wp-settings-time-' . $user->ID]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user->ID] ) : 0;558 $last_saved = (int) get_user_option( 'user-settings-time', $user_id ); 559 $current = isset( $_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id] ) : 0; 562 560 563 if ( $saved > $last_time ) {564 update_user_option( $user->ID, 'user-settings', $cookie, false );565 update_user_option( $user->ID, 'user-settings-time', time() - 5, false );566 return;567 }561 // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is 562 if ( $current > $last_saved ) { 563 update_user_option( $user_id, 'user-settings', $cookie, false ); 564 update_user_option( $user_id, 'user-settings-time', time() - 5, false ); 565 return; 568 566 } 569 567 } 570 568 571 setcookie( 'wp-settings-' . $user->ID, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH ); 572 setcookie( 'wp-settings-time-' . $user->ID, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH ); 573 $_COOKIE['wp-settings-' . $user->ID] = $settings; 569 // The cookie is not set in the current browser or the saved value is newer. 570 setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH ); 571 setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH ); 572 $_COOKIE['wp-settings-' . $user_id] = $settings; 574 573 } 575 574 576 575 /** … … 585 584 * @return mixed the last saved user setting or the default value/false if it doesn't exist. 586 585 */ 587 586 function get_user_setting( $name, $default = false ) { 588 589 $all = get_all_user_settings(); 590 591 return isset($all[$name]) ? $all[$name] : $default; 587 $all_user_settings = get_all_user_settings(); 588 return isset( $all_user_settings[$name] ) ? $all_user_settings[$name] : $default; 592 589 } 593 590 594 591 /** … … 610 607 if ( headers_sent() ) 611 608 return false; 612 609 613 $all = get_all_user_settings();610 $all_user_settings = get_all_user_settings(); 614 611 $name = preg_replace( '/[^A-Za-z0-9_]+/', '', $name ); 615 612 616 if ( empty( $name) )613 if ( empty( $name ) ) 617 614 return false; 618 615 619 $all [$name] = $value;616 $all_user_settings[$name] = $value; 620 617 621 return wp_set_all_user_settings( $all);618 return wp_set_all_user_settings( $all_user_settings ); 622 619 } 623 620 624 621 /** … … 639 636 if ( headers_sent() ) 640 637 return false; 641 638 642 $all = get_all_user_settings();639 $all_user_settings = get_all_user_settings(); 643 640 $names = (array) $names; 644 641 645 642 foreach ( $names as $name ) { 646 if ( isset( $all[$name]) ) {647 unset( $all[$name]);643 if ( isset( $all_user_settings[$name] ) ) { 644 unset( $all_user_settings[$name] ); 648 645 $deleted = true; 649 646 } 650 647 } 651 648 652 if ( isset( $deleted) )653 return wp_set_all_user_settings( $all);649 if ( isset( $deleted ) ) 650 return wp_set_all_user_settings( $all_user_settings ); 654 651 655 652 return false; 656 653 } … … 667 664 function get_all_user_settings() { 668 665 global $_updated_user_settings; 669 666 670 if ( ! $user = wp_get_current_user() )667 if ( ! $user_id = get_current_user_id() ) 671 668 return array(); 672 669 673 if ( isset( $_updated_user_settings) && is_array($_updated_user_settings) )670 if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) 674 671 return $_updated_user_settings; 675 672 676 $ all= array();677 if ( isset( $_COOKIE['wp-settings-' . $user->ID]) ) {678 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user ->ID] );673 $_updated_user_settings = array(); 674 if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) { 675 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] ); 679 676 680 if ( $cookie && strpos( $cookie, '=') ) // the'=' cannot be 1st char681 parse_str( $cookie, $all);677 if ( $cookie && strpos( $cookie, '=' ) ) // '=' cannot be 1st char 678 parse_str( $cookie, $_updated_user_settings ); 682 679 683 680 } else { 684 $option = get_user_option( 'user-settings', $user->ID);681 $option = get_user_option( 'user-settings', $user_id ); 685 682 if ( $option && is_string($option) ) 686 parse_str( $option, $ all);683 parse_str( $option, $_updated_user_settings ); 687 684 } 688 685 689 return $ all;686 return $_updated_user_settings; 690 687 } 691 688 692 689 /** … … 696 693 * @subpackage Option 697 694 * @since 2.8.0 698 695 * 699 * @param unknown $all696 * @param array $user_settings 700 697 * @return bool 701 698 */ 702 function wp_set_all_user_settings( $all) {699 function wp_set_all_user_settings( $user_settings ) { 703 700 global $_updated_user_settings; 704 701 705 if ( ! $user = wp_get_current_user() )702 if ( ! $user_id = get_current_user_id() ) 706 703 return false; 707 704 708 if ( is_super_admin( $user->ID ) && 709 ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user->ID ) ) ) 710 ) 705 if ( is_super_admin() && ! is_user_member_of_blog() ) 711 706 return; 712 707 713 $_updated_user_settings = $ all;708 $_updated_user_settings = $user_settings; 714 709 $settings = ''; 715 foreach ( $ all as $k => $v) {716 $v = preg_replace( '/[^A-Za-z0-9_]+/', '', $v);717 $settings .= $ k . '=' . $v. '&';710 foreach ( $user_settings as $name => $value ) { 711 $value = preg_replace( '/[^A-Za-z0-9_]+/', '', $value ); 712 $settings .= $name . '=' . $value . '&'; 718 713 } 719 714 720 715 $settings = rtrim($settings, '&'); 721 716 722 update_user_option( $user ->ID, 'user-settings', $settings, false );723 update_user_option( $user ->ID, 'user-settings-time', time(), false );717 update_user_option( $user_id, 'user-settings', $settings, false ); 718 update_user_option( $user_id, 'user-settings-time', time(), false ); 724 719 725 720 return true; 726 721 } … … 733 728 * @since 2.7.0 734 729 */ 735 730 function delete_all_user_settings() { 736 if ( ! $user = wp_get_current_user() )731 if ( ! $user_id = get_current_user_id() ) 737 732 return; 738 733 739 update_user_option( $user ->ID, 'user-settings', '', false );740 setcookie('wp-settings-' . $user ->ID, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH);734 update_user_option( $user_id, 'user-settings', '', false ); 735 setcookie('wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH); 741 736 } 742 737 743 738 /**