Ticket #4287 (closed defect: fixed)

Opened 1 year ago

Last modified 6 months ago

Links widget has duplicate ID issue

Reported by: Otto42 Assigned to: mdawaffe
Priority: normal Milestone: 2.5.1
Component: General Version: 2.2
Severity: normal Keywords: has-patch commit
Cc:

Description (Last modified by rob1n)

wp_list_bookmarks can generate several "blocks" in the sidebar, one per category. In combination with the links widget, this can produce several list items (LI) all using the same id. This will cause the site to fail validation, since there are duplicated ID's.

The reason this happens is because dynamic_sidebar() builds the "before_widget" string using replacements for $1 and $2 as the id and class, respectively. This string then gets passed to wp_list_bookmarks as the "category_before" parameter.

What really needs to occur, in this particular case, is that the original, unreplaced, before_widget string needs to get "$1" replaced with "%id", allowing the normal wp_list_bookmarks code to work correctly, ensuring a unique ID for each of the bookmark blocks.

What the right was to do this is, I'm not entirely certain. We could copy the original string to $params[0]['original_before_widget'] and then let wp_widget_links handle it correctly by doing its own replacement. That would work.

Attachments

wp-includes-widgets.php.patch (467 bytes) - added by docwhat on 04/03/08 15:33:28.

Change History

05/18/07 19:43:44 changed by Otto42

Reference to somebody pointing out this issue: http://wordpress.org/support/topic/118321

05/18/07 20:11:11 changed by Otto42

Correction: dynamic_sidebar is replacing %1$s and %2$s with the id and class, respectively. My mistake.

05/25/07 15:57:29 changed by rob1n

  • description changed.

06/08/07 23:10:09 changed by rob1n

  • milestone changed from 2.2.1 to 2.2.2.

06/10/07 14:58:34 changed by docwhat

Here's a stupid simple fix. Add this right before the call to wp_list_bookmarks() in wp_widget_links():

$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);

07/25/07 14:33:42 changed by Otto42

  • milestone changed from 2.2.2 to 2.3 (trunk).

09/13/07 05:23:42 changed by ryan

  • milestone changed from 2.3 to 2.4.

09/24/07 05:34:57 changed by docwhat

The impact of this bug is rather serious. I don't know why it keeps getting bumped even though there is a simple one line fix for it. It may not be the *best* fix, but it is a fix and it'll work reliably.

Without it CSS and JavaScript? cannot do the right thing with respect to the link widget and the (X)HTML is not valid. This is a huge problem for themes like Sandbox, where you need the markup to be valid to get the CSS to work.

Ciao!

03/31/08 20:56:54 changed by Otto42

  • milestone changed from 2.6 to 2.5.1.

Any chance of this getting in soon? Still happening in 2.5.

03/31/08 23:20:25 changed by lloydbudd

  • owner changed from anonymous to mdawaffe.

(follow-up: ↓ 12 ) 04/03/08 11:35:10 changed by hakre

Maybe this does not get in because of the new way widgets are handled in version 2.5. Does this patch works with the current widget-admin? Maybe it is related to the the ID-problems there (#6549) as well?

(in reply to: ↑ 11 ) 04/03/08 15:33:10 changed by docwhat

  • keywords set to has-patch.

Replying to hakre:

Maybe this does not get in because of the new way widgets are handled in version 2.5. Does this patch works with the current widget-admin? Maybe it is related to the the ID-problems there (#6549) as well?

I don't think #6549 is related at all. That's the widget admin page, not the normal views.

The patch still works just fine, though fuzzy. I'll upload a non-fuzzy one in a second. I'm using it on my blog (http://docwhat.gerf.org/) right now. Without it I can't have the nice collapsing Friends & Links.

Ciao!

04/03/08 15:33:28 changed by docwhat

  • attachment wp-includes-widgets.php.patch added.

04/17/08 20:26:27 changed by mdawaffe

  • keywords changed from has-patch to has-patch commit.

+! untested

04/17/08 20:31:40 changed by ryan

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

(In [7723]) Make link widget IDs unique. Props docwhat. fixes #4287 for 2.5

04/17/08 20:32:15 changed by ryan

(In [7724]) Make link widget IDs unique. Props docwhat. fixes #4287 for trunk