Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#52882 closed defect (bug) (fixed)

get_term_link() WARNING

Reported by: tkama's profile Tkama Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.8 Priority: normal
Severity: normal Version: 3.1
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

$rewrite parameter for the register_taxonomy() function can be set as false. Doing so we get such WARNING

https://prnt.sc/10sfqew

https://prnt.sc/10sfr2d

Attachments (2)

tax.diff (635 bytes) - added by Tkama 4 years ago.
52882.diff (2.1 KB) - added by SergeyBiryukov 4 years ago.

Download all attachments as: .zip

Change History (5)

@Tkama
4 years ago

#1 @SergeyBiryukov
4 years ago

  • Component changed from General to Taxonomy
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 5.8
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

@SergeyBiryukov
4 years ago

#2 @SergeyBiryukov
4 years ago

  • Version changed from 5.7 to 3.1

Hi there, thanks for the report and the patch.

I was able to reproduce the issue, but only when the taxonomy also has a custom permalink structure, either by calling add_permastruct() or using the pre_term_link filter. By default, add_permastruct() is only called for a taxonomy if the `rewrite` argument is not false, which is the opposite of what's being reported here.

Otherwise, the $wp_rewrite->get_extra_permastruct() call a few lines above returns false and the control gets into the first conditional branch, and not the one that causes the warning.

52882.diff includes a unit test.

This is not new in 5.7 and appears to be introduced in [15824], adjusting the version accordingly.

#3 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 50565:

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.

Note: See TracTickets for help on using tickets.