Changeset 10355 for trunk/src/bp-core/classes/class-bp-core-user.php
- Timestamp:
- 11/15/2015 07:13:42 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/classes/class-bp-core-user.php (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-core-user.php
r10108 r10355 19 19 * $user = new BP_Core_User( $user_id ); 20 20 * $user_avatar = $user->avatar; 21 * $user_email = $user->email;21 * $user_email = $user->email; 22 22 * $user_status = $user->status; 23 23 * etc. … … 178 178 } 179 179 180 // Cache a few things that are fetched often 180 // Cache a few things that are fetched often. 181 181 wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' ); 182 182 wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' ); … … 282 282 $sql['from'] = "FROM {$wpdb->users} u LEFT JOIN {$wpdb->usermeta} um ON um.user_id = u.ID"; 283 283 284 // We search against xprofile fields, so we must join the table 284 // We search against xprofile fields, so we must join the table. 285 285 if ( $search_terms && bp_is_active( 'xprofile' ) ) { 286 286 $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id"; 287 287 } 288 288 289 // Alphabetical sorting is done by the xprofile Full Name field 289 // Alphabetical sorting is done by the xprofile Full Name field. 290 290 if ( 'alphabetical' == $type ) { 291 291 $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id"; … … 349 349 $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key ); 350 350 351 // If a meta value is provided, match it 351 // If a meta value is provided, match it. 352 352 if ( $meta_value ) { 353 353 $sql['where_meta'] .= $wpdb->prepare( " AND umm.meta_value = %s", $meta_value ); … … 388 388 $paged_users = $wpdb->get_results( $paged_users_sql ); 389 389 390 // Re-jig the SQL so we can get the total user count 390 // Re-jig the SQL so we can get the total user count. 391 391 unset( $sql['select_main'] ); 392 392 … … 420 420 $total_users = $wpdb->get_var( $total_users_sql ); 421 421 422 /** *422 /** 423 423 * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list. 424 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join) 424 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join). 425 425 */ 426 426 if ( !empty( $populate_extras ) ) { … … 431 431 } 432 432 433 // Add additional data to the returned results 433 // Add additional data to the returned results. 434 434 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids, $type ); 435 435 } … … 448 448 * @param int $page The page number we are currently on, used in conjunction 449 449 * with $limit to get the start position for the limit. 450 * @param bool $populate_extras Populate extra user fields?450 * @param bool $populate_extras If we should populate extra user fields. 451 451 * @param string $exclude Comma-separated IDs of users whose results 452 452 * aren't to be fetched. 453 *454 453 * @return mixed False on error, otherwise associative array of results. 455 454 */ … … 462 461 } 463 462 464 // Multibyte compliance 463 // Multibyte compliance. 465 464 if ( function_exists( 'mb_strlen' ) ) { 466 465 if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) { … … 506 505 $paged_users = $wpdb->get_results( $paged_users_sql ); 507 506 508 /** *507 /** 509 508 * Lets fetch some other useful data in a separate queries, this will be 510 509 * faster than querying the data for every user in a list. We can't add … … 517 516 $user_ids[] = (int) $user->id; 518 517 519 // Add additional data to the returned results 518 // Add additional data to the returned results. 520 519 if ( $populate_extras ) { 521 520 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); … … 536 535 * @param int $limit The limit of results we want. 537 536 * @param int $page The page we are on for pagination. 538 * @param bool $populate_extras Populate extra user fields? 539 * 537 * @param bool $populate_extras If we should populate extra user fields. 540 538 * @return array Associative array. 541 539 */ … … 607 605 $paged_users = $wpdb->get_results( $paged_users_sql ); 608 606 609 /** *607 /** 610 608 * Lets fetch some other useful data in a separate queries, this will be 611 609 * faster than querying the data for every user in a list. We can't add … … 615 613 */ 616 614 617 // Add additional data to the returned results 615 // Add additional data to the returned results. 618 616 if ( !empty( $populate_extras ) ) { 619 617 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); … … 632 630 * @param int $limit The limit of results we want. 633 631 * @param int $page The page we are on for pagination. 634 * @param boolean $populate_extras Populate extra user fields? 635 * 632 * @param boolean $populate_extras If we should populate extra user fields. 636 633 * @return array Associative array. 637 634 */ … … 668 665 $paged_users = $wpdb->get_results( $paged_users_sql ); 669 666 670 /** *667 /** 671 668 * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list. 672 669 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join) … … 675 672 $user_ids[] = $user->id; 676 673 677 // Add additional data to the returned results 674 // Add additional data to the returned results. 678 675 if ( $populate_extras ) 679 676 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); … … 692 689 * @param string $user_ids The user ids to select information about. 693 690 * @param string|bool $type The type of fields we wish to get. 694 *695 691 * @return mixed False on error, otherwise associative array of results. 696 692 */ … … 703 699 return $paged_users; 704 700 705 // Sanitize user IDs 701 // Sanitize user IDs. 706 702 $user_ids = implode( ',', wp_parse_id_list( $user_ids ) ); 707 703 708 // Fetch the user's full name 704 // Fetch the user's full name. 709 705 if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) { 710 706 $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) ); … … 717 713 } 718 714 719 // Fetch the user's total friend count 715 // Fetch the user's total friend count. 720 716 if ( 'popular' != $type ) { 721 717 $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) ); … … 728 724 } 729 725 730 // Fetch whether or not the user is a friend 726 // Fetch whether or not the user is a friend. 731 727 if ( bp_is_active( 'friends' ) ) { 732 728 $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) ); … … 749 745 } 750 746 751 // Fetch the user's last_activity 747 // Fetch the user's last_activity. 752 748 if ( 'active' != $type ) { 753 749 $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) ); … … 760 756 } 761 757 762 // Fetch the user's latest update 758 // Fetch the user's latest update. 763 759 $user_update = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as latest_update FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'bp_latest_update' ) ) ); 764 760 for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { … … 778 774 * 779 775 * @param int $user_id User ID. 780 *781 776 * @return array Associative array. 782 777 */ … … 793 788 * Get last activity data for a user or set of users. 794 789 * 795 * @param int|array User IDs or multiple user IDs. 796 * 790 * @param int|array $user_id User IDs or multiple user IDs. 797 791 * @return array 798 792 */ … … 800 794 global $wpdb; 801 795 802 // Sanitize and remove empty values 796 // Sanitize and remove empty values. 803 797 $user_ids = array_filter( wp_parse_id_list( $user_id ) ); 804 798 … … 825 819 } 826 820 827 // Fetch all user data from the cache 821 // Fetch all user data from the cache. 828 822 $retval = array(); 829 823 foreach ( $user_ids as $user_id ) { … … 844 838 * @param int $user_id ID of the user whose last_activity you are updating. 845 839 * @param string $time MySQL-formatted time string. 846 *847 840 * @return bool True on success, false on failure. 848 841 */ … … 858 851 $table_name, 859 852 860 // Data to update 853 // Data to update. 861 854 array( 862 855 'date_recorded' => $time, 863 856 ), 864 857 865 // WHERE 858 // WHERE. 866 859 array( 867 860 'id' => $activity[ $user_id ]['activity_id'], 868 861 ), 869 862 870 // Data sanitization format 863 // Data sanitization format. 871 864 array( 872 865 '%s', 873 866 ), 874 867 875 // WHERE sanitization format 868 // WHERE sanitization format. 876 869 array( 877 870 '%d', … … 879 872 ); 880 873 881 // add new date to existing activity entry for caching874 // Add new date to existing activity entry for caching. 882 875 $activity[ $user_id ]['date_recorded'] = $time; 883 876 … … 886 879 $table_name, 887 880 888 // Data 881 // Data. 889 882 array( 890 883 'user_id' => $user_id, … … 898 891 ), 899 892 900 // Data sanitization format 893 // Data sanitization format. 901 894 array( 902 895 '%d', … … 911 904 ); 912 905 913 // set up activity array for caching914 // view the foreach loop in the get_last_activity() method for format906 // Set up activity array for caching. 907 // View the foreach loop in the get_last_activity() method for format. 915 908 $activity = array(); 916 909 $activity[ $user_id ] = array( … … 921 914 } 922 915 923 // set cache916 // Set cache. 924 917 wp_cache_set( $user_id, $activity[ $user_id ], 'bp_last_activity' ); 925 918 … … 932 925 * @since 2.0.0 933 926 * 934 * @param int $user_id 935 * 927 * @param int $user_id ID of the user whose activity should be deleted. 936 928 * @return bool True on success, false on failure or if no last_activity 937 929 * is found for the user. … … 949 941 buddypress()->members->table_name_last_activity, 950 942 951 // WHERE 943 // WHERE. 952 944 array( 953 945 'id' => $existing[ $user_id ]['activity_id'], 954 946 ), 955 947 956 // WHERE sanitization format 948 // WHERE sanitization format. 957 949 array( 958 950 '%s',
Note: See TracChangeset
for help on using the changeset viewer.