Make WordPress Core


Ignore:
Timestamp:
06/23/2016 03:51:03 PM (10 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r36874 r37857  
    11831183
    11841184        /**
     1185         * Test that hooks are fired when post gets stuck and unstuck.
     1186         *
     1187         * @ticket 35600
     1188         */
     1189        function test_hooks_fire_when_post_gets_stuck_and_unstuck() {
     1190                $post_id = self::factory()->post->create();
     1191                $a1 = new MockAction();
     1192                $a2 = new MockAction();
     1193
     1194                $this->assertFalse( is_sticky( $post_id ) );
     1195
     1196                add_action( 'post_stuck', array( $a1, 'action' ) );
     1197                add_action( 'post_unstuck', array( $a2, 'action' ) );
     1198
     1199                stick_post( $post_id );
     1200                $this->assertTrue( is_sticky( $post_id ) );
     1201                unstick_post( $post_id );
     1202                $this->assertFalse( is_sticky( $post_id ) );
     1203
     1204                remove_action( 'post_stuck', array( $a1, 'action' ) );
     1205                remove_action( 'post_unstuck', array( $a2, 'action' ) );
     1206
     1207                $this->assertEquals( 1, $a1->get_call_count() );
     1208                $this->assertEquals( 1, $a2->get_call_count() );
     1209        }
     1210
     1211        /**
    11851212         * If a post is updated without providing a post_name param,
    11861213         * a new slug should not be generated.
Note: See TracChangeset for help on using the changeset viewer.