Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#9970 closed defect (bug) (fixed)

Category search throws PHP exception when search returns category children

Reported by: gortsleigh Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: Administration Keywords:
Focuses: Cc:


"Search Categories" in wp-admin/categories.php throws a warning

Warning: str_repeat(): Second argument has to be greater than or equal to 0 in ..../wp-admin/includes/template.php on line 124

exception when the search results include child categories.

To reproduce:

Create category "Top Level"

Create child categories "Child Level One" and "Child Level Two"

Search for "level"

Note: search for "top" will not generate the warning, because only the parent category is returned in the search results.

The cause of the problem is that function _cat_row() is called with parameter $level set to -1 (level zero subtracted by number of parents). This happens only during a search; normally the level is set correctly. The included patch simply fixes the call to str_replace, not the value of the parameter passed to _cat_row()

The purpose of the parameter is to aid in formatting the hierarchy of categories. Perhaps this should never be called with a negative value, but the formatting does not need to show hierarchy in search results, since it is likely the parents/ancestors will be missing from the results.

So, I think this patch is "good enough".

Attachments (1)

ticket-9970.patch (621 bytes) - added by gortsleigh 7 years ago.

Download all attachments as: .zip

Change History (3)

#1 @ryan
7 years ago

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

(In [11485]) Fix notice when searching categories. Props gortsleigh. fixes #9970

#2 @ryan
7 years ago

  • Milestone changed from Unassigned to 2.8
Note: See TracTickets for help on using tickets.