Skip to content

Commit 2cbeca4

Browse files
committed
Fix unfollow: use custom get_feed_by_url method
1 parent 520cce2 commit 2cbeca4

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

includes/adapters/class-friends.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,36 @@ public function owns_feed( $url ) {
8888
return false;
8989
}
9090

91-
$feed = \Friends\User_Feed::get_by_url( $url );
91+
$feed = $this->get_feed_by_url( $url );
9292
return ! empty( $feed );
9393
}
9494

95+
/**
96+
* Find a user feed by URL.
97+
*
98+
* @param string $url The feed URL to find.
99+
* @return \Friends\User_Feed|null The feed or null if not found.
100+
*/
101+
protected function get_feed_by_url( $url ) {
102+
$friend_users = \Friends\User_Query::all_friends_subscriptions();
103+
104+
foreach ( $friend_users->get_results() as $friend_user ) {
105+
if ( ! $friend_user instanceof \Friends\User ) {
106+
continue;
107+
}
108+
109+
$user_feeds = $friend_user->get_active_feeds();
110+
111+
foreach ( $user_feeds as $user_feed ) {
112+
if ( $user_feed->get_url() === $url ) {
113+
return $user_feed;
114+
}
115+
}
116+
}
117+
118+
return null;
119+
}
120+
95121
/**
96122
* Get list of channels.
97123
*
@@ -522,16 +548,11 @@ public function unfollow( $result, $channel, $url, $user_id ) {
522548
return $result;
523549
}
524550

525-
// Check if we own this feed.
526-
if ( ! $this->owns_feed( $url ) ) {
527-
return $result; // Pass to next adapter.
528-
}
529-
530551
// Find the feed by URL.
531-
$feed = \Friends\User_Feed::get_by_url( $url );
552+
$feed = $this->get_feed_by_url( $url );
532553

533554
if ( ! $feed ) {
534-
return false;
555+
return $result; // Pass to next adapter.
535556
}
536557

537558
$friend_user = $feed->get_friend_user();

0 commit comments

Comments
 (0)