Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Sidebar not saving widgets WordPress

  • SOLVED

I am using a sidebar system that is more complex that normal themes. My problem is that widgets are not saving. I am using the latest stable WP version and this theme is run on multiple blogs within the same multisite setup. The functions code can be found here:
[[LINK href="http://pastebin.com/1f3diTxN"]]http://pastebin.com/1f3diTxN[[/LINK]].

I am looking for a second set of eyes to help me find the issue. Thanks so much. :)


Update: I failed to mention that the main widget area is saving the widgets which to me would suggest that my arrays are jacked up somewhere. Of course I could be wrong...

Answers (4)

2010-08-05

wjm answers:

I have been working on design bug in the core wordpress files when registering sidebars, and at first glance, i can say that one line may be causing trouble.

'id' => 'sidebar-widgetarea',

<strong>sidebar-</strong> is a the prefix used for sidebars registered with a missing id, usually used in the form of sidebar-1 for the first sidebar registered, sidebar-2 for the second and so on.

so my suggestion is change that id to something else cause it may cause conflicts
i will look at your code later if you cannot solve this issue.
- wjm


wjm comments:

also, ALWAYS use an ID when registering a sidebar. because if you move the order, that is you add another sibebar before the onces you have.. ALL YOUR WIDGETS WILL BE GONE.


wjm comments:

man this is a weird bug,
i think i tracked it down,
it has to do with ids having a capital letter.
so replace
'id' => 'footerL-widgetarea',
with
'id' => 'footerl-widgetarea',
and it will work

and whereever you have a capital case in your id.
more on this later, i will report a bug and patch to trac.wordpress


wjm comments:

bug and patch submitted,
[[LINK href="http://core.trac.wordpress.org/ticket/14548"]]http://core.trac.wordpress.org/ticket/14548[[/LINK]]


wjm comments:

here is the fixed version of your file,
i have tested every sidebar and it the widgets remain there after reloading the page.
[[LINK href="http://pastebin.com/km356aEQ"]]http://pastebin.com/km356aEQ[[/LINK]]

2010-08-05

Pippin Williamson answers:

Does WP give you an error when trying to save the widget?


Matt Taylor comments:

No. Everything looks as normal.


Matt Taylor comments:

When the page is refreshed or navigated away from and then back to the widgets appear in the Inactive Widgets section.


Pippin Williamson comments:

If the widgets don't work in the default theme either, then it's no an issue with your coding. It's probably a plugin conflict. Deactivate all plugins and test.


Matt Taylor comments:

Just deactivated all plugins and removed mu-plugins folder, no changes.


Pippin Williamson comments:

Do no widgets save, or just some of them? Is the site running on a local WP install or on a live server?


Matt Taylor comments:

I failed to mention that the main widget area is saving the widgets which to me would suggest that my arrays are jacked up somewhere. Of course I could be wrong...

No widgets save in any area outside of the primary sidebar, id: sidebar-widgetarea.


Pippin Williamson comments:

Do they save in other widget areas?


Pippin Williamson comments:

Oops, I mean do they save in the primary widget area?


Matt Taylor comments:

Just the primary area. Not in the other seven.


Pippin Williamson comments:

Create a new widget area by copying the code from the primary, then very carefully change the names. See if that area saves. If so, you have your problem solved.


Matt Taylor comments:

I have done that twice already. :/


Pippin Williamson comments:

Have you tried making another widget area with as few options as possible, to make the margin of error much less?


Matt Taylor comments:

Yes of course.


Pippin Williamson comments:

Have you tried running the theme on a different server? Perhaps on a local WP install? As Rashad said, it might be a problem with your hosting config.


Matt Taylor comments:

Yes I have tried it on other web hosts, no change.


Pippin Williamson comments:

I found a solution.

Apparently assigning an ID to each widget breaks it. Remove


'id' => 'footerL-widgetarea',


from each widget and everything should work fine.

2010-08-05

Rashad Aliyev answers:

Hello,

Change your theme to Default and check it again.


Matt Taylor comments:

That was the first thing I tried. Even uninstalled the theme.


Rashad Aliyev comments:

If it's not happened after installing some plugins then it may causing from your hosting settings.


Rashad Aliyev comments:

Try to change this code with yours please.

P.S: Don't forget backup your files.

<?php

/*** WIDGETS ***/
// Check if widget area is active source: http://themeshaper.com/registering-new-sidebars-for-custom-page-templates-the-smart-way/
function is_pagetemplate_active($pagetemplate = '') {
global $wpdb;
$sql = "select meta_key from $wpdb->postmeta where meta_key like '_wp_page_template' and meta_value like '" . $pagetemplate . "'";
$result = $wpdb->query($sql);
if ($result) { return TRUE; } else { return FALSE; } } // is_pagetemplate_active()
// Register widgetized areas
if ( function_exists('register_sidebars') ) {
register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar-widgetarea',
'description' => __('This is right sidebar & is the primary widget area.', 'sidebar-widgetarea'),
'before_widget' => '<div id="%1$s" class="%2$s widget sidebar-widget">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title sidebar-widget-title">',
'after_title' => '</h3>' ));

