Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#5155 closed defect (bug) (fixed)

wp_tag_cloud('format=array') does not return array

Reported by: andrewflanagan's profile andrewflanagan Owned by: ryan's profile ryan
Milestone: 2.5 Priority: low
Severity: minor Version: 2.3
Component: Template Keywords: tags, tag cloud, array, has-patch
Focuses: Cc:

Description

wp_tag_cloud('format=array'); will always return "Array" since the array is not returned but it merely attempts to "echo" the array (which in PHP will just output "Array"). I don't think that this is the intended purpose...

I had thought that the purpose of the parameter "format=array" was to get an actual PHP array of all tags. I can get this tag array by using get_terms('post_tag', $args);

I tried to slog through the code a little bit (wp-includes/category-template.php line 310 and on) but it didn't seem to handle the special case of not "echo"ing a result, but merely returning an array object.

Attachments (2)

5155.diff (485 bytes) - added by Otto42 17 years ago.
5155.improved.diff (696 bytes) - added by westi 17 years ago.
Improved patch

Download all attachments as: .zip

Change History (11)

#1 @andrewflanagan
17 years ago

  • Summary changed from wp_get_tags to wp_tag_cloud('format=array') does not return array

#2 @westi
17 years ago

  • Owner changed from anonymous to ryan

I think wp_tag_cloud is only designed to print out the tag cloud either as a flat list or with UL's. The array format that wp_generate_tag_cloud supports should only be used in calls to wp_generate_tag_cloud which does return the array.

This is an array of html links for the tags.

I think if anything you are calling wp_tag_cloud incorrectly.

Assigning to ryan for more input on this.

#3 follow-up: @Otto42
17 years ago

No, I gotta agree with the ticket. wp_generate_tag_cloud requires an input of tags from get_tags, which wp_tag_cloud does. Forcing them to use it directly adds more potential for error and doesn't necessarily allow for the result to always be the same data that wp_tag_cloud will create with the same parameters. So allowing format to be 'array' should return the array.

Anyway, it's an easy patch. Attached.

@Otto42
17 years ago

#4 in reply to: ↑ 3 @westi
17 years ago

  • Milestone changed from 2.3.1 to 2.4

Replying to Otto42:

No, I gotta agree with the ticket. wp_generate_tag_cloud requires an input of tags from get_tags, which wp_tag_cloud does. Forcing them to use it directly adds more potential for error and doesn't necessarily allow for the result to always be the same data that wp_tag_cloud will create with the same parameters. So allowing format to be 'array' should return the array.

Anyway, it's an easy patch. Attached.

Thanks for that.

I guess I should have read the code a bit closer last night :-)

However that patch isn't quite correct I don't think.

Attaching a new one for testing.

@westi
17 years ago

Improved patch

#5 follow-up: @Otto42
17 years ago

Why would you want to apply the wp_tag_cloud filters to an array?

Just wondering. Seems unlikely to me that any filters will be written to handle arrays properly there.

#6 in reply to: ↑ 5 @westi
17 years ago

Replying to Otto42:

Why would you want to apply the wp_tag_cloud filters to an array?

Just wondering. Seems unlikely to me that any filters will be written to handle arrays properly there.

I think we should always give the chance for a plugin to filter the output.

The plugin gets the $args string as a second argument to the filter call so it should be checking what it is getting before filtering anyway - otherwise it could break the output already if it applies filtering for flat displays to lists.

#7 @santosj
17 years ago

  • Component changed from General to Template

#8 @hansengel
17 years ago

  • Keywords has-patch added

#9 @ryan
17 years ago

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

(In [6616]) Return, don't echo, array. Props Otto42. fixes #5155

Note: See TracTickets for help on using tickets.