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:
parent
20d15bc95d
commit
444c4b2837
4 changed files with 42 additions and 4 deletions
|
@ -240,8 +240,11 @@ class Signature {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix route for subdirectory installs
|
// 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 );
|
||||||
$path = trim( $path, '/' );
|
|
||||||
|
if ( \is_string( $path ) ) {
|
||||||
|
$path = trim( $path, '/' );
|
||||||
|
}
|
||||||
|
|
||||||
if ( $path ) {
|
if ( $path ) {
|
||||||
$route = '/' . $path . $route;
|
$route = '/' . $path . $route;
|
||||||
|
|
|
@ -115,8 +115,8 @@ class Post {
|
||||||
$wp_post = $this->wp_post;
|
$wp_post = $this->wp_post;
|
||||||
$object = new Base_Object();
|
$object = new Base_Object();
|
||||||
|
|
||||||
$object->set_id( \esc_url( \get_permalink( $wp_post->ID ) ) );
|
$object->set_id( $this->get_id() );
|
||||||
$object->set_url( \esc_url( \get_permalink( $wp_post->ID ) ) );
|
$object->set_url( $this->get_url() );
|
||||||
$object->set_type( $this->get_object_type() );
|
$object->set_type( $this->get_object_type() );
|
||||||
|
|
||||||
$published = \strtotime( $wp_post->post_date_gmt );
|
$published = \strtotime( $wp_post->post_date_gmt );
|
||||||
|
@ -151,6 +151,32 @@ class Post {
|
||||||
return $object;
|
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.
|
* Returns the User-URL of the Author of the Post.
|
||||||
*
|
*
|
||||||
|
|
|
@ -55,6 +55,11 @@
|
||||||
<p class="description">
|
<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' ); ?>
|
<?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>
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
<?php \esc_html_e( 'Please avoid using an existing author’s name as the blog profile ID. Fediverse platforms might use caching and this could break the functionality completely.', 'activitypub' ); ?>
|
||||||
|
</strong>
|
||||||
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -19,5 +19,9 @@ class Test_Activitypub_Post extends WP_UnitTestCase {
|
||||||
$activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
|
$activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
|
||||||
|
|
||||||
$this->assertEquals( $permalink, $activitypub_post->get_id() );
|
$this->assertEquals( $permalink, $activitypub_post->get_id() );
|
||||||
|
|
||||||
|
$cached = \get_post_meta( $post, 'activitypub_canonical_url', true );
|
||||||
|
|
||||||
|
$this->assertEquals( $cached, $activitypub_post->get_id() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue