Make WordPress Core


Ignore:
Timestamp:
03/23/2021 01:53:50 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Taxonomy: Use a consistent check for the $rewrite['hierarchical'] parameter.

This avoids a "Trying to access array offset on value of type bool" PHP warning in get_term_link() if the $rewrite parameter of register_taxonomy() is set as false.

Props Tkama, SergeyBiryukov.
Fixes #52882.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/getTermLink.php

    r49108 r50565  
    103103                $this->assertContains( 'taxonomy=wptests_tax2', $actual );
    104104                $this->assertContains( 'term=bar', $actual );
     105        }
     106
     107        /**
     108         * @ticket 52882
     109         */
     110        public function test_taxonomy_with_rewrite_false_and_custom_permalink_structure() {
     111                $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     112
     113                register_taxonomy(
     114                        'wptests_tax2',
     115                        'post',
     116                        array(
     117                                'rewrite' => false,
     118                        )
     119                );
     120
     121                add_permastruct( 'wptests_tax2', 'foo/%wptests_tax2%' );
     122
     123                $t = self::factory()->term->create(
     124                        array(
     125                                'taxonomy' => 'wptests_tax2',
     126                                'slug'     => 'bar',
     127                        )
     128                );
     129
     130                $actual = get_term_link( $t, 'wptests_tax2' );
     131
     132                remove_permastruct( 'wptests_tax2' );
     133
     134                $this->assertContains( '/foo/bar/', $actual );
    105135        }
    106136
Note: See TracChangeset for help on using the changeset viewer.