Skip to content

Commit

Permalink
Merge branch 'trunk' into add/oembed-reply-block
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwiebe committed Mar 3, 2025
2 parents 1a964e4 + f61964c commit 35e7a3f
Show file tree
Hide file tree
Showing 30 changed files with 1,261 additions and 435 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

* Updates to certain user meta fields did not trigger an Update activity.

## [5.4.0] - 2025-03-03

### Added

* Upgrade script to fix Follower json representations with unescaped backslashes.
* Centralized place for sanitization functions.

### Changed

* Bumped minimum required WordPress version to 6.4.
* 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.
* Use webfinger as author email for comments from the Fediverse.
* Remove the special handling of comments from Enable Mastodon Apps.

### Fixed

* Do not redirect `/@username` URLs to the API any more, to improve `AUTHORIZED_FETCH` handling.

## [5.3.2] - 2025-02-27

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

* initial

[Unreleased]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.2...trunk
[Unreleased]: https://github.com/Automattic/wordpress-activitypub/compare/5.4.0...trunk
<!-- Add new release below and update "Unreleased" link -->
[5.4.0]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.2...5.4.0
[5.3.2]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.1...5.3.2
[5.3.1]: https://github.com/Automattic/wordpress-activitypub/compare/5.3.0...5.3.1
[5.3.0]: https://github.com/Automattic/wordpress-activitypub/compare/5.2.0...5.3.0
Expand Down
5 changes: 3 additions & 2 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: ActivityPub
* Plugin URI: https://github.com/Automattic/wordpress-activitypub
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
* Version: 5.3.2
* Version: 5.4.0
* Author: Matthias Pfefferle & Automattic
* Author URI: https://automattic.com/
* License: MIT
Expand All @@ -19,7 +19,7 @@

use WP_CLI;

\define( 'ACTIVITYPUB_PLUGIN_VERSION', '5.3.2' );
\define( 'ACTIVITYPUB_PLUGIN_VERSION', '5.4.0' );

