Ticket #47777: 47777.4.diff
File 47777.4.diff, 7.8 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_first = '2018-01-30 16:09:28'; 12 $post_post_date_last = '2018-01-31 16:09:28'; 13 $book_post_date_first = '2019-02-28 18:11:30'; 14 $book_post_date_last = '2019-02-28 18:11:30'; 15 16 // Register book post type. 17 register_post_type( 'book', array( 'has_archive' => true ) ); 18 19 // Create a simple post. 20 $simple_post_id_first = self::factory()->post->create( 21 array( 22 'post_title' => 'Simple Post First', 23 'post_type' => 'post', 24 'post_date' => $post_post_date_first, 25 ) 26 ); 27 28 $simple_post_id_last = self::factory()->post->create( 29 array( 30 'post_title' => 'Simple Post Last', 31 'post_type' => 'post', 32 'post_date' => $post_post_date_last, 33 ) 34 ); 35 36 // Create custom type post 37 $book_cpt_id_first = self::factory()->post->create( 38 array( 39 'post_title' => 'Book CPT First', 40 'post_type' => 'book', 41 'post_date' => $book_post_date_first 42 ) 43 ); 44 45 $book_cpt_id_last = self::factory()->post->create( 46 array( 47 'post_title' => 'Book CPT Last', 48 'post_type' => 'book', 49 'post_date' => $book_post_date_last 50 ) 51 ); 52 53 54 // Delete cache to get the updated modified date. 55 wp_cache_delete( $simple_post_id_first, 'posts' ); 56 wp_cache_delete( $simple_post_id_last, 'posts' ); 57 wp_cache_delete( $book_cpt_id_first, 'posts' ); 58 wp_cache_delete( $book_cpt_id_last, 'posts' ); 59 60 61 $post_lastpost_date = get_lastpostdate( 'blog', 'post' ); 62 $book_lastpost_date = get_lastpostdate( 'blog', 'book' ); 63 64 $this->assertEquals( $post_post_date_last, $post_lastpost_date ); 65 $this->assertEquals( $book_post_date_last, $book_lastpost_date ); 66 } 67 } -
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_first = '2016-01-30 16:09:28'; 12 $post_post_modified_date_first = '2016-02-28 17:10:29'; 13 14 $post_post_date_last = '2017-03-30 18:11:30'; 15 $post_post_modified_date_last = '2017-04-30 19:12:31'; 16 17 $book_post_date_first = '2018-05-30 20:09:28'; 18 $book_post_modified_date_first = '2018-06-30 21:10:29'; 19 20 $book_post_date_last = '2019-07-30 22:11:30'; 21 $book_post_modified_date_last = '2019-08-30 23:12:31'; 22 23 // Register book post type. 24 register_post_type( 'book', array( 'has_archive' => true ) ); 25 26 // Create a simple post. 27 $simple_post_id_first = self::factory()->post->create( 28 array( 29 'post_title' => 'Simple Post First', 30 'post_type' => 'post', 31 'post_date' => $post_post_date_first, 32 ) 33 ); 34 35 $simple_post_id_last = self::factory()->post->create( 36 array( 37 'post_title' => 'Simple Post Last', 38 'post_type' => 'post', 39 'post_date' => $post_post_date_last, 40 ) 41 ); 42 43 // Create custom type post 44 $book_cpt_id_first = self::factory()->post->create( 45 array( 46 'post_title' => 'Book CPT First', 47 'post_type' => 'book', 48 'post_date' => $book_post_date_first 49 ) 50 ); 51 52 $book_cpt_id_last = self::factory()->post->create( 53 array( 54 'post_title' => 'Book CPT Last', 55 'post_type' => 'book', 56 'post_date' => $book_post_date_last 57 ) 58 ); 59 60 // Update `post_modified` and `post_modified_gmt`. 61 global $wpdb; 62 63 $wpdb->update( 64 $wpdb->posts, 65 array( 66 'post_modified' => $post_post_modified_date_first, 67 'post_modified_gmt' => $post_post_modified_date_first, 68 ), 69 array( 70 'ID' => $simple_post_id_first, 71 ) 72 ); 73 74 $wpdb->update( 75 $wpdb->posts, 76 array( 77 'post_modified' => $post_post_modified_date_last, 78 'post_modified_gmt' => $post_post_modified_date_last, 79 ), 80 array( 81 'ID' => $simple_post_id_last, 82 ) 83 ); 84 85 $wpdb->update( 86 $wpdb->posts, 87 array( 88 'post_modified' => $book_post_modified_date_first, 89 'post_modified_gmt' => $book_post_modified_date_first, 90 ), 91 array( 92 'ID' => $book_cpt_id_first, 93 ) 94 ); 95 96 $wpdb->update( 97 $wpdb->posts, 98 array( 99 'post_modified' => $book_post_modified_date_last, 100 'post_modified_gmt' => $book_post_modified_date_last, 101 ), 102 array( 103 'ID' => $book_cpt_id_last, 104 ) 105 ); 106 107 // Delete cache to get the updated modified date. 108 wp_cache_delete( $simple_post_id_first, 'posts' ); 109 wp_cache_delete( $simple_post_id_last, 'posts' ); 110 wp_cache_delete( $book_cpt_id_first, 'posts' ); 111 wp_cache_delete( $book_cpt_id_last, 'posts' ); 112 113 $post_lastpost_modified = get_lastpostmodified( 'blog', 'post' ); 114 $book_lastpost_modified = get_lastpostmodified( 'blog', 'book' ); 115 116 $this->assertEquals( $post_post_modified_date_last, $post_lastpost_modified ); 117 $this->assertEquals( $book_post_modified_date_last, $book_lastpost_modified ); 118 } 119 }