WordPress.org

Make WordPress Core

Changeset 50565


Ignore:
Timestamp:
03/23/2021 01:53:50 PM (4 weeks 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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r49946 r50565  
    11191119                );
    11201120
    1121                 if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
     1121                if ( ! empty( $t->rewrite['hierarchical'] ) ) {
    11221122                    $q[ $t->query_var ] = wp_basename( $q[ $t->query_var ] );
    11231123                }
  • trunk/src/wp-includes/taxonomy.php

    r50562 r50565  
    44764476        $termlink = home_url( $termlink );
    44774477    } else {
    4478         if ( $t->rewrite['hierarchical'] ) {
     4478        if ( ! empty( $t->rewrite['hierarchical'] ) ) {
    44794479            $hierarchical_slugs = array();
    44804480            $ancestors          = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' );
  • 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.