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?

  • 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 Oct 8 '19 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 Oct 10 '19 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 Oct 11 '19 at 4:35

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
  • Thanks for the feedback @JohanPretorius. I'd prefer to avoid deprecating anything if possible. Another option I was considering was using the constructor for the widget deregister itself, and then register the new widget. I am not sure that this would work though. – Brady Charron Oct 10 '19 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.