Changeset 13180
- Timestamp:
- 12/11/2021 07:40:10 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/bp-members-activity.php
r13177 r13180 251 251 } 252 252 add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity', 10, 4 ); 253 254 /** 255 * Remove the `new_avatar` activity corresponding to the deleted previous avatar. 256 * 257 * @since 10.0.0 258 * 259 * @param int $user_id The user ID. 260 * @param int $timestamp The timestamp when the activity was created. 261 * @return bool True on success. False otherwise. 262 */ 263 function bp_members_remove_previous_avatar_activity( $user_id = 0, $timestamp = 0 ) { 264 if ( ! $user_id || ! $timestamp || ! bp_is_active( 'activity' ) ) { 265 return false; 266 } 267 268 // Look for a `new_avatar` activity corresponding to the date and user. 269 $activity_id = BP_Activity_Activity::get_id( 270 array( 271 'user_id' => $user_id, 272 'component' => buddypress()->members->id, 273 'type' => 'new_avatar', 274 'date_recorded' => date( 'Y-m-d H:i:s', $timestamp ), 275 ) 276 ); 277 278 if ( $activity_id ) { 279 return bp_activity_delete( 280 array( 281 'id' => $activity_id, 282 ) 283 ); 284 } 285 286 return false; 287 } 288 add_action( 'bp_previous_user_avatar_deleted', 'bp_members_remove_previous_avatar_activity', 10, 2 ); -
trunk/tests/phpunit/testcases/members/activity.php
r13155 r13180 150 150 $this->assertEquals( 2, $new_avatar_activities['total'] ); 151 151 } 152 153 /** 154 * @group bp_members_remove_previous_avatar_activity 155 */ 156 public function test_bp_members_remove_previous_avatar_activity() { 157 $u = self::factory()->user->create(); 158 $timestamp = strtotime( bp_core_current_time() ); 159 $prev_timestamp = $timestamp - ( 121 * HOUR_IN_SECONDS ); 160 $date_recorded = date( 'Y-m-d H:i:s', $timestamp ); 161 $prev_time = date( 'Y-m-d H:i:s', $prev_timestamp ); 162 163 $a1 = self::factory()->activity->create( array( 164 'component' => buddypress()->members->id, 165 'type' => 'new_avatar', 166 'user_id' => $u, 167 'recorded_time' => $prev_time, 168 ) ); 169 170 $a2 = self::factory()->activity->create( 171 array( 172 'component' => buddypress()->members->id, 173 'type' => 'new_avatar', 174 'user_id' => $u, 175 'recorded_time' => $date_recorded, 176 ) 177 ); 178 179 $this->assertTrue( bp_members_remove_previous_avatar_activity( $u, $prev_timestamp ) ); 180 181 $new_avatar_activities = bp_activity_get( array( 182 'filter' => array( 183 'object' => buddypress()->members->id, 184 'user_id' => $u, 185 'action' => 'new_avatar', 186 ), 187 'count_total' => 'count_query', 188 ) ); 189 190 $this->assertEquals( 1, $new_avatar_activities['total'] ); 191 } 152 192 }
Note: See TracChangeset
for help on using the changeset viewer.