Change WordPress plugin widget `id_base` without breaking widget

I have developed a WordPress plugin, and one of the widgets in the plugin has a spelling error in the $id_base param of

I have developed a WordPress plugin, and one of the widgets in the plugin has a spelling error in the $id_base param of the parent::__construct method called in the Widget constructor. It seems that fixing the spelling error removes any instance of the widget currently in place. Is it possible to change the $id_base for the widget without breaking current instances of the widget?

I have developed a WordPress plugin, and one of the widgets in the plugin has a spelling error in the $id_base param of the parent::__construct method called in the Widget constructor. It seems that fixing the spelling error removes any instance of the widget currently in place. Is it possible to change the $id_base for the widget without breaking current instances of the widget?

Share Improve this question asked Oct 7, 2019 at 18:27 Brady CharronBrady Charron 213 bronze badges 3
  • You're going to need to change the sidebar widgets option (an array of sidebars and widget IDs in the database) and the widget's instances (an array of widget's instance settings in the database). – Sally CJ Commented Oct 8, 2019 at 16:14
  • @SallyCJ That is an option that I was considering, but didn't want to have to mess with the DB. Would you suggest doing that with some sort of migration or update script in a future release of the plugin? – Brady Charron Commented Oct 10, 2019 at 12:57
  • I would, but developers/users already using the plugin may rely upon the old $id_base, so you'd need to make sure they're aware of the $id_base change (like a grace period for letting them update their code). So either keep the typo.. change it.. or maybe as the answer suggested, deprecate the old widget. – Sally CJ Commented Oct 11, 2019 at 4:35
Add a comment  | 

1 Answer 1

Reset to default 0

You can deprecate the whole function which will probably be quite hard to do in your situation but it is possible with some work:

You could check for both, but load the new one for future installs:

function badly_named() {

    __doing_it_wrong( 'badly_named', 'This method has been deprecated in favor of better_named_function' );

    /**
     * Call the better named method
     */
     better_named_function();
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745098964a4611157.html

相关推荐

  • Change WordPress plugin widget `id_base` without breaking widget

    I have developed a WordPress plugin, and one of the widgets in the plugin has a spelling error in the $id_base param of

    17小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信