/** * @covers ::bbp_get_topic_favoriters */ public function test_bbp_get_topic_favoriters() { $u = $this->factory->user->create_many(3); $t = $this->factory->topic->create(); // Add topic favorites. bbp_add_user_favorite($u[0], $t); bbp_add_user_favorite($u[1], $t); $expected = array($u[0], $u[1]); $favoriters = bbp_get_topic_favoriters($t); $this->assertEquals($expected, $favoriters); // Add topic favorites. bbp_add_user_favorite($u[2], $t); $expected = array($u[0], $u[1], $u[2]); $favoriters = bbp_get_topic_favoriters($t); $this->assertEquals($expected, $favoriters); // Remove user favorite. bbp_remove_user_favorite($u[1], $t); $expected = array($u[0], $u[2]); $favoriters = bbp_get_topic_favoriters($t); $this->assertEquals($expected, $favoriters); }
/** * Remove a deleted topic from all users' favorites * * @since bbPress (r2652) * * @param int $topic_id Get the topic id to remove * @uses bbp_get_topic_id To get the topic id * @uses bbp_get_topic_favoriters() To get the topic's favoriters * @uses bbp_remove_user_favorite() To remove the topic from user's favorites */ function bbp_remove_topic_from_all_favorites($topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); // Bail if no topic if (empty($topic_id)) { return; } // Get users $users = (array) bbp_get_topic_favoriters($topic_id); // Users exist if (!empty($users)) { // Loop through users foreach ($users as $user) { // Remove each user bbp_remove_user_favorite($user, $topic_id); } } }