Make WordPress Core


Ignore:
Timestamp:
03/21/2019 12:43:48 PM (7 years ago)
Author:
desrosj
Message:

Posts, Post Types: Add type parameter to post_exists().

This allows post exists checks scoped to a specific post type.

Props sgarza, birgire, swissspidy.
Fixes #37406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r44672 r44959  
    852852                $this->assertEquals( '', get_post_meta( $p, 'testkey', true ) );
    853853        }
     854
     855        /**
     856         * Test the post type support in post_exists().
     857         *
     858         * @ticket 37406
     859         */
     860        public function test_post_exists_should_support_post_type() {
     861                $title     = 'Foo Bar';
     862                $post_type = 'page';
     863                $post_id   = self::factory()->post->create(
     864                        array(
     865                                'post_title' => $title,
     866                                'post_type'  => $post_type,
     867                        )
     868                );
     869                $this->assertSame( $post_id, post_exists( $title, null, null, $post_type ) );
     870        }
     871
     872        /**
     873         * Test that post_exists() doesn't find an existing page as a post.
     874         *
     875         * @ticket 37406
     876         */
     877        public function test_post_exists_should_not_match_a_page_for_post() {
     878                $title     = 'Foo Bar';
     879                $post_type = 'page';
     880                $post_id   = self::factory()->post->create(
     881                        array(
     882                                'post_title' => $title,
     883                                'post_type'  => $post_type,
     884                        )
     885                );
     886                $this->assertSame( 0, post_exists( $title, null, null, 'post' ) );
     887        }
    854888}
Note: See TracChangeset for help on using the changeset viewer.