Skip to content

Commit 3cae586

Browse files
authored
Integrate Federated Reply block with Reader post share (#2302)
1 parent 500aef9 commit 3cae586

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
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+
Integrate Federated Reply block with WP.com Reader's post share functionality, allowing users to reply to ActivityPub posts directly from the Reader.

integration/class-jetpack.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
use Activitypub\Collection\Followers;
1111
use Activitypub\Collection\Following;
1212
use Activitypub\Comment;
13+
use Activitypub\Http;
1314
use Automattic\Jetpack\Connection\Manager;
1415

16+
use function Activitypub\is_activity_object;
17+
1518
/**
1619
* Jetpack integration class.
1720
*/
@@ -36,6 +39,8 @@ public static function init() {
3639
\add_filter( 'activitypub_following_row_actions', array( self::class, 'add_reader_link' ), 10, 2 );
3740
\add_filter( 'pre_option_activitypub_following_ui', array( self::class, 'pre_option_activitypub_following_ui' ) );
3841
}
42+
43+
\add_action( 'load-post-new.php', array( self::class, 'adapt_post_share' ) );
3944
}
4045

4146
/**
@@ -128,4 +133,25 @@ public static function add_reader_link( $actions, $item ) {
128133
public static function pre_option_activitypub_following_ui() {
129134
return '1';
130135
}
136+
137+
/**
138+
* Adapt the parameters for a post share request to be compatible with the Federated Reply block.
139+
*/
140+
public static function adapt_post_share() {
141+
if ( ! isset( $_GET['is_post_share'], $_GET['url'] ) || ! $_GET['is_post_share'] ) { // phpcs:ignore WordPress.Security
142+
return;
143+
}
144+
145+
$url = \sanitize_url( \wp_unslash( $_GET['url'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
146+
147+
if ( is_activity_object( Http::get_remote_object( $url ) ) ) {
148+
$args = array(
149+
'post_type' => 'post',
150+
'in_reply_to' => $url,
151+
);
152+
153+
\wp_safe_redirect( \add_query_arg( $args, \admin_url( 'post-new.php' ) ) );
154+
exit;
155+
}
156+
}
131157
}

0 commit comments

Comments
 (0)