From d4f5ad8ec19ba2307ec8cbd3decfcaeff5daf13b Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 6 Jul 2023 16:10:48 +0200 Subject: [PATCH] use post_meta instead of post_content --- includes/collection/class-followers.php | 17 +++++++++++++++-- includes/model/class-follower.php | 7 ++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/includes/collection/class-followers.php b/includes/collection/class-followers.php index bc35a18..65d8cdb 100644 --- a/includes/collection/class-followers.php +++ b/includes/collection/class-followers.php @@ -100,6 +100,18 @@ class Followers { ) ); + register_post_meta( + self::POST_TYPE, + 'activitypub_actor_json', + array( + 'type' => 'string', + 'single' => true, + 'sanitize_callback' => function( $value ) { + return sanitize_text_field( $value ); + }, + ) + ); + do_action( 'activitypub_after_register_post_type' ); } @@ -254,13 +266,14 @@ class Followers { if ( isset( $object['user_id'] ) ) { unset( $object['user_id'] ); - unset( $object['@context'] ); } + unset( $object['@context'] ); + $user = Users::get_by_id( $user_id ); // get inbox - $inbox = $follower->get_inbox(); + $inbox = $follower->get_shared_inbox(); // send "Accept" activity $activity = new Activity(); diff --git a/includes/model/class-follower.php b/includes/model/class-follower.php index 573696b..0036f8f 100644 --- a/includes/model/class-follower.php +++ b/includes/model/class-follower.php @@ -111,7 +111,6 @@ class Follower extends Actor { 'post_type' => Followers::POST_TYPE, 'post_name' => esc_url_raw( $this->get_id() ), 'post_excerpt' => esc_html( $this->get_summary() ) ? $this->get_summary() : '', - 'post_content' => esc_sql( $this->to_json() ), 'post_status' => 'publish', 'meta_input' => $this->get_post_meta_input(), ); @@ -150,7 +149,8 @@ class Follower extends Actor { */ protected function get_post_meta_input() { $meta_input = array(); - $meta_input['activitypub_inbox'] = esc_url_raw( $this->get_shared_inbox() ); + $meta_input['activitypub_inbox'] = $this->get_shared_inbox(); + $meta_input['activitypub_actor_json'] = $this->to_json(); return $meta_input; } @@ -197,7 +197,8 @@ class Follower extends Actor { * @return array Activitypub\Model\Follower */ public static function init_from_cpt( $post ) { - $object = self::init_from_json( $post->post_content ); + $actor_json = get_post_meta( $post->ID, 'activitypub_actor_json', true ); + $object = self::init_from_json( $actor_json ); $object->set__id( $post->ID ); $object->set_id( $post->guid ); $object->set_published( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_published ) ) );