Ticket #5155 (closed defect: fixed)

Opened 1 year ago

Last modified 11 months ago

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

Reported by: andrewflanagan Assigned to: ryan
Priority: low Milestone: 2.5
Component: Template Version: 2.3
Severity: minor Keywords: tags, tag cloud, array, has-patch
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

5155.diff (485 bytes) - added by Otto42 on 10/06/07 21:09:33.
5155.improved.diff (0.7 kB) - added by westi on 10/07/07 07:43:14.
Improved patch

Change History

10/06/07 18:17:15 changed by andrewflanagan

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

10/06/07 20:37:02 changed by westi

  • 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.

(follow-up: ↓ 4 ) 10/06/07 21:09:16 changed by 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.

10/06/07 21:09:33 changed by Otto42

  • attachment 5155.diff added.

(in reply to: ↑ 3 ) 10/07/07 07:41:59 changed by westi

  • 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.

10/07/07 07:43:14 changed by westi

  • attachment 5155.improved.diff added.

Improved patch

(follow-up: ↓ 6 ) 10/08/07 05:02:29 changed by 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.

(in reply to: ↑ 5 ) 10/08/07 06:19:13 changed by westi

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.

12/27/07 21:00:48 changed by santosj

  • component changed from General to Template.

01/13/08 16:50:20 changed by hansengel

  • keywords changed from tags, tag cloud, array to tags, tag cloud, array, has-patch.

01/14/08 22:35:43 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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