// Plugin related constants.
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Expand Down Expand Up @@ -84,6 +84,7 @@ function plugin_init() {
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Settings', 'init' ) );
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Settings_Fields', 'init' ) );
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Blog_Settings_Fields', 'init' ) );
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\User_Settings_Fields', 'init' ) );

if ( site_supports_blocks() ) {
\add_action( 'init', array( __NAMESPACE__ . '\Blocks', 'init' ) );
Expand Down
8 changes: 4 additions & 4 deletions includes/activity/class-actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class Actor extends Base_Object {
'@id' => 'lemmy:moderators',
'@type' => '@id',
),
'attributionDomains' => array(
'@id' => 'toot:attributionDomains',
'@type' => '@id',
),
'alsoKnownAs' => array(
'@id' => 'as:alsoKnownAs',
'@type' => '@id',
Expand All @@ -55,6 +51,10 @@ class Actor extends Base_Object {
'@id' => 'as:movedTo',
'@type' => '@id',
),
'attributionDomains' => array(
'@id' => 'toot:attributionDomains',
'@type' => '@id',
),
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
'discoverable' => 'toot:discoverable',
'indexable' => 'toot:indexable',
Expand Down
161 changes: 100 additions & 61 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Activitypub;

use Exception;
use Activitypub\Collection\Actors;
use Activitypub\Collection\Outbox;
use Activitypub\Collection\Followers;
use Activitypub\Collection\Extra_Fields;
Expand Down Expand Up @@ -43,22 +44,17 @@ public static function init() {

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

\add_action( 'in_plugin_update_message-' . ACTIVITYPUB_PLUGIN_BASENAME, array( self::class, 'plugin_update_message' ) );

if ( site_supports_blocks() ) {
\add_action( 'tool_box', array( self::class, 'tool_box' ) );
Embed::init();
}

\add_filter( 'activitypub_get_actor_extra_fields', array( Extra_Fields::class, 'default_actor_extra_fields' ), 10, 2 );

\add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 );
\add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 );
\add_action( 'init', array( self::class, 'register_user_meta' ), 11 );

// Register several post_types.
self::register_post_types();

self::register_oembed_providers();
Embed::init();
}

/**
Expand Down Expand Up @@ -97,6 +93,8 @@ public static function uninstall() {
delete_option( 'activitypub_authorized_fetch' );
delete_option( 'activitypub_application_user_private_key' );
delete_option( 'activitypub_application_user_public_key' );
delete_option( 'activitypub_blog_user_also_known_as' );
delete_option( 'activitypub_blog_user_moved_to' );
delete_option( 'activitypub_blog_user_private_key' );
delete_option( 'activitypub_blog_user_public_key' );
delete_option( 'activitypub_blog_description' );
Expand Down Expand Up @@ -257,29 +255,50 @@ public static function redirect_canonical( $redirect_url, $requested_url ) {
* @return void
*/
public static function template_redirect() {
global $wp_query;

$comment_id = get_query_var( 'c', null );

// Check if it seems to be a comment.
if ( ! $comment_id ) {
return;
}
if ( $comment_id ) {
$comment = get_comment( $comment_id );

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

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

// Stop if it's not an ActivityPub comment.
if ( is_activitypub_request() && ! is_local_comment( $comment ) ) {
return;
wp_safe_redirect( get_comment_link( $comment ) );
exit;
}

wp_safe_redirect( get_comment_link( $comment ) );
exit;
$actor = get_query_var( 'actor', null );
if ( $actor ) {
$actor = Actors::get_by_username( $actor );
if ( ! $actor || \is_wp_error( $actor ) ) {
$wp_query->set_404();
return;
}

if ( is_activitypub_request() ) {
return;
}

if ( $actor->get__id() > 0 ) {
$redirect_url = $actor->get_url();
} else {
$redirect_url = get_bloginfo( 'url' );
}

wp_safe_redirect( $redirect_url, 301 );
exit;
}
}

/**
Expand All @@ -293,6 +312,7 @@ public static function add_query_vars( $vars ) {
$vars[] = 'activitypub';
$vars[] = 'preview';
$vars[] = 'author';
$vars[] = 'actor';
$vars[] = 'c';
$vars[] = 'p';

Expand Down Expand Up @@ -414,12 +434,7 @@ public static function add_rewrite_rules() {
);
}

\add_rewrite_rule(
'^@([\w\-\.]+)$',
'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/actors/$matches[1]',
'top'
);

\add_rewrite_rule( '^@([\w\-\.]+)\/?$', 'index.php?actor=$matches[1]', 'top' );
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
}

Expand All @@ -431,15 +446,6 @@ public static function flush_rewrite_rules() {
\flush_rewrite_rules();
}

/**
* Adds metabox on wp-admin/tools.php.
*/
public static function tool_box() {
if ( \current_user_can( 'edit_posts' ) ) {
\load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/toolbox.php' );
}
}

/**
* Theme compatibility stuff.
*/
Expand All @@ -462,30 +468,6 @@ public static function theme_compat() {
}
}

/**
* Display plugin upgrade notice to users.
*
* @param array $data The plugin data.
*/
public static function plugin_update_message( $data ) {
if ( ! isset( $data['upgrade_notice'] ) ) {
return;
}

printf(
'<div class="update-message">%s</div>',
wp_kses(
wpautop( $data['upgrade_notice '] ),
array(
'p' => array(),
'a' => array( 'href', 'title' ),
'strong' => array(),
'em' => array(),
)
)
);
}

/**
* Register Custom Post Types.
*/
Expand Down Expand Up @@ -753,4 +735,61 @@ public static function register_oembed_providers() {
\wp_oembed_add_provider( '#https?://mastodon\.world/(@.+)/([0-9]+)#i', 'https://mastodon.world/api/oembed', true );
\wp_oembed_add_provider( '#https?://mas\.to/(@.+)/([0-9]+)#i', 'https://mas.to/api/oembed', true );
}

/**
* Register user meta.
*/
public static function register_user_meta() {
$blog_prefix = $GLOBALS['wpdb']->get_blog_prefix();

\register_meta(
'user',
$blog_prefix . 'activitypub_also_known_as',
array(
'type' => 'array',
'description' => 'An array of URLs that the user is known by.',
'single' => true,
'default' => array(),
'sanitize_callback' => array( Sanitize::class, 'url_list' ),
)
);

\register_meta(
'user',
$blog_prefix . 'activitypub_description',
array(
'type' => 'string',
'description' => 'The user’s description.',
'single' => true,
'default' => '',
'sanitize_callback' => function ( $value ) {
return wp_kses( $value, 'user_description' );
},
)
);

\register_meta(
'user',
$blog_prefix . 'activitypub_icon',
array(
'type' => 'integer',
'description' => 'The attachment ID for user’s profile image.',
'single' => true,
'default' => 0,
'sanitize_callback' => 'absint',
)
);

\register_meta(
'user',
$blog_prefix . 'activitypub_header_image',
array(
'type' => 'integer',
'description' => 'The attachment ID for the user’s header image.',
'single' => true,
'default' => 0,
'sanitize_callback' => 'absint',
)
);
}
}
32 changes: 32 additions & 0 deletions includes/class-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,36 @@ public function reschedule( $args ) {

WP_CLI::success( 'Rescheduled activity.' );
}

/**
* Move the blog to a new URL.
*
* ## OPTIONS
*
* <from>
* The current URL of the blog.
*
* <to>
* The new URL of the blog.
*
* ## EXAMPLES
*
* $ wp activitypub move https://example.com/ https://newsite.com/
*
* @synopsis <from> <to>
*
* @param array $args The arguments.
*/
public function move( $args ) {
$from = $args[0];
$to = $args[1];

$outbox_item_id = Move::account( $from, $to );

if ( is_wp_error( $outbox_item_id ) ) {
WP_CLI::error( $outbox_item_id->get_error_message() );
} else {
WP_CLI::success( 'Moved Scheduled.' );
}
}
}
Loading

0 comments on commit 35e7a3f

Please sign in to comment.