Skip to content

Commit 5aa38b6

Browse files
committed
Use friends- prefix for post format channels in Friends adapter
1 parent 971332b commit 5aa38b6

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

includes/adapters/class-friends.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function get_channels( $channels, $user_id ) {
167167

168168
foreach ( $post_formats as $format => $name ) {
169169
$channels[] = array(
170-
'uid' => 'format-' . $format,
170+
'uid' => 'friends-' . $format,
171171
'name' => $name,
172172
);
173173
}
@@ -344,19 +344,21 @@ public function get_timeline( $result, $channel, $args ) {
344344
}
345345

346346
$query_args['author__in'] = $friend_users;
347-
} elseif ( str_starts_with( $channel, 'format-' ) ) {
347+
} elseif ( str_starts_with( $channel, 'friends-' ) ) {
348348
// Filter by post format.
349-
$format = substr( $channel, 7 );
349+
$format = substr( $channel, 8 );
350350

351351
if ( 'standard' === $format ) {
352352
// Standard = posts without any post format.
353+
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
353354
$query_args['tax_query'] = array(
354355
array(
355356
'taxonomy' => 'post_format',
356357
'operator' => 'NOT EXISTS',
357358
),
358359
);
359360
} else {
361+
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
360362
$query_args['tax_query'] = array(
361363
array(
362364
'taxonomy' => 'post_format',
@@ -368,7 +370,7 @@ public function get_timeline( $result, $channel, $args ) {
368370
} elseif ( 'home' !== $channel ) {
369371
// Unknown channel, pass to next adapter.
370372
return $result;
371-
}
373+
}//end if
372374

373375
// Handle cursor-based pagination.
374376
if ( ! empty( $args['after'] ) ) {
@@ -385,7 +387,7 @@ public function get_timeline( $result, $channel, $args ) {
385387
'after' => $args['before'],
386388
),
387389
);
388-
$query_args['order'] = 'ASC';
390+
$query_args['order'] = 'ASC';
389391
}
390392

391393
$query = new \WP_Query( $query_args );
@@ -414,7 +416,8 @@ public function get_following( $result, $channel, $user_id ) {
414416
$friend_users = $this->get_friend_users_for_channel( $channel );
415417

416418
if ( null === $friend_users ) {
417-
return $result; // Unknown channel.
419+
return $result;
420+
// Unknown channel.
418421
}
419422

420423
foreach ( $friend_users as $friend_user ) {
@@ -444,8 +447,8 @@ public function get_following( $result, $channel, $user_id ) {
444447
}
445448

446449
$result[] = $feed;
447-
}
448-
}
450+
}//end foreach
451+
}//end foreach
449452

450453
return $result;
451454
}
@@ -458,7 +461,7 @@ public function get_following( $result, $channel, $user_id ) {
458461
*/
459462
protected function get_friend_users_for_channel( $channel ) {
460463
// For home, notifications, and format channels, return all friends.
461-
if ( 'home' === $channel || 'notifications' === $channel || str_starts_with( $channel, 'format-' ) ) {
464+
if ( 'home' === $channel || 'notifications' === $channel || str_starts_with( $channel, 'friends-' ) ) {
462465
$query = \Friends\User_Query::all_friends_subscriptions();
463466
return $query->get_results();
464467
}
@@ -485,9 +488,10 @@ protected function get_friend_users_for_channel( $channel ) {
485488
}
486489
}
487490
return $users;
488-
}
491+
}//end if
489492

490-
return null; // Unknown channel.
493+
return null;
494+
// Unknown channel.
491495
}
492496

493497
/**
@@ -506,7 +510,8 @@ public function follow( $result, $channel, $url, $user_id ) {
506510

507511
// Check if we can handle this URL.
508512
if ( ! $this->can_handle_url( $url ) ) {
509-
return $result; // Pass to next adapter.
513+
return $result;
514+
// Pass to next adapter.
510515
}
511516

512517
// Use Friends plugin to subscribe to the URL.
@@ -550,7 +555,8 @@ public function unfollow( $result, $channel, $url, $user_id ) {
550555
$feed = $this->get_feed_by_url( $url );
551556

552557
if ( ! $feed ) {
553-
return $result; // Pass to next adapter.
558+
return $result;
559+
// Pass to next adapter.
554560
}
555561

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

0 commit comments

Comments
 (0)