Skip to content

Commit 078f9c4

Browse files
authored
Fix content visibility override bug from PR #1900 (#2139)
1 parent b022645 commit 078f9c4

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
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+
Fix content visibility override issue preventing authors from changing visibility on older posts.

includes/class-activitypub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,11 @@ public static function default_post_metadata( $meta_value, $object_id, $meta_key
887887
return $meta_value;
888888
}
889889

890+
// If meta value is already explicitly set, respect the author's choice.
891+
if ( null !== $meta_value ) {
892+
return $meta_value;
893+
}
894+
890895
// If the post is federated, return the default visibility.
891896
if ( 'federated' === \get_post_meta( $object_id, 'activitypub_status', true ) ) {
892897
return $meta_value;

tests/includes/class-test-activitypub.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public function test_get_post_metadata() {
328328
$post_id = self::factory()->post->create(
329329
array(
330330
'post_author' => 1,
331-
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 months' ) ), // Post older than a year.
331+
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 months' ) ), // Post older than a month.
332332
)
333333
);
334334

@@ -341,21 +341,30 @@ public function test_get_post_metadata() {
341341
$result = Activitypub::default_post_metadata( 'original_value', $post_id, 'activitypub_content_visibility' );
342342
$this->assertEquals( 'original_value', $result, 'Should return original value for federated posts.' );
343343

344-
// Test 3: When post is not federated and older than a year, should return local visibility.
344+
// Test 3: When post is not federated and older than a month, should return local visibility.
345345
\update_post_meta( $post_id, 'activitypub_status', 'pending' );
346-
$result = Activitypub::default_post_metadata( 'original_value', $post_id, 'activitypub_content_visibility' );
346+
$result = Activitypub::default_post_metadata( null, $post_id, 'activitypub_content_visibility' );
347347
$this->assertEquals( ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL, $result, 'Should return local visibility for old non-federated posts.' );
348348

349-
// Test 4: When post is not federated but less than a year old, should return original value.
349+
// Test 4: When post is not federated but less than a month old, should return original value.
350350
$recent_post_id = self::factory()->post->create(
351351
array(
352352
'post_author' => 1,
353353
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 weeks' ) ), // Recent post.
354354
)
355355
);
356356
\update_post_meta( $recent_post_id, 'activitypub_status', 'pending' );
357-
$result = Activitypub::default_post_metadata( 'original_value', $recent_post_id, 'activitypub_content_visibility' );
358-
$this->assertEquals( 'original_value', $result, 'Should return original value for recent non-federated posts.' );
357+
$result = Activitypub::default_post_metadata( null, $recent_post_id, 'activitypub_content_visibility' );
358+
$this->assertEquals( null, $result, 'Should return original value for recent non-federated posts.' );
359+
360+
// Test 5: When meta value is already set (not null), should respect author's explicit choice.
361+
\update_post_meta( $post_id, 'activitypub_status', 'pending' ); // Ensure not federated.
362+
$result = Activitypub::default_post_metadata( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, $post_id, 'activitypub_content_visibility' );
363+
$this->assertEquals( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, $result, 'Should respect explicitly set public visibility even for old unfederated posts.' );
364+
365+
// Test 6: Only apply local visibility when meta value is null (no explicit setting).
366+
$result = Activitypub::default_post_metadata( null, $post_id, 'activitypub_content_visibility' );
367+
$this->assertEquals( ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL, $result, 'Should return local visibility when no explicit value is set for old unfederated posts.' );
359368

360369
// Clean up.
361370
\wp_delete_post( $post_id, true );

0 commit comments

Comments
 (0)