Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#52882 closed defect (bug) (fixed)

get_term_link() WARNING

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

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 6 years ago.
52882.diff​ (2.1 KB ) - added by SergeyBiryukov 6 years ago.

Download all attachments as: .zip

Change History (5)

#1 @SergeyBiryukov
6 years ago

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

#2 @SergeyBiryukov
6 years ago

  • Version 5.7 → 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
6 years ago

  • Resolution → fixed
  • Status reviewing → 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.