WordPress.org

Make WordPress Core

Ticket #35385: 35385.diff

File 35385.diff, 3.2 KB (added by wido, 8 months ago)

Introduce additional parameter to get the raw version of the post type archive description

  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index a4cec6a796..32d5595bb1 100644
    a b function get_the_archive_description() { 
    16681668/**
    16691669 * Retrieves the description for a post type archive.
    16701670 *
    1671  * @param bool $raw To get the raw version of the description. Optional
     1671 * @since 4.9.0
    16721672 *
    16731673 * @return string The post type description.
    1674  *@since 4.9.0
    1675  *
    16761674 */
    1677 function get_the_post_type_description( $raw = false ) {
     1675function get_the_post_type_description() {
    16781676        $post_type = get_query_var( 'post_type' );
    16791677
    16801678        if ( is_array( $post_type ) ) {
    function get_the_post_type_description( $raw = false ) { 
    16901688                $description = '';
    16911689        }
    16921690
    1693         /**
    1694          * Filters the description text for a post type archive.
    1695          *
    1696          * @param string $description The post type description.
    1697          * @param WP_Post_Type $post_type_obj The post type object.
    1698          */
    1699         $description = apply_filters( 'get_the_post_type_description_text', $description, $post_type_obj );
    1700 
    1701         if ( $raw ) {
    1702                 return $description;
    1703         }
    1704 
    17051691        /**
    17061692         * Filters the description for a post type archive.
    17071693         *
  • deleted file tests/phpunit/tests/general/thePostTypeDescription.php

    diff --git a/tests/phpunit/tests/general/thePostTypeDescription.php b/tests/phpunit/tests/general/thePostTypeDescription.php
    deleted file mode 100644
    index c1bb2ca4e2..0000000000
    + -  
    1 <?php
    2 
    3 class Tests_The_Post_Type_Description extends WP_UnitTestCase {
    4 
    5         /**
    6          * @ticket 35385
    7          */
    8         public function test_the_post_type_description_return_raw_description() {
    9                 $post_type_name        = uniqid();
    10                 $post_type_description = uniqid();
    11 
    12                 register_post_type(
    13                         $post_type_name,
    14                         [
    15                                 'rewrite'     => true,
    16                                 'has_archive' => true,
    17                                 'label'       => 'WordCamp Test',
    18                                 'public'      => true,
    19                                 'description' => $post_type_description,
    20                         ]
    21                 );
    22 
    23                 $this->go_to( "?post_type={$post_type_name}" );
    24                 $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    25                 $this->assertEquals( get_queried_object(), get_post_type_object( $post_type_name ) );
    26 
    27                 $result = get_the_post_type_description( true );
    28 
    29                 $this->assertEquals( $post_type_description, $result );
    30         }
    31 
    32         public function test_the_post_type_description_return_raw_filtered_description() {
    33                 $post_type_name                          = uniqid();
    34                 $post_type_description                   = uniqid();
    35                 $expected_filtered_post_type_description = uniqid();
    36 
    37                 register_post_type(
    38                         $post_type_name,
    39                         [
    40                                 'has_archive' => true,
    41                                 'public'      => true,
    42                                 'description' => $post_type_description,
    43                         ]
    44                 );
    45 
    46                 $this->go_to( "?post_type={$post_type_name}" );
    47                 $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    48                 $this->assertEquals( get_queried_object(), get_post_type_object( $post_type_name ) );
    49 
    50                 add_filter(
    51                         'get_the_post_type_description_text',
    52                         function ( $raw_description ) use ( $expected_filtered_post_type_description ) {
    53                                 return $expected_filtered_post_type_description;
    54                         }
    55                 );
    56 
    57                 $result = get_the_post_type_description( true );
    58 
    59                 $this->assertEquals( $expected_filtered_post_type_description, $result );
    60         }
    61 }
    62