This commit is contained in:
Matthias Pfefferle 2023-04-23 22:56:45 +02:00
parent 69aa0b9691
commit 28c077e422

View file

@ -28,6 +28,13 @@ class Post {
*/
private $id;
/**
* The Object URL.
*
* @var string
*/
private $url;
/**
* The Object Summary.
*
@ -179,6 +186,7 @@ class Post {
$array = array(
'id' => $this->get_id(),
'url' => $this->get_url(),
'type' => $this->get_object_type(),
'published' => \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_date_gmt ) ),
'attributedTo' => \get_author_posts_url( $post->post_author ),
@ -206,6 +214,29 @@ class Post {
return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
}
/**
* Returns the URL of an Activity Object
*
* @return string
*/
public function get_url() {
if ( $this->url ) {
return $this->url;
}
$post = $this->post;
if ( 'trash' === get_post_status( $post ) ) {
$permalink = \get_post_meta( $post->url, 'activitypub_canonical_url', true );
} else {
$permalink = \get_permalink( $post );
}
$this->url = $permalink;
return $permalink;
}
/**
* Returns the ID of an Activity Object
*
@ -216,17 +247,9 @@ class Post {
return $this->id;
}
$post = $this->post;
$this->id = $this->get_url();
if ( 'trash' === get_post_status( $post ) ) {
$permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
} else {
$permalink = \get_permalink( $post );
}
$this->id = $permalink;
return $permalink;
return $this->id;
}
/**