Skip to content

Commit 35e7a3f

Browse files
committed
Merge branch 'trunk' into add/oembed-reply-block
2 parents 1a964e4 + f61964c commit 35e7a3f

30 files changed

+1261
-435
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
* Updates to certain user meta fields did not trigger an Update activity.
13+
14+
## [5.4.0] - 2025-03-03
15+
16+
### Added
17+
18+
* Upgrade script to fix Follower json representations with unescaped backslashes.
19+
* Centralized place for sanitization functions.
20+
1021
### Changed
1122

1223
* Bumped minimum required WordPress version to 6.4.
1324
* Use a later hook for Posts to get published to the Outbox, to get sure all `post_meta`s and `taxonomy`s are set stored properly.
1425
* Use webfinger as author email for comments from the Fediverse.
26+
* Remove the special handling of comments from Enable Mastodon Apps.
27+
28+
### Fixed
29+
30+
* Do not redirect `/@username` URLs to the API any more, to improve `AUTHORIZED_FETCH` handling.
1531

1632
## [5.3.2] - 2025-02-27
1733

@@ -1353,8 +1369,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13531369

13541370
* initial
13551371

1356-
[Unreleased]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.2...trunk
1372+
[Unreleased]: https://github.com/Automattic/wordpress-activitypub/compare/5.4.0...trunk
13571373
<!-- Add new release below and update "Unreleased" link -->
1374+
[5.4.0]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.2...5.4.0
13581375
[5.3.2]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.1...5.3.2
13591376
[5.3.1]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.0...5.3.1
13601377
[5.3.0]: https://github.com/Automattic/wordpress-activitypub/compare/5.2.0...5.3.0

activitypub.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: ActivityPub
44
* Plugin URI: https://github.com/Automattic/wordpress-activitypub
55
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
6-
* Version: 5.3.2
6+
* Version: 5.4.0
77
* Author: Matthias Pfefferle & Automattic
88
* Author URI: https://automattic.com/
99
* License: MIT
@@ -19,7 +19,7 @@
1919

2020
use WP_CLI;
2121

22-
\define( 'ACTIVITYPUB_PLUGIN_VERSION', '5.3.2' );
22+
\define( 'ACTIVITYPUB_PLUGIN_VERSION', '5.4.0' );
2323

