Skip to content

Commit 06ebf1f

Browse files
authored
Add row action filters and Jetpack Reader link integration (#2241)
1 parent 3a2fa90 commit 06ebf1f

File tree

8 files changed

+487
-6
lines changed

8 files changed

+487
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
You can now follow people and see their updates right in the WordPress.com Reader when using Jetpack or WordPress.com.

includes/wp-admin/class-admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static function init() {
8282
*/
8383
public static function admin_notices() {
8484
$current_screen = get_current_screen();
85+
8586
if ( ! $current_screen ) {
8687
return;
8788
}

includes/wp-admin/table/class-blocked-actors.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,19 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
397397
),
398398
);
399399

400+
/**
401+
* Filters the array of row action links on the Blocked Actors list table.
402+
*
403+
* This filter is evaluated for each blocked actor item in the list table.
404+
*
405+
* @since unreleased
406+
*
407+
* @param string[] $actions An array of row action links. Defaults are
408+
* 'Unblock'.
409+
* @param array $item The current blocked actor item.
410+
*/
411+
$actions = apply_filters( 'activitypub_blocked_actors_row_actions', $actions, $item );
412+
400413
return $this->row_actions( $actions );
401414
}
402415
}

includes/wp-admin/table/class-followers.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,20 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
477477
}
478478
}
479479

480+
/**
481+
* Filters the array of row action links for each follower in the Followers list table.
482+
*
483+
* This filter allows you to modify the available row actions (such as Delete, Block, or Follow back)
484+
* for each follower item displayed in the table.
485+
*
486+
* @since unreleased
487+
*
488+
* @param string[] $actions An array of row action links. Defaults are
489+
* 'Delete', 'Block', and optionally 'Follow back'.
490+
* @param array $item The current follower item.
491+
*/
492+
$actions = apply_filters( 'activitypub_followers_row_actions', $actions, $item );
493+
480494
return $this->row_actions( $actions );
481495
}
482496

includes/wp-admin/table/class-following.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ public function single_row( $item ) {
481481
* @param array $item The current following item.
482482
* @param string $column_name The current column name.
483483
* @param string $primary The primary column name.
484+
*
484485
* @return string HTML for the row actions.
485486
*/
486487
protected function handle_row_actions( $item, $column_name, $primary ) {
@@ -498,6 +499,18 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
498499
),
499500
);
500501

502+
/**
503+
* Filters the array of row action links on the Following list table.
504+
*
505+
* This filter allows you to modify the row actions for each following item in the Following list table.
506+
*
507+
* @since unreleased
508+
*
509+
* @param string[] $actions An array of row action links. Defaults include 'Unfollow'.
510+
* @param array $item The current following item.
511+
*/
512+
$actions = apply_filters( 'activitypub_following_row_actions', $actions, $item );
513+
501514
return $this->row_actions( $actions );
502515
}
503516
}

integration/class-jetpack.php

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@ class Jetpack {
2020
* Initialize the class, registering WordPress hooks.
2121
*/
2222
public static function init() {
23-
\add_filter( 'jetpack_sync_post_meta_whitelist', array( self::class, 'add_sync_meta' ) );
24-
\add_filter( 'jetpack_sync_comment_meta_whitelist', array( self::class, 'add_sync_comment_meta' ) );
25-
\add_filter( 'jetpack_sync_whitelisted_comment_types', array( self::class, 'add_comment_types' ) );
26-
\add_filter( 'jetpack_json_api_comment_types', array( self::class, 'add_comment_types' ) );
27-
\add_filter( 'jetpack_api_include_comment_types_count', array( self::class, 'add_comment_types' ) );
23+
if ( ! \defined( 'IS_WPCOM' ) ) {
24+
\add_filter( 'jetpack_sync_post_meta_whitelist', array( self::class, 'add_sync_meta' ) );
25+
\add_filter( 'jetpack_sync_comment_meta_whitelist', array( self::class, 'add_sync_comment_meta' ) );
26+
\add_filter( 'jetpack_sync_whitelisted_comment_types', array( self::class, 'add_comment_types' ) );
27+
\add_filter( 'jetpack_json_api_comment_types', array( self::class, 'add_comment_types' ) );
28+
\add_filter( 'jetpack_api_include_comment_types_count', array( self::class, 'add_comment_types' ) );
29+
}
30+
31+
if (
32+
( \defined( 'IS_WPCOM' ) && IS_WPCOM ) ||
33+
( \class_exists( '\Jetpack' ) && \Jetpack::is_connection_ready() )
34+
) {
35+
\add_filter( 'activitypub_following_row_actions', array( self::class, 'add_reader_link' ), 10, 2 );
36+
\add_filter( 'pre_option_activitypub_following_ui', array( self::class, 'pre_option_activitypub_following_ui' ) );
37+
}
2838
}
2939

3040
/**
@@ -68,4 +78,47 @@ public static function add_comment_types( $comment_types ) {
6878

6979
return array_unique( \array_merge( $comment_types, Comment::get_comment_type_slugs() ) );
7080
}
81+
82+
/**
83+
* Add a "Reader" link to the bulk actions dropdown on the following list screen.
84+
*
85+
* @param array $actions The bulk actions.
86+
* @param array $item The current following item.
87+
*
88+
* @return array The bulk actions with the "Reader" link.
89+
*/
90+
public static function add_reader_link( $actions, $item ) {
91+
// Do not show the link for pending follow requests.
92+
if ( 'pending' === $item['status'] ) {
93+
return $actions;
94+
}
95+
96+
$feed = \get_post_meta( $item['id'], '_activitypub_actor_feed', true );
97+
98+
if ( isset( $feed['feed_id'] ) ) {
99+
$url = sprintf( 'https://wordpress.com/reader/feed/%d', (int) $feed['feed_id'] );
100+
} else {
101+
$url = sprintf( 'https://wordpress.com/reader/feeds/lookup/%s', rawurlencode( $item['identifier'] ) );
102+
}
103+
104+
return array_merge(
105+
array(
106+
'reader' => sprintf(
107+
'<a href="%s" target="_blank">%s</a>',
108+
esc_url( $url ),
109+
esc_html__( 'View Feed', 'activitypub' )
110+
),
111+
),
112+
$actions
113+
);
114+
}
115+
116+
/**
117+
* Force the ActivityPub Following UI to be enabled when Jetpack is active.
118+
*
119+
* @return string '1' to enable the ActivityPub Following UI.
120+
*/
121+
public static function pre_option_activitypub_following_ui() {
122+
return '1';
123+
}
71124
}

integration/load.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function plugin_init() {
6262
*
6363
* @see https://jetpack.com/
6464
*/
65-
if ( \defined( 'JETPACK__VERSION' ) && ! \defined( 'IS_WPCOM' ) ) {
65+
if ( \defined( 'JETPACK__VERSION' ) ) {
6666
Jetpack::init();
6767
}
6868

0 commit comments

Comments
 (0)