Permalinks: Make get_post_type_archive_link()
work for the 'post' post type.
Props jjj. See #19902. git-svn-id: https://develop.svn.wordpress.org/trunk@36225 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b5a4504f7e
commit
5304745be0
@ -1124,6 +1124,19 @@ function get_post_type_archive_link( $post_type ) {
|
||||
if ( ! $post_type_obj = get_post_type_object( $post_type ) )
|
||||
return false;
|
||||
|
||||
if ( 'post' === $post_type ) {
|
||||
$show_on_front = get_option( 'show_on_front' );
|
||||
$page_for_posts = get_option( 'page_for_posts' );
|
||||
|
||||
if ( 'page' == $show_on_front && $page_for_posts ) {
|
||||
$link = get_permalink( $page_for_posts );
|
||||
} else {
|
||||
$link = get_home_url();
|
||||
}
|
||||
/** This filter is documented in wp-includes/link-template.php */
|
||||
return apply_filters( 'post_type_archive_link', $link, $post_type );
|
||||
}
|
||||
|
||||
if ( ! $post_type_obj->has_archive )
|
||||
return false;
|
||||
|
||||
|
28
tests/phpunit/tests/link/getPostTypeArchiveLink.php
Normal file
28
tests/phpunit/tests/link/getPostTypeArchiveLink.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @group link
|
||||
*/
|
||||
class Tests_Link_GetPostTypeArchiveLink extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 19902
|
||||
*/
|
||||
public function test_get_post_archive_link_with_post_archive_on_front_page() {
|
||||
update_option( 'show_on_front', 'posts' );
|
||||
$actual = get_post_type_archive_link( 'post' );
|
||||
$expected = get_home_url();
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 19902
|
||||
*/
|
||||
public function test_get_post_archive_link_with_post_archive_on_a_blog_page() {
|
||||
$page_for_posts = $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) );
|
||||
update_option( 'show_on_front', 'page' );
|
||||
update_option( 'page_for_posts', $page_for_posts );
|
||||
$actual = get_post_type_archive_link( 'post' );
|
||||
$expected = get_permalink( $page_for_posts );
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user