2424
// Plugin related constants.
2525
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
@@ -84,6 +84,7 @@ function plugin_init() {
8484
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Settings', 'init' ) );
8585
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Settings_Fields', 'init' ) );
8686
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Blog_Settings_Fields', 'init' ) );
87+
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\User_Settings_Fields', 'init' ) );
8788

8889
if ( site_supports_blocks() ) {
8990
\add_action( 'init', array( __NAMESPACE__ . '\Blocks', 'init' ) );

includes/activity/class-actor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ class Actor extends Base_Object {
4343
'@id' => 'lemmy:moderators',
4444
'@type' => '@id',
4545
),
46-
'attributionDomains' => array(
47-
'@id' => 'toot:attributionDomains',
48-
'@type' => '@id',
49-
),
5046
'alsoKnownAs' => array(
5147
'@id' => 'as:alsoKnownAs',
5248
'@type' => '@id',
@@ -55,6 +51,10 @@ class Actor extends Base_Object {
5551
'@id' => 'as:movedTo',
5652
'@type' => '@id',
5753
),
54+
'attributionDomains' => array(
55+
'@id' => 'toot:attributionDomains',
56+
'@type' => '@id',
57+
),
5858
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
5959
'discoverable' => 'toot:discoverable',
6060
'indexable' => 'toot:indexable',

includes/class-activitypub.php

Lines changed: 100 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Activitypub;
99

1010
use Exception;
11+
use Activitypub\Collection\Actors;
1112
use Activitypub\Collection\Outbox;
1213
use Activitypub\Collection\Followers;
1314
use Activitypub\Collection\Extra_Fields;
@@ -43,22 +44,17 @@ public static function init() {
4344

4445
\add_action( 'user_register', array( self::class, 'user_register' ) );
4546

46-
\add_action( 'in_plugin_update_message-' . ACTIVITYPUB_PLUGIN_BASENAME, array( self::class, 'plugin_update_message' ) );
47-
48-
if ( site_supports_blocks() ) {
49-
\add_action( 'tool_box', array( self::class, 'tool_box' ) );
50-
Embed::init();
51-
}
52-
5347
\add_filter( 'activitypub_get_actor_extra_fields', array( Extra_Fields::class, 'default_actor_extra_fields' ), 10, 2 );
5448

5549
\add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 );
5650
\add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 );
51+
\add_action( 'init', array( self::class, 'register_user_meta' ), 11 );
5752

5853
// Register several post_types.
5954
self::register_post_types();
6055

6156
self::register_oembed_providers();
57+
Embed::init();
6258
}
6359

6460
/**
@@ -97,6 +93,8 @@ public static function uninstall() {
9793
delete_option( 'activitypub_authorized_fetch' );
9894
delete_option( 'activitypub_application_user_private_key' );
9995
delete_option( 'activitypub_application_user_public_key' );
96+
delete_option( 'activitypub_blog_user_also_known_as' );
97+
delete_option( 'activitypub_blog_user_moved_to' );
10098
delete_option( 'activitypub_blog_user_private_key' );
10199
delete_option( 'activitypub_blog_user_public_key' );
102100
delete_option( 'activitypub_blog_description' );
@@ -257,29 +255,50 @@ public static function redirect_canonical( $redirect_url, $requested_url ) {
257255
* @return void
258256
*/
259257
public static function template_redirect() {
258+
global $wp_query;
259+
260260
$comment_id = get_query_var( 'c', null );
261261

262262
// Check if it seems to be a comment.
263-
if ( ! $comment_id ) {
264-
return;
265-
}
263+
if ( $comment_id ) {
264+
$comment = get_comment( $comment_id );
266265

267-
$comment = get_comment( $comment_id );
266+
// Load a 404-page if `c` is set but not valid.
267+
if ( ! $comment ) {
268+
$wp_query->set_404();
269+
return;
270+
}
268271

269-
// Load a 404-page if `c` is set but not valid.
270-
if ( ! $comment ) {
271-
global $wp_query;
272-
$wp_query->set_404();
273-
return;
274-
}
272+
// Stop if it's not an ActivityPub comment.
273+
if ( is_activitypub_request() && ! is_local_comment( $comment ) ) {
274+
return;
275+
}
275276

276-
// Stop if it's not an ActivityPub comment.
277-
if ( is_activitypub_request() && ! is_local_comment( $comment ) ) {
278-
return;
277+
wp_safe_redirect( get_comment_link( $comment ) );
278+
exit;
279279
}
280280

281-
wp_safe_redirect( get_comment_link( $comment ) );
282-
exit;
281+
$actor = get_query_var( 'actor', null );
282+
if ( $actor ) {
283+
$actor = Actors::get_by_username( $actor );
284+
if ( ! $actor || \is_wp_error( $actor ) ) {
285+
$wp_query->set_404();
286+
return;
287+
}
288+
289+
if ( is_activitypub_request() ) {
290+
return;
291+
}
292+
293+
if ( $actor->get__id() > 0 ) {
294+
$redirect_url = $actor->get_url();
295+
} else {
296+
$redirect_url = get_bloginfo( 'url' );
297+
}
298+
299+
wp_safe_redirect( $redirect_url, 301 );
300+
exit;
301+
}
283302
}
284303

285304
/**
@@ -293,6 +312,7 @@ public static function add_query_vars( $vars ) {
293312
$vars[] = 'activitypub';
294313
$vars[] = 'preview';
295314
$vars[] = 'author';
315+
$vars[] = 'actor';
296316
$vars[] = 'c';
297317
$vars[] = 'p';
298318

@@ -414,12 +434,7 @@ public static function add_rewrite_rules() {
414434
);
415435
}
416436

417-
\add_rewrite_rule(
418-
'^@([\w\-\.]+)$',
419-
'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/actors/$matches[1]',
420-
'top'
421-
);
422-
437+
\add_rewrite_rule( '^@([\w\-\.]+)\/?$', 'index.php?actor=$matches[1]', 'top' );
423438
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
424439
}
425440

@@ -431,15 +446,6 @@ public static function flush_rewrite_rules() {
431446
\flush_rewrite_rules();
432447
}
433448

434-
/**
435-
* Adds metabox on wp-admin/tools.php.
436-
*/
437-
public static function tool_box() {
438-
if ( \current_user_can( 'edit_posts' ) ) {
439-
\load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/toolbox.php' );
440-
}
441-
}
442-
443449
/**
444450
* Theme compatibility stuff.
445451
*/
@@ -462,30 +468,6 @@ public static function theme_compat() {
462468
}
463469
}
464470

465-
/**
466-
* Display plugin upgrade notice to users.
467-
*
468-
* @param array $data The plugin data.
469-
*/
470-
public static function plugin_update_message( $data ) {
471-
if ( ! isset( $data['upgrade_notice'] ) ) {
472-
return;
473-
}
474-
475-
printf(
476-
'<div class="update-message">%s</div>',
477-
wp_kses(
478-
wpautop( $data['upgrade_notice '] ),
479-
array(
480-
'p' => array(),
481-
'a' => array( 'href', 'title' ),
482-
'strong' => array(),
483-
'em' => array(),
484-
)
485-
)
486-
);
487-
}
488-
489471
/**
490472
* Register Custom Post Types.
491473
*/
@@ -753,4 +735,61 @@ public static function register_oembed_providers() {
753735
\wp_oembed_add_provider( '#https?://mastodon\.world/(@.+)/([0-9]+)#i', 'https://mastodon.world/api/oembed', true );
754736
\wp_oembed_add_provider( '#https?://mas\.to/(@.+)/([0-9]+)#i', 'https://mas.to/api/oembed', true );
755737
}
738+
739+
/**
740+
* Register user meta.
741+
*/
742+
public static function register_user_meta() {
743+
$blog_prefix = $GLOBALS['wpdb']->get_blog_prefix();
744+
745+
\register_meta(
746+
'user',
747+
$blog_prefix . 'activitypub_also_known_as',
748+
array(
749+
'type' => 'array',
750+
'description' => 'An array of URLs that the user is known by.',
751+
'single' => true,
752+
'default' => array(),
753+
'sanitize_callback' => array( Sanitize::class, 'url_list' ),
754+
)
755+
);
756+
757+
\register_meta(
758+
'user',
759+
$blog_prefix . 'activitypub_description',
760+
array(
761+
'type' => 'string',
762+
'description' => 'The user’s description.',
763+
'single' => true,
764+
'default' => '',
765+
'sanitize_callback' => function ( $value ) {
766+
return wp_kses( $value, 'user_description' );
767+
},
768+
)
769+
);
770+
771+
\register_meta(
772+
'user',
773+
$blog_prefix . 'activitypub_icon',
774+
array(
775+
'type' => 'integer',
776+
'description' => 'The attachment ID for user’s profile image.',
777+
'single' => true,
778+
'default' => 0,
779+
'sanitize_callback' => 'absint',
780+
)
781+
);
782+
783+
\register_meta(
784+
'user',
785+
$blog_prefix . 'activitypub_header_image',
786+
array(
787+
'type' => 'integer',
788+
'description' => 'The attachment ID for the user’s header image.',
789+
'single' => true,
790+
'default' => 0,
791+
'sanitize_callback' => 'absint',
792+
)
793+
);
794+
}
756795
}

includes/class-cli.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,36 @@ public function reschedule( $args ) {
199199

200200
WP_CLI::success( 'Rescheduled activity.' );
201201
}
202+
203+
/**
204+
* Move the blog to a new URL.
205+
*
206+
* ## OPTIONS
207+
*
208+
* <from>
209+
* The current URL of the blog.
210+
*
211+
* <to>
212+
* The new URL of the blog.
213+
*
214+
* ## EXAMPLES
215+
*
216+
* $ wp activitypub move https://example.com/ https://newsite.com/
217+
*
218+
* @synopsis <from> <to>
219+
*
220+
* @param array $args The arguments.
221+
*/
222+
public function move( $args ) {
223+
$from = $args[0];
224+
$to = $args[1];
225+
226+
$outbox_item_id = Move::account( $from, $to );
227+
228+
if ( is_wp_error( $outbox_item_id ) ) {
229+
WP_CLI::error( $outbox_item_id->get_error_message() );
230+
} else {
231+
WP_CLI::success( 'Moved Scheduled.' );
232+
}
233+
}
202234
}

0 commit comments

Comments
 (0)