Skip to content

Commit 6df4adb

Browse files
authored
Merge branch 'trunk' into add/emoji-support
2 parents d1565c8 + 2cbdfb8 commit 6df4adb

17 files changed

+346
-109
lines changed

.wp-env.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"WP_SITEURL": "http://example.org",
99
"WP_HOME": "http://example.org"
1010
},
11+
"port": 80,
1112
"mappings": {
1213
"wp-content/plugins/activitypub": ".",
1314
"wp-content/plugins/activitypub/tests": "./tests"

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
* Support for custom emoji in interaction contents and actor names
1313
* Added a filter to make custom comment types manageable in WP.com Calypso
1414

15+
### Changed
16+
17+
* Hide ActivityPub post meta keys from the custom Fields UI
18+
1519
### Fixed
1620

1721
* Undefined array key warnings in various places
22+
* Fetching replies from the same instance for Enable Mastodon Apps
23+
* Image captions not being included in the ActivityPub representation when the image is attached to the post
1824

1925
## [4.6.0] - 2024-12-20
2026

includes/class-activitypub.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public static function get_avatar_url( $comment ) {
339339
public static function trash_post( $post_id ) {
340340
\add_post_meta(
341341
$post_id,
342-
'activitypub_canonical_url',
342+
'_activitypub_canonical_url',
343343
\get_permalink( $post_id ),
344344
true
345345
);
@@ -351,7 +351,7 @@ public static function trash_post( $post_id ) {
351351
* @param string $post_id The Post ID.
352352
*/
353353
public static function untrash_post( $post_id ) {
354-
\delete_post_meta( $post_id, 'activitypub_canonical_url' );
354+
\delete_post_meta( $post_id, '_activitypub_canonical_url' );
355355
}
356356

357357
/**
@@ -482,7 +482,7 @@ private static function register_post_types() {
482482

483483
\register_post_meta(
484484
Followers::POST_TYPE,
485-
'activitypub_inbox',
485+
'_activitypub_inbox',
486486
array(
487487
'type' => 'string',
488488
'single' => true,
@@ -492,7 +492,7 @@ private static function register_post_types() {
492492

493493
\register_post_meta(
494494
Followers::POST_TYPE,
495-
'activitypub_errors',
495+
'_activitypub_errors',
496496
array(
497497
'type' => 'string',
498498
'single' => false,
@@ -508,7 +508,7 @@ private static function register_post_types() {
508508

509509
\register_post_meta(
510510
Followers::POST_TYPE,
511-
'activitypub_user_id',
511+
'_activitypub_user_id',
512512
array(
513513
'type' => 'string',
514514
'single' => false,
@@ -520,7 +520,7 @@ private static function register_post_types() {
520520

521521
\register_post_meta(
522522
Followers::POST_TYPE,
523-
'activitypub_actor_json',
523+
'_activitypub_actor_json',
524524
array(
525525
'type' => 'string',
526526
'single' => true,

includes/class-migration.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ public static function maybe_migrate() {
161161
if ( \version_compare( $version_from_db, '4.5.0', '<' ) ) {
162162
\wp_schedule_single_event( \time() + MINUTE_IN_SECONDS, 'activitypub_update_comment_counts' );
163163
}
164+
if ( \version_compare( $version_from_db, '4.6.0', '<' ) ) {
165+
self::migrate_to_4_6_0();
166+
}
164167

165168
/**
166169
* Fires when the system has to be migrated.
@@ -387,6 +390,26 @@ public static function migrate_to_4_1_0() {
387390
);
388391
}
389392

393+
/**
394+
* Updates post meta keys to be prefixed with an underscore.
395+
*/
396+
public static function migrate_to_4_6_0() {
397+
global $wpdb;
398+
399+
$meta_keys = array(
400+
'activitypub_actor_json',
401+
'activitypub_canonical_url',
402+
'activitypub_errors',
403+
'activitypub_inbox',
404+
'activitypub_user_id',
405+
);
406+
407+
foreach ( $meta_keys as $meta_key ) {
408+
// phpcs:ignore WordPress.DB
409+
$wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_' . $meta_key ), array( 'meta_key' => $meta_key ) );
410+
}
411+
}
412+
390413
/**
391414
* Update comment counts for posts in batches.
392415
*

includes/collection/class-actors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static function get_by_username( $username ) {
100100
'meta_query' => array(
101101
'relation' => 'OR',
102102
array(
103-
'key' => 'activitypub_user_identifier',
103+
'key' => '_activitypub_user_identifier',
104104
'value' => $username,
105105
'compare' => 'LIKE',
106106
),

includes/collection/class-followers.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public static function add_follower( $user_id, $actor ) {
5252
return $id;
5353
}
5454

55-
$post_meta = get_post_meta( $id, 'activitypub_user_id', false );
55+
$post_meta = get_post_meta( $id, '_activitypub_user_id', false );
5656

5757
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
5858
if ( is_array( $post_meta ) && ! in_array( $user_id, $post_meta ) ) {
59-
add_post_meta( $id, 'activitypub_user_id', $user_id );
59+
add_post_meta( $id, '_activitypub_user_id', $user_id );
6060
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
6161
}
6262

@@ -89,7 +89,7 @@ public static function remove_follower( $user_id, $actor ) {
8989
*/
9090
do_action( 'activitypub_followers_pre_remove_follower', $follower, $user_id, $actor );
9191

92-
return delete_post_meta( $follower->get__id(), 'activitypub_user_id', $user_id );
92+
return delete_post_meta( $follower->get__id(), '_activitypub_user_id', $user_id );
9393
}
9494

9595
/**
@@ -106,7 +106,7 @@ public static function get_follower( $user_id, $actor ) {
106106
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
107107
$post_id = $wpdb->get_var(
108108
$wpdb->prepare(
109-
"SELECT DISTINCT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE p.post_type = %s AND pm.meta_key = 'activitypub_user_id' AND pm.meta_value = %d AND p.guid = %s",
109+
"SELECT DISTINCT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE p.post_type = %s AND pm.meta_key = '_activitypub_user_id' AND pm.meta_value = %d AND p.guid = %s",
110110
array(
111111
esc_sql( self::POST_TYPE ),
112112
esc_sql( $user_id ),
@@ -188,7 +188,7 @@ public static function get_followers_with_count( $user_id, $number = -1, $page =
188188
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
189189
'meta_query' => array(
190190
array(
191-
'key' => 'activitypub_user_id',
191+
'key' => '_activitypub_user_id',
192192
'value' => $user_id,
193193
),
194194
),
@@ -219,11 +219,11 @@ public static function get_all_followers() {
219219
'meta_query' => array(
220220
'relation' => 'AND',
221221
array(
222-
'key' => 'activitypub_inbox',
222+
'key' => '_activitypub_inbox',
223223
'compare' => 'EXISTS',
224224
),
225225
array(
226-
'key' => 'activitypub_actor_json',
226+
'key' => '_activitypub_actor_json',
227227
'compare' => 'EXISTS',
228228
),
229229
),
@@ -247,15 +247,15 @@ public static function count_followers( $user_id ) {
247247
'meta_query' => array(
248248
'relation' => 'AND',
249249
array(
250-
'key' => 'activitypub_user_id',
250+
'key' => '_activitypub_user_id',
251251
'value' => $user_id,
252252
),
253253
array(
254-
'key' => 'activitypub_inbox',
254+
'key' => '_activitypub_inbox',
255255
'compare' => 'EXISTS',
256256
),
257257
array(
258-
'key' => 'activitypub_actor_json',
258+
'key' => '_activitypub_actor_json',
259259
'compare' => 'EXISTS',
260260
),
261261
),
@@ -290,15 +290,15 @@ public static function get_inboxes( $user_id ) {
290290
'meta_query' => array(
291291
'relation' => 'AND',
292292
array(
293-
'key' => 'activitypub_inbox',
293+
'key' => '_activitypub_inbox',
294294
'compare' => 'EXISTS',
295295
),
296296
array(
297-
'key' => 'activitypub_user_id',
297+
'key' => '_activitypub_user_id',
298298
'value' => $user_id,
299299
),
300300
array(
301-
'key' => 'activitypub_inbox',
301+
'key' => '_activitypub_inbox',
302302
'value' => '',
303303
'compare' => '!=',
304304
),
@@ -318,7 +318,7 @@ public static function get_inboxes( $user_id ) {
318318
$wpdb->prepare(
319319
"SELECT DISTINCT meta_value FROM {$wpdb->postmeta}
320320
WHERE post_id IN (" . implode( ', ', array_fill( 0, count( $posts ), '%d' ) ) . ")
321-
AND meta_key = 'activitypub_inbox'
321+
AND meta_key = '_activitypub_inbox'
322322
AND meta_value IS NOT NULL",
323323
$posts
324324
)
@@ -378,24 +378,24 @@ public static function get_faulty_followers( $number = 20 ) {
378378
'meta_query' => array(
379379
'relation' => 'OR',
380380
array(
381-
'key' => 'activitypub_errors',
381+
'key' => '_activitypub_errors',
382382
'compare' => 'EXISTS',
383383
),
384384
array(
385-
'key' => 'activitypub_inbox',
385+
'key' => '_activitypub_inbox',
386386
'compare' => 'NOT EXISTS',
387387
),
388388
array(
389-
'key' => 'activitypub_actor_json',
389+
'key' => '_activitypub_actor_json',
390390
'compare' => 'NOT EXISTS',
391391
),
392392
array(
393-
'key' => 'activitypub_inbox',
393+
'key' => '_activitypub_inbox',
394394
'value' => '',
395395
'compare' => '=',
396396
),
397397
array(
398-
'key' => 'activitypub_actor_json',
398+
'key' => '_activitypub_actor_json',
399399
'value' => '',
400400
'compare' => '=',
401401
),
@@ -437,7 +437,7 @@ public static function add_error( $post_id, $error ) {
437437

438438
return add_post_meta(
439439
$post_id,
440-
'activitypub_errors',
440+
'_activitypub_errors',
441441
$error_message
442442
);
443443
}

includes/constants.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@
3434
'ACTIVITYPUB_MASTODON_HTML_SANITIZER',
3535
array(
3636
'p' => array(),
37-
'span' => array( 'class' ),
37+
'span' => array( 'class' => true ),
3838
'br' => array(),
39-
'a' => array( 'href', 'rel', 'class' ),
39+
'a' => array(
40+
'href' => true,
41+
'rel' => true,
42+
'class' => true,
43+
),
4044
'del' => array(),
4145
'pre' => array(),
4246
'code' => array(),
@@ -46,8 +50,11 @@
4650
'i' => array(),
4751
'u' => array(),
4852
'ul' => array(),
49-
'ol' => array( 'start', 'reversed' ),
50-
'li' => array( 'value' ),
53+
'ol' => array(
54+
'start' => true,
55+
'reversed' => true,
56+
),
57+
'li' => array( 'value' => true ),
5158
'blockquote' => array(),
5259
'h1' => array(),
5360
'h2' => array(),

includes/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ function is_json( $data ) {
620620
}
621621

622622
/**
623-
* Check whther a blog is public based on the `blog_public` option.
623+
* Check whether a blog is public based on the `blog_public` option.
624624
*
625625
* @return bool True if public, false if not
626626
*/
@@ -1071,7 +1071,7 @@ function ( $enclosure ) {
10711071
*
10721072
* @param int|\WP_Comment $comment Comment ID or comment object.
10731073
*
1074-
* @return \WP_Comment[] Array of ancestor comments or empty array if there are none.
1074+
* @return int[] Array of ancestor IDs.
10751075
*/
10761076
function get_comment_ancestors( $comment ) {
10771077
$comment = \get_comment( $comment );

includes/model/class-follower.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Follower extends Actor {
3636
* @return mixed
3737
*/
3838
public function get_errors() {
39-
return get_post_meta( $this->_id, 'activitypub_errors', false );
39+
return get_post_meta( $this->_id, '_activitypub_errors', false );
4040
}
4141

4242
/**
@@ -72,7 +72,7 @@ public function get_url() {
7272
* Reset (delete) all errors.
7373
*/
7474
public function reset_errors() {
75-
delete_post_meta( $this->_id, 'activitypub_errors' );
75+
delete_post_meta( $this->_id, '_activitypub_errors' );
7676
}
7777

7878
/**
@@ -216,9 +216,9 @@ public function delete() {
216216
* Update the post meta.
217217
*/
218218
protected function get_post_meta_input() {
219-
$meta_input = array();
220-
$meta_input['activitypub_inbox'] = $this->get_shared_inbox();
221-
$meta_input['activitypub_actor_json'] = $this->to_json();
219+
$meta_input = array();
220+
$meta_input['_activitypub_inbox'] = $this->get_shared_inbox();
221+
$meta_input['_activitypub_actor_json'] = $this->to_json();
222222

223223
return $meta_input;
224224
}
@@ -334,7 +334,7 @@ public function get_shared_inbox() {
334334
* @return \Activitypub\Activity\Base_Object|WP_Error
335335
*/
336336
public static function init_from_cpt( $post ) {
337-
$actor_json = get_post_meta( $post->ID, 'activitypub_actor_json', true );
337+
$actor_json = get_post_meta( $post->ID, '_activitypub_actor_json', true );
338338
$object = self::init_from_json( $actor_json );
339339
$object->set__id( $post->ID );
340340
$object->set_id( $post->guid );

includes/transformer/class-post.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function get_url() {
152152

153153
switch ( \get_post_status( $post ) ) {
154154
case 'trash':
155-
$permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
155+
$permalink = \get_post_meta( $post->ID, '_activitypub_canonical_url', true );
156156
break;
157157
case 'draft':
158158
// Get_sample_permalink is in wp-admin, not always loaded.
@@ -454,10 +454,21 @@ protected function get_media_from_blocks( $blocks, $media ) {
454454
$alt = $match[2];
455455
}
456456

457-
$media['image'][] = array(
458-
'id' => $block['attrs']['id'],
459-
'alt' => $alt,
460-
);
457+
$found = false;
458+
foreach ( $media['image'] as $i => $image ) {
459+
if ( $image['id'] === $block['attrs']['id'] ) {
460+
$media['image'][ $i ]['alt'] = $alt;
461+
$found = true;
462+
break;
463+
}
464+
}
465+
466+
if ( ! $found ) {
467+
$media['image'][] = array(
468+
'id' => $block['attrs']['id'],
469+
'alt' => $alt,
470+
);
471+
}
461472
}
462473
break;
463474
case 'core/audio':

0 commit comments

Comments
 (0)