Skip to content

Commit 018abb9

Browse files
authored
Add activitypub_json REST field for ap_actor posts (#2121)
1 parent 404e3e1 commit 018abb9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-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+
Add activitypub_json REST field for ap_actor posts to access raw JSON data

includes/class-activitypub.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public static function init() {
3131
\add_action( 'init', array( self::class, 'register_post_types' ), 11 );
3232
\add_action( 'init', array( self::class, 'register_oembed_providers' ), 11 );
3333

34+
\add_action( 'rest_api_init', array( self::class, 'register_ap_actor_rest_field' ) );
35+
3436
\add_filter( 'template_include', array( self::class, 'render_activitypub_template' ), 99 );
3537
\add_action( 'template_redirect', array( self::class, 'template_redirect' ) );
3638
\add_filter( 'redirect_canonical', array( self::class, 'redirect_canonical' ), 10, 2 );
@@ -806,6 +808,32 @@ public static function register_post_types() {
806808
\do_action( 'activitypub_after_register_post_type' );
807809
}
808810

811+
/**
812+
* Register REST field for ap_actor posts.
813+
*/
814+
public static function register_ap_actor_rest_field() {
815+
\register_rest_field(
816+
Actors::POST_TYPE,
817+
'activitypub_json',
818+
array(
819+
/**
820+
* Get the raw post content without WordPress content filtering.
821+
*
822+
* @param array $response Prepared response array.
823+
* @return string The raw post content.
824+
*/
825+
'get_callback' => function ( $response ) {
826+
return \get_post_field( 'post_content', $response['id'] );
827+
},
828+
'schema' => array(
829+
'description' => 'Raw ActivityPub JSON data without WordPress content filtering',
830+
'type' => 'string',
831+
'context' => array( 'view', 'edit' ),
832+
),
833+
)
834+
);
835+
}
836+
809837
/**
810838
* Add the 'activitypub' capability to users who can publish posts.
811839
*

0 commit comments

Comments
 (0)