diff --git a/includes/model/class-follower.php b/includes/model/class-follower.php index 7117cae..7c590e5 100644 --- a/includes/model/class-follower.php +++ b/includes/model/class-follower.php @@ -33,6 +33,19 @@ class Follower extends Actor { return get_post_meta( $this->_id, 'activitypub_errors' ); } + /** + * Get the Summary. + * + * @return int The Summary. + */ + public function get_summary() { + if ( isset( $this->summary ) ) { + return $this->summary; + } + + return ''; + } + /** * Getter for URL attribute. * @@ -122,11 +135,11 @@ class Follower extends Actor { $args = array( 'ID' => $this->get__id(), 'guid' => esc_url_raw( $this->get_id() ), - 'post_title' => esc_html( $this->get_name() ), + 'post_title' => wp_strip_all_tags( sanitize_text_field( $this->get_name() ) ), 'post_author' => 0, 'post_type' => Followers::POST_TYPE, 'post_name' => esc_url_raw( $this->get_id() ), - 'post_excerpt' => $this->get_summary() ? esc_html( $this->get_summary() ) : '', + 'post_excerpt' => sanitize_text_field( wp_kses( $this->get_summary(), 'user_description' ) ), 'post_status' => 'publish', 'meta_input' => $this->get_post_meta_input(), ); @@ -266,6 +279,8 @@ class Follower extends Actor { $object = self::init_from_json( $actor_json ); $object->set__id( $post->ID ); $object->set_id( $post->guid ); + $object->set_name( $post->post_title ); + $object->set_summary( $post->post_excerpt ); $object->set_published( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_published ) ) ); $object->set_updated( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) ) ); diff --git a/tests/test-class-db-activitypub-followers.php b/tests/test-class-db-activitypub-followers.php index 14b77f6..cf7de1e 100644 --- a/tests/test-class-db-activitypub-followers.php +++ b/tests/test-class-db-activitypub-followers.php @@ -40,7 +40,7 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase { 'id' => 'https://user2.example.com', 'url' => 'https://user2.example.com', 'inbox' => 'https://user2.example.com/inbox', - 'name' => 'user2', + 'name' => 'úser2', 'preferredUsername' => 'user2', ), ); @@ -126,6 +126,7 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase { $follower2 = \Activitypub\Collection\Followers::get_follower( 2, 'https://user2.example.com' ); $this->assertEquals( 'https://user2.example.com', $follower2->get_url() ); + $this->assertEquals( 'úser2', $follower2->get_name() ); } public function test_delete_follower() {