Support » Fixing WordPress » Delete sidebar causes remaining sidebar widgets to scramble

  • I have a weird problem that hopefully someone has encountered here before. I’m using the Karma theme by TrueThemes and it has the ability to add custom sidebars. I love that! However, I just found that if I delete one of those custom sidebars, the remaining sidebars’ widgets get scrambled. It’s like the widgets all bump up (or down?) one whenever I delete a sidebar.

    Here are some other particulars if it’s of any use:
    WordPress 3.2.1
    MySQL – 5.0.92
    PHP 5.2.17

    I’ve reinstalled WordPress and the Karma theme but nothing seems to change this weird behavior.

    Can anyone help me figure this out? I can’t deliver this website to the customer with the knowledge that the sidebars could scramble on them.

Viewing 5 replies - 1 through 5 (of 5 total)
  • It’s probably not a bug in WordPress or your configuration. It’s most likely caused by the way additional sidebars are registered; additional sidebars are probably given a numerical ID that automatically increments. So, for example, when you have four sidebars and you delete the first one, something like this probably happens:

    Sidebar 1 -> Deleted
    Sidebar 2 -> Sidebar 1
    Sidebar 3 -> Sidebar 2
    Sidebar 4 -> Sidebar 3

    If this is what happens, at the very least it’s a predictable problem.

    Since it’s a premium theme this is all really just speculation. For a definitive answer it would probably be best to ask for support directly from TrueThemes:

    http://support.truethemes.net/

    Thanks! Yes, I’ve asked for help at the theme provider’s support forum but last word was they didn’t think it was their problem. That’s why I’m posting here to see if perhaps this has occurred elsewhere with other implementations.

    I’ll re-post to their support forum. Thanks for responding!

    In case someone stumbles on this thread, here’s what I’ve learned from the theme provider. It seems to make sense though it doesn’t seem reasonable that WordPress would do this. Hopefully, WordPress will work up a fix to this behavior. Here’s the response:

    This is not a bug, it is how WordPress Works.
    When you remove or add sidebars, you need to move all widgets to the “inactive widgets” area to prevent “lost” of widget and its data.

    When you add a sidebar, the sidebar ID increases…So if you add another sidebar, WordPress will assign it as sidebar ID. Remove any sidebar, will break the running order of the ID, causing WordPress to reassign the ID’s again in running order.

    Removing any of the sidebars will either cause the widget to disappear or shift up to the preceding sidebar, WordPress sees the sidebars as ID in running order and does not care about the name you give to the sidebar.

    So to avoid any lost of widget and its data you need to move all widgets to the “Inactive Widgets” area before you remove any sidebar.

    Well…yes, that’s what happens when you use register_sidebars() with default arguments. The fix would be to store an integer that increments with each new sidebar and use it to assign a unique ID to each sidebar that is never altered. I had to do something similar in a plugin recently.

    They’re right though, to be safe it’s always good to move widgets to the inactive widgets area to make sure nothing happens to them when you do anything that might alter the sidebars. Ultimately, it’s their decision if they want to hack around the default behavior of a WordPress function to ensure a slightly easier end user experience. I don’t know how exactly they implemented this, so it could mean a fair amount of work.

    As an “old” programmer (who doesn’t program any more) that was what I thought should happen, too. Assign a unique id to the sidebar and don’t reuse it. Seems simple but perhaps it’s more work than I know.

    I’m sure I’ve used a sidebar plugin on another site I support that doesn’t allow this behavior upon deletion of a sidebar. I think I’ll install that and use it instead of the “native” theme sidebar feature.

    Too bad, because I really like the Karma theme. It seems to be well documented, and well designed other than this little “feature”.

    Perhaps a change to this behavior will be included with a future update to the theme.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Delete sidebar causes remaining sidebar widgets to scramble’ is closed to new replies.