Ticket #47777: 47777.3.diff
File 47777.3.diff, 6.2 KB (added by , 4 years ago) |
---|
-
src/wp-includes/post.php
6597 6597 * @param string|false $date Date the last post was published. False on failure. 6598 6598 * @param string $timezone Location to use for getting the post published date. 6599 6599 * See get_lastpostdate() for accepted `$timezone` values. 6600 * @param string $post_type The post type to check. 6600 6601 */ 6601 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone );6602 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone, $post_type ); 6602 6603 } 6603 6604 6604 6605 /** … … 6636 6637 6637 6638 $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); 6638 6639 6639 $lastpostdate = get_lastpostdate( $timezone );6640 $lastpostdate = get_lastpostdate( $timezone, $post_type ); 6640 6641 if ( $lastpostdate > $lastpostmodified ) { 6641 6642 $lastpostmodified = $lastpostdate; 6642 6643 } … … 6645 6646 * Filters the most recent time that a post was modified. 6646 6647 * 6647 6648 * @since 2.3.0 6649 * @since 5.4.0 - Add `$post_type` as the third parameter. 6648 6650 * 6649 6651 * @param string|false $lastpostmodified The most recent time that a post was modified, in 'Y-m-d H:i:s' format. 6650 6652 * False on failure. 6651 6653 * @param string $timezone Location to use for getting the post modified date. 6652 6654 * See get_lastpostdate() for accepted `$timezone` values. 6655 * @param string $post_type The post type to check. 6653 6656 */ 6654 return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );6657 return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone, $post_type ); 6655 6658 } 6656 6659 6657 6660 /** -
tests/phpunit/tests/post/getLastPostDate.php
1 <?php 2 3 /** 4 * @group post 5 */ 6 class Tests_Post_GetLastPostDate extends WP_UnitTestCase { 7 /** 8 * @ticket 47777 9 */ 10 public function test_get_lastpostdate() { 11 $post_post_date = '2018-01-30 16:09:28'; 12 $book_post_date = '2019-02-28 18:11:30'; 13 14 // Register book post type. 15 register_post_type( 'book', array( 'has_archive' => true ) ); 16 17 // Create a simple post. 18 $simple_post_id = self::factory()->post->create( 19 array( 20 'post_title' => 'Simple Post', 21 'post_type' => 'post', 22 'post_date' => $post_post_date, 23 ) 24 ); 25 26 // Create custom type post 27 $book_cpt_id = self::factory()->post->create( 28 array( 29 'post_title' => 'Book CPT', 30 'post_type' => 'book', 31 'post_date' => $book_post_date 32 ) 33 ); 34 35 // Update `post_modified` and `post_modified_gmt`. 36 global $wpdb; 37 38 $wpdb->update( 39 $wpdb->posts, 40 array( 41 'post_date' => $post_post_date, 42 'post_date_gmt' => $post_post_date, 43 ), 44 array( 45 'ID' => $simple_post_id, 46 ) 47 ); 48 49 $wpdb->update( 50 $wpdb->posts, 51 array( 52 'post_date' => $book_post_date, 53 'post_date_gmt' => $book_post_date, 54 ), 55 array( 56 'ID' => $book_cpt_id, 57 ) 58 ); 59 60 // Delete cache to get the updated modified date. 61 wp_cache_delete( $simple_post_id, 'posts' ); 62 wp_cache_delete( $book_cpt_id, 'posts' ); 63 64 $post_lastpost_date = get_lastpostdate( 'blog', 'post' ); 65 $book_lastpost_date = get_lastpostdate( 'blog', 'book' ); 66 67 $this->assertEquals( $post_post_date, $post_lastpost_date ); 68 $this->assertEquals( $book_post_date, $book_lastpost_date ); 69 } 70 } -
tests/phpunit/tests/post/getLastPostModified.php
Property changes on: tests/phpunit/tests/post/getLastPostDate.php ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
1 <?php 2 3 /** 4 * @group post 5 */ 6 class Tests_Post_GetLastPostModified extends WP_UnitTestCase { 7 /** 8 * @ticket 47777 9 */ 10 public function test_get_lastpostmodified() { 11 $post_post_date = '2018-01-30 16:09:28'; 12 $post_post_modified_date = '2018-02-28 17:10:29'; 13 14 $book_post_date = '2019-03-30 18:11:30'; 15 $book_post_modified_date = '2019-04-30 19:12:31'; 16 17 // Register book post type. 18 register_post_type( 'book', array( 'has_archive' => true ) ); 19 20 // Create a simple post. 21 $simple_post_id = self::factory()->post->create( 22 array( 23 'post_title' => 'Simple Post', 24 'post_type' => 'post', 25 'post_date' => $post_post_date, 26 ) 27 ); 28 29 // Create custom type post 30 $book_cpt_id = self::factory()->post->create( 31 array( 32 'post_title' => 'Book CPT', 33 'post_type' => 'book', 34 'post_date' => $book_post_date 35 ) 36 ); 37 38 // Update `post_modified` and `post_modified_gmt`. 39 global $wpdb; 40 41 $wpdb->update( 42 $wpdb->posts, 43 array( 44 'post_modified' => $post_post_modified_date, 45 'post_modified_gmt' => $post_post_modified_date, 46 ), 47 array( 48 'ID' => $simple_post_id, 49 ) 50 ); 51 52 $wpdb->update( 53 $wpdb->posts, 54 array( 55 'post_modified' => $book_post_modified_date, 56 'post_modified_gmt' => $book_post_modified_date, 57 ), 58 array( 59 'ID' => $book_cpt_id, 60 ) 61 ); 62 63 // Delete cache to get the updated modified date. 64 wp_cache_delete( $simple_post_id, 'posts' ); 65 wp_cache_delete( $book_cpt_id, 'posts' ); 66 67 $post_lastpost_modified = get_lastpostmodified( 'blog', 'post' ); 68 $book_lastpost_modified = get_lastpostmodified( 'blog', 'book' ); 69 70 $this->assertEquals( $post_post_modified_date, $post_lastpost_modified ); 71 $this->assertEquals( $book_post_modified_date, $book_lastpost_modified ); 72 } 73 }