Skip to content

Commit ad5788b

Browse files
authored
Changed: Moved password check to is_post_disabled function. (#1246)
* move password check to `is_post_disabled` check fix #1244 * add changelog * added tests * fix phpcs
1 parent fad2f32 commit ad5788b

File tree

5 files changed

+93
-10
lines changed

5 files changed

+93
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12-
* Improved content negotiation and AUTHORIZED_FETCH support for third-party plugins
12+
* Improved content negotiation and AUTHORIZED_FETCH support for third-party plugins.
13+
* Moved password check to `is_post_disabled` function.
1314

1415
### Fixed
1516

includes/functions.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,21 @@ function is_activitypub_request() {
379379
* @return boolean True if the post is disabled, false otherwise.
380380
*/
381381
function is_post_disabled( $post ) {
382-
$post = \get_post( $post );
383-
$disabled = false;
382+
$post = \get_post( $post );
383+
$disabled = false;
384+
385+
if ( ! $post ) {
386+
return true;
387+
}
388+
384389
$visibility = \get_post_meta( $post->ID, 'activitypub_content_visibility', true );
385390

386391
if (
387392
ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL === $visibility ||
388-
! \post_type_supports( $post->post_type, 'activitypub' )
393+
ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE === $visibility ||
394+
! \post_type_supports( $post->post_type, 'activitypub' ) ||
395+
'private' === $post->post_status ||
396+
! empty( $post->post_password )
389397
) {
390398
$disabled = true;
391399
}

includes/scheduler/class-post.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public static function schedule_post_activity( $new_status, $old_status, $post )
7878
return;
7979
}
8080

81-
// Do not send activities if post is password protected.
82-
if ( \post_password_required( $post ) ) {
83-
return;
84-
}
85-
8681
switch ( $new_status ) {
8782
case 'publish':
8883
$type = ( 'publish' === $old_status ) ? 'Update' : 'Create';

readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ For reasons of data protection, it is not possible to see the followers of other
135135

136136
* Added: Outbox queue
137137
* Changed: Rewrite the current dispatcher system, to use the Outbox instead of a Scheduler.
138-
* Changed: Improved content negotiation and AUTHORIZED_FETCH support for third-party plugins
138+
* Changed: Improved content negotiation and AUTHORIZED_FETCH support for third-party plugins.
139+
* Changed: Moved password check to `is_post_disabled` function.
139140
* Fixed: Handle deletes from remote servers that leave behind an accessible Tombstone object.
140141
* Fixed: No longer parses tags for post types that don't support Activitypub.
141142
* Fixed: rel attribute will now contain no more than one "me" value.

tests/includes/class-test-functions.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,82 @@ public function test_is_activity_with_invalid_input() {
299299
);
300300
}
301301
}
302+
303+
/**
304+
* Test is_post_disabled function.
305+
*
306+
* @covers ::is_post_disabled
307+
*/
308+
public function test_is_post_disabled() {
309+
// Test standard public post.
310+
$public_post_id = self::factory()->post->create();
311+
$this->assertFalse( \Activitypub\is_post_disabled( $public_post_id ) );
312+
313+
// Test local-only post.
314+
$local_post_id = self::factory()->post->create();
315+
add_post_meta( $local_post_id, 'activitypub_content_visibility', ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL );
316+
$this->assertTrue( \Activitypub\is_post_disabled( $local_post_id ) );
317+
318+
// Test private post.
319+
$private_post_id = self::factory()->post->create(
320+
array(
321+
'post_status' => 'private',
322+
)
323+
);
324+
$this->assertTrue( \Activitypub\is_post_disabled( $private_post_id ) );
325+
326+
// Test password protected post.
327+
$password_post_id = self::factory()->post->create(
328+
array(
329+
'post_password' => 'test123',
330+
)
331+
);
332+
$this->assertTrue( \Activitypub\is_post_disabled( $password_post_id ) );
333+
334+
// Test unsupported post type.
335+
register_post_type( 'unsupported', array() );
336+
$unsupported_post_id = self::factory()->post->create(
337+
array(
338+
'post_type' => 'unsupported',
339+
)
340+
);
341+
$this->assertTrue( \Activitypub\is_post_disabled( $unsupported_post_id ) );
342+
unregister_post_type( 'unsupported' );
343+
344+
// Test with filter.
345+
add_filter( 'activitypub_is_post_disabled', '__return_true' );
346+
$this->assertTrue( \Activitypub\is_post_disabled( $public_post_id ) );
347+
remove_filter( 'activitypub_is_post_disabled', '__return_true' );
348+
349+
// Clean up.
350+
wp_delete_post( $public_post_id, true );
351+
wp_delete_post( $local_post_id, true );
352+
wp_delete_post( $private_post_id, true );
353+
wp_delete_post( $password_post_id, true );
354+
}
355+
356+
/**
357+
* Test is_post_disabled with private visibility.
358+
*
359+
* @covers ::is_post_disabled
360+
*/
361+
public function test_is_post_disabled_private_visibility() {
362+
$visible_private_post_id = self::factory()->post->create();
363+
364+
add_post_meta( $visible_private_post_id, 'activitypub_content_visibility', ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE );
365+
$this->assertFalse( \Activitypub\is_post_disabled( $visible_private_post_id ) );
366+
367+
wp_delete_post( $visible_private_post_id, true );
368+
}
369+
370+
/**
371+
* Test is_post_disabled with invalid post.
372+
*
373+
* @covers ::is_post_disabled
374+
*/
375+
public function test_is_post_disabled_invalid_post() {
376+
$this->assertTrue( \Activitypub\is_post_disabled( 0 ) );
377+
$this->assertTrue( \Activitypub\is_post_disabled( null ) );
378+
$this->assertTrue( \Activitypub\is_post_disabled( 999999 ) );
379+
}
302380
}

0 commit comments

Comments
 (0)