Skip to content

Commit c05d55c

Browse files
authored
Register post types and meta on 'init' action (#2232)
1 parent bbacdd7 commit c05d55c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Fixed an issue where post metadata in the block editor was missing or failed to update.

includes/class-post-types.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class Post_Types {
2222
* Initialize the class, registering all custom post types and post meta.
2323
*/
2424
public static function init() {
25-
self::register_remote_actors_post_type();
26-
self::register_inbox_post_type();
27-
self::register_outbox_post_type();
28-
self::register_extra_fields_post_types();
29-
self::register_activitypub_post_meta();
25+
\add_action( 'init', array( self::class, 'register_remote_actors_post_type' ), 11 );
26+
\add_action( 'init', array( self::class, 'register_inbox_post_type' ), 11 );
27+
\add_action( 'init', array( self::class, 'register_outbox_post_type' ), 11 );
28+
\add_action( 'init', array( self::class, 'register_extra_fields_post_types' ), 11 );
29+
\add_action( 'init', array( self::class, 'register_activitypub_post_meta' ), 11 );
3030

3131
\add_action( 'rest_api_init', array( self::class, 'register_ap_actor_rest_field' ) );
3232

@@ -529,20 +529,20 @@ public static function default_post_meta_data( $meta_value, $object_id, $meta_ke
529529
}
530530

531531
// If meta value is already explicitly set, respect the author's choice.
532-
if ( null !== $meta_value ) {
532+
if ( $meta_value ) {
533533
return $meta_value;
534534
}
535535

536536
// If the post is federated, return the default visibility.
537537
if ( 'federated' === \get_post_meta( $object_id, 'activitypub_status', true ) ) {
538-
return null;
538+
return $meta_value;
539539
}
540540

541541
// If the post is not federated and older than a month, return local visibility.
542542
if ( \get_the_date( 'U', $object_id ) < \strtotime( '-1 month' ) ) {
543543
return ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL;
544544
}
545545

546-
return null;
546+
return $meta_value;
547547
}
548548
}

tests/includes/class-test-post-types.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public function test_get_post_metadata() {
8585

8686
// Test 5: When meta value is already set (not null), should respect author's explicit choice.
8787
\update_post_meta( $post_id, 'activitypub_status', 'pending' ); // Ensure not federated.
88-
$result = Post_Types::default_post_meta_data( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, $post_id, 'activitypub_content_visibility' );
89-
$this->assertEquals( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, $result, 'Should respect explicitly set public visibility even for old unfederated posts.' );
88+
$result = Post_Types::default_post_meta_data( ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC, $post_id, 'activitypub_content_visibility' );
89+
$this->assertEquals( ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC, $result, 'Should respect explicitly set public visibility even for old unfederated posts.' );
9090

9191
// Test 6: Only apply local visibility when meta value is null (no explicit setting).
9292
$result = Post_Types::default_post_meta_data( null, $post_id, 'activitypub_content_visibility' );

0 commit comments

Comments
 (0)