Ticket #35600: 35600.4.diff
File 35600.4.diff, 2.1 KB (added by , 5 years ago) |
---|
-
src/wp-includes/post.php
2169 2169 if ( ! in_array($post_id, $stickies) ) 2170 2170 $stickies[] = $post_id; 2171 2171 2172 update_option('sticky_posts', $stickies); 2172 $updated = update_option( 'sticky_posts', $stickies ); 2173 2174 if ( $updated ) { 2175 /** 2176 * Fires once a post has been added to the sticky list. 2177 * 2178 * @since 4.6.0 2179 * 2180 * @param int $post_id ID of the post that was stuck. 2181 */ 2182 do_action( 'post_stuck', $post_id ); 2183 } 2173 2184 } 2174 2185 2175 2186 /** … … 2196 2207 2197 2208 array_splice($stickies, $offset, 1); 2198 2209 2199 update_option('sticky_posts', $stickies); 2210 $updated = update_option( 'sticky_posts', $stickies ); 2211 2212 if ( $updated ) { 2213 /** 2214 * Fires once a post has been removed from the sticky list. 2215 * 2216 * @since 4.6.0 2217 * 2218 * @param int $post_id ID of the post that was unstuck. 2219 */ 2220 do_action( 'post_unstuck', $post_id ); 2221 } 2200 2222 } 2201 2223 2202 2224 /** -
tests/phpunit/tests/post.php
1182 1182 } 1183 1183 1184 1184 /** 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 /** 1185 1212 * If a post is updated without providing a post_name param, 1186 1213 * a new slug should not be generated. 1187 1214 *