Skip to content

Commit 944521b

Browse files
authored
Trigger Actor updates on (un)setting a post as sticky. (#1982)
1 parent a3b6ffd commit 944521b

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Trigger Actor updates on (un)setting a post as sticky.

includes/scheduler/class-actor.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static function init() {
4848
\add_action( 'update_option_activitypub_actor_mode', array( self::class, 'blog_user_update' ) );
4949

5050
\add_action( 'transition_post_status', array( self::class, 'schedule_post_activity' ), 33, 3 );
51+
52+
\add_action( 'post_stuck', array( self::class, 'sticky_post_update' ) );
53+
\add_action( 'post_unstuck', array( self::class, 'sticky_post_update' ) );
5154
}
5255

5356
/**
@@ -143,4 +146,19 @@ public static function schedule_profile_update( $user_id ) {
143146

144147
add_to_outbox( $actor, 'Update', $user_id );
145148
}
149+
150+
/**
151+
* Detect sticky posts update.
152+
*
153+
* @param int $post_id The post ID.
154+
*/
155+
public static function sticky_post_update( $post_id ) {
156+
$post = \get_post( $post_id );
157+
158+
if ( ! $post ) {
159+
return;
160+
}
161+
162+
self::schedule_profile_update( $post->post_author );
163+
}
146164
}

tests/includes/scheduler/class-test-actor.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Activitypub\Collection\Actors;
1111
use Activitypub\Collection\Extra_Fields;
12+
use Activitypub\Collection\Outbox;
1213
use Activitypub\Scheduler\Actor;
1314

1415
/**
@@ -320,4 +321,34 @@ public function test_actor_profile_update_sets_updated_attribute() {
320321
// Verify the updated attribute is set and matches the post's modified date.
321322
$this->assertEqualsWithDelta( strtotime( $post->post_modified ), strtotime( $activity['updated'] ), 2, 'Updated attribute does not match post modified date.' );
322323
}
324+
325+
/**
326+
* Test that sticky posts are detected.
327+
*
328+
* @covers ::sticky_post_update
329+
*/
330+
public function test_sticky_post_update() {
331+
$user_id = self::factory()->user->create( array( 'role' => 'author' ) );
332+
333+
$last_item = $this->get_latest_outbox_item();
334+
335+
$this->assertNull( $last_item );
336+
337+
$post_id = self::factory()->post->create( array( 'post_author' => $user_id ) );
338+
\stick_post( $post_id );
339+
340+
$last_item_stick = $this->get_latest_outbox_item();
341+
342+
$this->assertNotNull( $last_item_stick );
343+
344+
\unstick_post( $post_id );
345+
346+
$last_item_unstick = $this->get_latest_outbox_item();
347+
348+
$this->assertNotEquals( $last_item_stick->ID, $last_item_unstick->ID );
349+
$this->assertEquals( $last_item_stick->post_author, $last_item_unstick->post_author );
350+
351+
\wp_delete_post( $post_id );
352+
\wp_delete_user( $user_id );
353+
}
323354
}

0 commit comments

Comments
 (0)