WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 7 years ago

Last modified 5 years ago

#4596 closed defect (bug) (worksforme)

use_desc_for_title doesnt work in wp_list_categories()

Reported by: tiosolid Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.2.1
Component: General Keywords: wp_list_categories categories lists reporter-feedback
Focuses: Cc:

Description (last modified by westi)

When you make a call to wp_list_categories(), the use_desc_for_title is set to TRUE by default, but even if the category has a description, the default text (View all posts filed under..) is shown. Even if you force the use_desc_for_title to TRUE in the wp_list_categories() call, it still doesnt work.

I managed to "fix" this bug changing the line 586 in the classes.php file from:

if ( $use_desc_for_title == 0 || empty($category->category_description) )

to

if ( empty($category->category_description) )

but, this break the use_desc_for_title variable usage.

Attachments (1)

test_walker_category.php (7.2 KB) - added by darkdragon 7 years ago.
Automattic Automated Tests for Walker Category

Download all attachments as: .zip

Change History (8)

comment:1 @foolswisdom8 years ago

  • Milestone set to 2.3 (trunk)

comment:2 @darkdragon7 years ago

  • Keywords reporter-feedback added

Question: Was the operator between those two an || or an && when you were having trouble?

This is an interesting bug. However, it appears that Trac removed some formatting from the description. I'm going to try to track down and see what the rest of the string is.

It appears that the line is using the correct logic, however, because of PHP implicit type jungling it is unclear whether your TRUE value is being type casted to INT 1.

It might be better to explicitly type cast $use_desc_for_title to boolean and then test for false value. However, type casting anything to boolean means that an empty variable and 0 will have false value and everything else will have true value.

With:

if( (bool) $use_desc_for_title === false || empty( $category->description ) )

These should have false values:

  • $use_desc_for_title = ''
  • $use_desc_for_title = 0
  • $use_desc_for_title = false

These should have true values:

  • $use_desc_for_title = true
  • $use_desc_for_title = 'a'
  • $use_desc_for_title = 1

It is unlikely that a drastic logic modification like removing the variable check would help anything. The logic itself should be fixed.

comment:3 @westi7 years ago

  • Description modified (diff)

fixed description so full text was visible.

comment:4 follow-up: @darkdragon7 years ago

I'm going to take ownership of this for the weekend or tonight. If I provide a patch and find a solution, is it possible it can get in? Or is it too early to tell?

comment:5 in reply to: ↑ 4 @westi7 years ago

Replying to darkdragon:

I'm going to take ownership of this for the weekend or tonight. If I provide a patch and find a solution, is it possible it can get in? Or is it too early to tell?

Go for it. Patches that fix issues are always appreciated!

comment:6 @darkdragon7 years ago

Wait! use_desc_for_title is set to '1' by default. However, it is a string, it will still be type casted to 1, which doesn't equal 0, so the first evaluates to false and unless the description contains something, it will display the first block with "View all posts..."

I'm unsure if the goal is to allow for setting the value to true. In which case, I would have to agree that it should allow you to set the argument to true.

@darkdragon7 years ago

Automattic Automated Tests for Walker Category

comment:7 @darkdragon7 years ago

  • Milestone 2.4 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Unit Tests show that this is not a problem. $category->category_description no longer exists and is now $category->description, it is most likely that the problem you were having was fixed on the switch over to Taxonomy API.

Note: See TracTickets for help on using tickets.