@@ -328,7 +328,7 @@ public function test_get_post_metadata() {
328
328
$ post_id = self ::factory ()->post ->create (
329
329
array (
330
330
'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 .
332
332
)
333
333
);
334
334
@@ -341,21 +341,30 @@ public function test_get_post_metadata() {
341
341
$ result = Activitypub::default_post_metadata ( 'original_value ' , $ post_id , 'activitypub_content_visibility ' );
342
342
$ this ->assertEquals ( 'original_value ' , $ result , 'Should return original value for federated posts. ' );
343
343
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.
345
345
\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 ' );
347
347
$ this ->assertEquals ( ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL , $ result , 'Should return local visibility for old non-federated posts. ' );
348
348
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.
350
350
$ recent_post_id = self ::factory ()->post ->create (
351
351
array (
352
352
'post_author ' => 1 ,
353
353
'post_date ' => gmdate ( 'Y-m-d H:i:s ' , strtotime ( '-2 weeks ' ) ), // Recent post.
354
354
)
355
355
);
356
356
\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. ' );
359
368
360
369
// Clean up.
361
370
\wp_delete_post ( $ post_id , true );
0 commit comments