register_sidebar(array(
'name' => 'Footer, left',
'id' => 'footerL-widgetarea',
'description' => __('Widget area for the footer, left side.', 'footerL-widgetarea'),
'before_widget' => '<section id="fwal"><div id="%1$s" class="%2$s widget footer-widget fw-left">',
'after_widget' => '</div></section>',
'before_title' => '<h3 class="widget-title footer-widget-title fw-left-title">',
'after_title' => '</h3>' ));

register_sidebar(array(
'name' => 'Footer, middle left',
'id' => 'footerML-widgetarea',
'description' => __('Widget area for the footer, middle left side.', 'footerML-widgetarea'),
'before_widget' => '<section id="fwar"><div id="%1$s" class="widget %2$s fw-rightblock">',
'after_widget' => '</div></section>',
'before_title' => '<h3 class="widgettitle fw-rightblock-title">',
'after_title' => '</h3>' ));

register_sidebar(array(
'name' => 'Footer, middle right',
'id' => 'footerMR-widgetarea',
'description' => __('Widget area for the footer, middle right side.', 'footerMR-widgetarea'),
'before_widget' => '<section id="fwar"><div id="%1$s" class="widget %2$s fw-rightblock">',
'after_widget' => '</div></section>',
'before_title' => '<h3 class="widgettitle fw-rightblock-title">',
'after_title' => '</h3>' ));

register_sidebar(array(
'name' => 'Footer, right',
'id' => 'footerR-widgetarea',
'description' => __('Widget area for the footer, right side.', 'footerR-widgetarea'),
'before_widget' => '<section id="fwar"><div id="%1$s" class="widget %2$s fw-rightblock">',
'after_widget' => '</div></section>',
'before_title' => '<h3 class="widgettitle fw-rightblock-title">',
'after_title' => '</h3>'));


function emp_template_widgets_init() {
if(is_pagetemplate_active('page-altsidebar.php') || is_pagetemplate_active('page-altsidebar-noslidertimecomments.php') ||
is_pagetemplate_active('page-altsidebar-nothingelse.php') ) {
register_sidebar( array (
'name' => 'Page Template - Alternate',
'id' => 'sidebarAlt-widgetarea',
'description' => __('This is the sidebar for an alternative sidebar page template.', 'sidebarAlt-widgetarea'),
'before_widget' => '<div id="%1$s" class="%2$s widget sidebarAlt-widget">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title sidebarAlt-widget-title">',
'after_title' => '</h3>' ));
} // end test for active template

if(is_pagetemplate_active('page-WPECsidebar.php')) {
register_sidebar( array (
'name' => 'Page Template - WPEC',
'id' => 'sidebarWPEC-widgetarea',
'description' => __('This is the sidebar for a WPEC page.', 'sidebarWPEC-widgetarea'),
'before_widget' => '<div id="%1$s" class="%2$s widget sidebarWPEC-widget">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title sidebarWPEC-widget-title">',
'after_title' => '</h3>' ));
} // end test for active template
} // test_template_widgets_init()
add_action ( 'init' , 'emp_template_widgets_init' );

register_sidebar( array(
'name' => 'Page Template - 404',
'id' => '404-widgetarea',
'description' => __('Widget area for 404 error pages.', '404'),
'before_widget' => '<div id="%1$s" class="%2$s widget 404-widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title 404-widget-title">',
'after_title' => '</h3>'));
} // end widget areas

?>


Rashad Aliyev comments:

Did you tried my codes? I think it'll work ;)


Matt Taylor comments:

I'm getting the exact same result my friend. :/

2010-08-05

Eddie Moya answers:

So what you mean is that your in the backend, in the widget editor, and the changes your making are not sticking?

If thats correct, I need to ask a few more questions...

What widgets are giving you this problem?

If they are custom widgets from a plugin then I suggest digging into the plugin's code, not your theme to find the problem.

If this problem is presenting itself with default widgets... well then I would first test if this is happening with other themes. If it is, then you possibly have some other plugin interfering. If it does NOT happen with other themes, well... then I guess I would have to see the whole theme and run it through step tracing and see what could possibly be stopping changes in the backend from being saved.


Matt Taylor comments:

This issue happens regardless of which widgets are used. I have tried both custom and WP default to no avail.


Eddie Moya comments:

Ok, so to sum this up...


You cant save changes to widgets in the wordpress backend widget editor. The problem happens only on this theme, and even when you deactivate all other plugins?

I seem to recall a similar problem once upon a time. However mine ended up being a problem with the widget itself, not the theme. If you have isolated this to the point where it can be other other than the theme, I think we need to consider looking at the entire theme and running it.


Matt Taylor comments:

Is it possible that the array is malformed?


Eddie Moya comments:

Sure, it can be any of many things. Without being able to run the theme through netbeans and trace the arrays, it would take too long to figure out by guessing. If you can post the theme somewhere for us to download, that would help speed things up.