Changeset 7860 for trunk/bp-members/bp-members-functions.php
- Timestamp:
- 02/12/2014 09:27:20 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-members/bp-members-functions.php
r7764 r7860 511 511 512 512 if ( !$count = get_transient( 'bp_active_member_count' ) ) { 513 $bp = buddypress(); 514 513 515 // Avoid a costly join by splitting the lookup 514 516 if ( is_multisite() ) { … … 520 522 $exclude_users = $wpdb->get_col( $sql ); 521 523 $exclude_users_sql = !empty( $exclude_users ) ? "AND user_id NOT IN (" . implode( ',', wp_parse_id_list( $exclude_users ) ) . ")" : ''; 522 $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(user_id) FROM {$ wpdb->usermeta} WHERE meta_key = %s {$exclude_users_sql}", bp_get_user_meta_key( 'last_activity' )) );524 $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = 'last_activity' {$exclude_users_sql}", $bp->members->id ) ); 523 525 524 526 set_transient( 'bp_active_member_count', $count ); … … 818 820 819 821 /** 820 * Update a user's last activity 821 * 822 * @since BuddyPress (1.9) 823 * @param int $user_id ID of the user being updated 824 * @param string $time Time of last activity, in 'Y-m-d H:i:s' format 825 * @return bool True on success 822 * Update a user's last activity. 823 * 824 * @since BuddyPress (1.9.0) 825 * 826 * @param int $user_id ID of the user being updated. 827 * @param string $time Time of last activity, in 'Y-m-d H:i:s' format. 828 * @return bool True on success, false on failure. 826 829 */ 827 830 function bp_update_user_last_activity( $user_id = 0, $time = '' ) { … … 841 844 } 842 845 843 return bp_update_user_meta( $user_id, 'last_activity', $time ); 844 } 845 846 /** 847 * Get the last activity for a given user 848 * 849 * @param int $user_id The ID of the user 846 // As of BuddyPress 2.0, last_activity is no longer stored in usermeta. 847 // However, we mirror it there for backward compatibility. Do not use! 848 // Remove our warning and re-add. 849 remove_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 ); 850 update_user_meta( $user_id, 'last_activity', $time ); 851 add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 ); 852 853 return BP_Core_User::update_last_activity( $user_id, $time ); 854 } 855 856 /** 857 * Backward compatibility for 'last_activity' usermeta fetching. 858 * 859 * In BuddyPress 2.0, user last_activity data was moved out of usermeta. For 860 * backward compatibility, we continue to mirror the data there. This function 861 * serves two purposes: it warns plugin authors of the change, and it returns 862 * the data from the proper location. 863 * 864 * @since BuddyPress (2.0.0) 865 * 866 * @access private For internal use only. 867 * 868 * @param null $retval 869 * @param int $object_id ID of the user. 870 * @param string $meta_key Meta key being fetched. 871 */ 872 function _bp_get_user_meta_last_activity_warning( $retval, $object_id, $meta_key ) { 873 static $warned; 874 875 if ( 'last_activity' === $meta_key ) { 876 // Don't send the warning more than once per pageload 877 if ( empty( $warned ) ) { 878 _doing_it_wrong( 'get_user_meta( $user_id, \'last_activity\' )', __( 'User last_activity data is no longer stored in usermeta. Use bp_get_user_last_activity() instead.', 'buddypress' ), '2.0.0' ); 879 $warned = 1; 880 } 881 882 return bp_get_user_last_activity( $object_id ); 883 } 884 885 return $retval; 886 } 887 add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 3 ); 888 889 /** 890 * Backward compatibility for 'last_activity' usermeta setting. 891 * 892 * In BuddyPress 2.0, user last_activity data was moved out of usermeta. For 893 * backward compatibility, we continue to mirror the data there. This function 894 * serves two purposes: it warns plugin authors of the change, and it updates 895 * the data in the proper location. 896 * 897 * @since BuddyPress (2.0.0) 898 * 899 * @access private For internal use only. 900 * 901 * @param int $meta_id ID of the just-set usermeta row. 902 * @param int $object_id ID of the user. 903 * @param string $meta_key Meta key being fetched. 904 * @param string $meta_value Active time. 905 */ 906 function _bp_update_user_meta_last_activity_warning( $meta_id, $object_id, $meta_key, $meta_value ) { 907 if ( 'last_activity' === $meta_key ) { 908 _doing_it_wrong( 'update_user_meta( $user_id, \'last_activity\' )', __( 'User last_activity data is no longer stored in usermeta. Use bp_update_user_last_activity() instead.', 'buddypress' ), '2.0.0' ); 909 bp_update_user_last_activity( $object_id, $meta_value ); 910 } 911 } 912 add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 ); 913 914 /** 915 * Get the last activity for a given user. 916 * 917 * @param int $user_id The ID of the user. 850 918 * @return string Time of last activity, in 'Y-m-d H:i:s' format, or an empty 851 * string if none is found919 * string if none is found. 852 920 */ 853 921 function bp_get_user_last_activity( $user_id = 0 ) { 854 // Fall back on current user855 if ( empty( $user_id ) ) { 856 $user_id = bp_loggedin_user_id();857 }858 859 $activity = bp_get_user_meta( $user_id, 'last_activity', true );922 $activity = ''; 923 924 $last_activity = BP_Core_User::get_last_activity( $user_id ); 925 if ( ! empty( $last_activity[ $user_id ] ) ) { 926 $activity = $last_activity[ $user_id ]['date_recorded']; 927 } 860 928 861 929 return apply_filters( 'bp_get_user_last_activity', $activity, $user_id ); … … 997 1065 function bp_core_remove_data( $user_id ) { 998 1066 999 // Remove usermeta1000 bp_delete_user_meta( $user_id, 'last_activity');1067 // Remove last_activity data 1068 BP_Core_User::delete_last_activity( $user_id ); 1001 1069 1002 1070 // Flush the cache to remove the user from all cached objects
Note: See TracChangeset
for help on using the changeset viewer.