mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-29 15:44:27 +00:00
Posts: Add hooks for post sticky status changes.
This adds a new `post_stuck` action that fires when a post is made sticky and a `post_unstuck` action that fires when the sticky flag is removed again. Props ojrask. Fixes #35600. git-svn-id: https://develop.svn.wordpress.org/trunk@37857 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1181,6 +1181,33 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
$this->assertEquals( 'Updated', $saved_post->post_content );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that hooks are fired when post gets stuck and unstuck.
|
||||
*
|
||||
* @ticket 35600
|
||||
*/
|
||||
function test_hooks_fire_when_post_gets_stuck_and_unstuck() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
|
||||
$this->assertFalse( is_sticky( $post_id ) );
|
||||
|
||||
add_action( 'post_stuck', array( $a1, 'action' ) );
|
||||
add_action( 'post_unstuck', array( $a2, 'action' ) );
|
||||
|
||||
stick_post( $post_id );
|
||||
$this->assertTrue( is_sticky( $post_id ) );
|
||||
unstick_post( $post_id );
|
||||
$this->assertFalse( is_sticky( $post_id ) );
|
||||
|
||||
remove_action( 'post_stuck', array( $a1, 'action' ) );
|
||||
remove_action( 'post_unstuck', array( $a2, 'action' ) );
|
||||
|
||||
$this->assertEquals( 1, $a1->get_call_count() );
|
||||
$this->assertEquals( 1, $a2->get_call_count() );
|
||||
}
|
||||
|
||||
/**
|
||||
* If a post is updated without providing a post_name param,
|
||||
* a new slug should not be generated.
|
||||
|
||||
Reference in New Issue
Block a user