[wp-hackers] Upgrading to wp_register_sidebar_widget Removes Current Widgets

David Law wp-hackers at google-adsense-templates.co.uk
Tue Aug 23 15:00:39 UTC 2011


Upgrading a theme to remove depreciated functions and using
wp_register_sidebar_widget to replace register_sidebar_widget
(depreciated) and the upgrade is removing the current widgets when I
upgrade sites running the theme.

Made a lot of changes to the themes code in the update but 100% sure
this is the cause of the issue. As a test replaced the code of one
widget, the 1st code snippet (old code) below to the 2nd code widget
(new code) or the 3rd code snippet (newer code)  below  (so two tests
with updated code) and the widget was removed from the sidebar which
confirms it must be the widget code upgrade.

The theme has widgets with code:

Old code

<?php
function st_Recent_Articles() { ?>
<span class="gat_widget"><?php _e('Recent Articles'); ?></span>
<ul>
<?php wp_get_archives('type=postbypost&limit=12'); ?>
</ul>
<?php } register_sidebar_widget(__('6GAT Recent Articles'),
'st_Recent_Articles');
?>

New code

<?php
function st_Recent_Articles() { ?>
<span class="gat_widget"><?php _e('Recent Articles'); ?></span>
<ul>
<?php wp_get_archives('type=postbypost&limit=12'); ?>
</ul>
<?php } wp_register_sidebar_widget('st_Recent_Articles','6GAT Recent
Articles','st_Recent_Articles');
?>

Newer code :-)

<?php function st_Recent_Articles() { ?>
<span class="gat_widget">Recent Articles</span>
<ul>
<?php wp_get_archives('type=postbypost&limit=12'); ?>
</ul>
<?php } wp_register_sidebar_widget(
'st_Recent_Articles',
'6GAT Recent Articles',
'st_Recent_Articles',
array(
'description' => 'Recent Articles'
)
);
?>

When the new themes code is uploaded all the themes custom widgets
that have been dragged and dropped to a sidebar are removed and have
to be readded. Widgets from plugins are unaffected.

The tests mentioned above confirms it much be this code change.

Would this be considered a bug or have I got my code wrong for the
update?

Thanks.

David
-- 
http://www.stallion-theme.com/ Stallion WordPress SEO Theme
http://www.stallion-theme.com/stallion-wordpress-seo-plugin Stallion
WordPress SEO Plugin


More information about the wp-hackers mailing list