mirror of
git://develop.git.wordpress.org/
synced 2025-04-30 08:58:29 +02:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@50565 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4179f10b7a
commit
accdb47ffb
@ -1118,7 +1118,7 @@ class WP_Query {
|
||||
'field' => 'slug',
|
||||
);
|
||||
|
||||
if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
|
||||
if ( ! empty( $t->rewrite['hierarchical'] ) ) {
|
||||
$q[ $t->query_var ] = wp_basename( $q[ $t->query_var ] );
|
||||
}
|
||||
|
||||
|
@ -4475,7 +4475,7 @@ function get_term_link( $term, $taxonomy = '' ) {
|
||||
}
|
||||
$termlink = home_url( $termlink );
|
||||
} else {
|
||||
if ( $t->rewrite['hierarchical'] ) {
|
||||
if ( ! empty( $t->rewrite['hierarchical'] ) ) {
|
||||
$hierarchical_slugs = array();
|
||||
$ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' );
|
||||
foreach ( (array) $ancestors as $ancestor ) {
|
||||
|
@ -104,6 +104,36 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
$this->assertContains( 'term=bar', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 52882
|
||||
*/
|
||||
public function test_taxonomy_with_rewrite_false_and_custom_permalink_structure() {
|
||||
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
|
||||
register_taxonomy(
|
||||
'wptests_tax2',
|
||||
'post',
|
||||
array(
|
||||
'rewrite' => false,
|
||||
)
|
||||
);
|
||||
|
||||
add_permastruct( 'wptests_tax2', 'foo/%wptests_tax2%' );
|
||||
|
||||
$t = self::factory()->term->create(
|
||||
array(
|
||||
'taxonomy' => 'wptests_tax2',
|
||||
'slug' => 'bar',
|
||||
)
|
||||
);
|
||||
|
||||
$actual = get_term_link( $t, 'wptests_tax2' );
|
||||
|
||||
remove_permastruct( 'wptests_tax2' );
|
||||
|
||||
$this->assertContains( '/foo/bar/', $actual );
|
||||
}
|
||||
|
||||
public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() {
|
||||
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user