Changeset 12754
- Timestamp:
- 10/15/2020 06:33:17 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-core-user.php
r12588 r12754 761 761 // Fetch the user's last_activity. 762 762 if ( 'active' != $type ) { 763 $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' ) ));763 $user_activity = self::get_last_activity( $user_ids ); 764 764 for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { 765 765 foreach ( (array) $user_activity as $activity ) { 766 if ( $activity->id == $paged_users[$i]->id ) 767 $paged_users[$i]->last_activity = $activity->last_activity; 766 if ( ! empty( $activity['user_id'] ) && (int) $activity['user_id'] === (int) $paged_users[$i]->id ) { 767 $paged_users[$i]->last_activity = $activity['date_recorded']; 768 } 768 769 } 769 770 } -
trunk/src/bp-members/bp-members-functions.php
r12729 r12754 127 127 ), 'core_get_users' ); 128 128 129 // For legacy users. Use of BP_Core_User::get_users() is deprecated. 130 if ( apply_filters( 'bp_use_legacy_user_query', false, __FUNCTION__, $r ) ) { 129 /** 130 * For legacy users. Use of BP_Core_User::get_users() is deprecated. 131 * 132 * Forcing this filter to true will use the legacy user query. As of 133 * BuddyPress 7.0.0, mirroring of the 'last_activity' value to usermeta 134 * is also disabled if true. See bp_update_user_last_activity(). 135 * 136 * @since 2.0.0 137 * 138 * @param bool $retval Defaults to false. 139 * @param string $function Current function name. 140 * @param array $r User query arguments. 141 */ 142 $use_legacy_query = apply_filters( 'bp_use_legacy_user_query', false, __FUNCTION__, $r ); 143 144 if ( $use_legacy_query ) { 131 145 $retval = BP_Core_User::get_users( 132 146 $r['type'], … … 1049 1063 * 1050 1064 * @since 1.9.0 1065 * @since 7.0.0 Backward compatibility usermeta mirroring is only allowed if the 1066 * legacy user query is enabled. 1051 1067 * 1052 1068 * @param int $user_id ID of the user being updated. … … 1071 1087 } 1072 1088 1073 // As of BuddyPress 2.0, last_activity is no longer stored in usermeta. 1074 // However, we mirror it there for backward compatibility. Do not use! 1075 // Remove our warning and re-add. 1076 remove_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10 ); 1077 remove_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10 ); 1078 bp_update_user_meta( $user_id, 'last_activity', $time ); 1079 add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 ); 1080 add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 4 ); 1089 /** This filter is documented in bp_core_get_users() */ 1090 $use_legacy_query = apply_filters( 'bp_use_legacy_user_query', false, __FUNCTION__, [ 'user_id' => $user_id ] ); 1091 1092 /* 1093 * As of BuddyPress 2.0, last_activity is no longer stored in usermeta. 1094 * However, we mirror it there for backward compatibility. Do not use! 1095 * 1096 * As of BuddyPress 7.0, mirroring is only allowed if the legacy user 1097 * query is enabled. 1098 */ 1099 if ( $use_legacy_query ) { 1100 remove_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10 ); 1101 remove_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10 ); 1102 bp_update_user_meta( $user_id, 'last_activity', $time ); 1103 add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 ); 1104 add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 4 ); 1105 } 1081 1106 1082 1107 return BP_Core_User::update_last_activity( $user_id, $time ); -
trunk/tests/phpunit/testcases/core/class-bp-core-user.php
r11737 r12754 10 10 */ 11 11 public function test_get_users_with_exclude_querystring() { 12 add_filter( 'bp_use_legacy_user_query', '__return_true' ); 13 12 14 $u1 = self::factory()->user->create(); 13 15 $u2 = self::factory()->user->create(); … … 19 21 $user_ids = wp_parse_id_list( wp_list_pluck( $users['users'], 'id' ) ); 20 22 23 remove_filter( 'bp_use_legacy_user_query', '__return_true' ); 24 21 25 $this->assertEquals( array( $u2 ), $user_ids ); 22 26 } … … 26 30 */ 27 31 public function test_get_users_with_exclude_array() { 32 add_filter( 'bp_use_legacy_user_query', '__return_true' ); 33 28 34 $u1 = self::factory()->user->create(); 29 35 $u2 = self::factory()->user->create(); … … 39 45 $user_ids = wp_parse_id_list( wp_list_pluck( $users['users'], 'id' ) ); 40 46 47 remove_filter( 'bp_use_legacy_user_query', '__return_true' ); 48 41 49 $this->assertEquals( array( $u2 ), $user_ids ); 42 50 } … … 46 54 */ 47 55 public function test_get_users_with_include_querystring() { 56 add_filter( 'bp_use_legacy_user_query', '__return_true' ); 57 48 58 $u1 = self::factory()->user->create( array( 49 59 'last_activity' => gmdate( 'Y-m-d H:i:s' ), … … 61 71 $user_ids = wp_parse_id_list( wp_list_pluck( $users['users'], 'id' ) ); 62 72 73 remove_filter( 'bp_use_legacy_user_query', '__return_true' ); 74 63 75 $this->assertEquals( array( $u1, $u3 ), $user_ids ); 64 76 } … … 68 80 */ 69 81 public function test_get_users_with_include_array() { 82 add_filter( 'bp_use_legacy_user_query', '__return_true' ); 83 70 84 $u1 = self::factory()->user->create( array( 71 85 'last_activity' => gmdate( 'Y-m-d H:i:s' ), … … 91 105 $user_ids = array_map( 'intval', $user_ids ); 92 106 107 remove_filter( 'bp_use_legacy_user_query', '__return_true' ); 108 93 109 $this->assertEquals( array( $u1, $u3 ), $user_ids ); 94 110 } -
trunk/tests/phpunit/testcases/members/functions.php
r12679 r12754 387 387 // Setup parameters to assert to be the same 388 388 $expected = $time; 389 $found = bp_get_user_ meta( $user, 'last_activity', true);389 $found = bp_get_user_last_activity( $user ); 390 390 391 391 $this->assertSame( $expected, $found );
Note: See TracChangeset
for help on using the changeset viewer.