Fixes PHP warnings and remote delete (#468)

* fix #463

* fix delete

/cc #465 @janboddez

* add disclaimer to not use the same name as an author login

see #470

* check if url is cached before trashing it
This commit is contained in:
Matthias Pfefferle 2023-09-27 11:05:11 +02:00 committed by GitHub
parent 20d15bc95d
commit 444c4b2837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 4 deletions

View file

@ -240,8 +240,11 @@ class Signature {
}
// fix route for subdirectory installs
$path = wp_parse_url( get_home_url(), PHP_URL_PATH );
$path = \wp_parse_url( \get_home_url(), PHP_URL_PATH );
if ( \is_string( $path ) ) {
$path = trim( $path, '/' );
}
if ( $path ) {
$route = '/' . $path . $route;

View file

@ -115,8 +115,8 @@ class Post {
$wp_post = $this->wp_post;
$object = new Base_Object();
$object->set_id( \esc_url( \get_permalink( $wp_post->ID ) ) );
$object->set_url( \esc_url( \get_permalink( $wp_post->ID ) ) );
$object->set_id( $this->get_id() );
$object->set_url( $this->get_url() );
$object->set_type( $this->get_object_type() );
$published = \strtotime( $wp_post->post_date_gmt );
@ -151,6 +151,32 @@ class Post {
return $object;
}
/**
* Returns the ID of the Post.
*
* @return string The Posts ID.
*/
public function get_id() {
return $this->get_url();
}
/**
* Returns the URL of the Post.
*
* @return string The Posts URL.
*/
public function get_url() {
$post = $this->wp_post;
if ( 'trash' === get_post_status( $post ) ) {
$permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
} else {
$permalink = \get_permalink( $post );
}
return \esc_url( $permalink );
}
/**
* Returns the User-URL of the Author of the Post.
*

View file

@ -55,6 +55,11 @@
<p class="description">
<?php \esc_html_e( 'This profile name will federate all posts written on your blog, regardless of the author who posted it.', 'activitypub' ); ?>
</p>
<p>
<strong>
<?php \esc_html_e( 'Please avoid using an existing authors name as the blog profile ID. Fediverse platforms might use caching and this could break the functionality completely.', 'activitypub' ); ?>
</strong>
</p>
</td>
</tr>
</tbody>

View file

@ -19,5 +19,9 @@ class Test_Activitypub_Post extends WP_UnitTestCase {
$activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
$this->assertEquals( $permalink, $activitypub_post->get_id() );
$cached = \get_post_meta( $post, 'activitypub_canonical_url', true );
$this->assertEquals( $cached, $activitypub_post->get_id() );
}
}