WordPress.org

Make WordPress Core

Ticket #35385: 35385-1.diff

File 35385-1.diff, 3.2 KB (added by wido, 5 months ago)

Fix wrong generated diff from master

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

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index 32d5595bb1..a4cec6a796 100644
    a b function get_the_archive_description() { 
    16681668/**
    16691669 * Retrieves the description for a post type archive.
    16701670 *
    1671  * @since 4.9.0
     1671 * @param bool $raw To get the raw version of the description. Optional
    16721672 *
    16731673 * @return string The post type description.
     1674 *@since 4.9.0
     1675 *
    16741676 */
    1675 function get_the_post_type_description() {
     1677function get_the_post_type_description( $raw = false ) {
    16761678        $post_type = get_query_var( 'post_type' );
    16771679
    16781680        if ( is_array( $post_type ) ) {
    function get_the_post_type_description() { 
    16881690                $description = '';
    16891691        }
    16901692
     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
    16911705        /**
    16921706         * Filters the description for a post type archive.
    16931707         *
  • new file tests/phpunit/tests/general/thePostTypeDescription.php

    diff --git a/tests/phpunit/tests/general/thePostTypeDescription.php b/tests/phpunit/tests/general/thePostTypeDescription.php
    new file mode 100644
    index 0000000000..c1bb2ca4e2
    - +  
     1<?php
     2
     3class 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