I'm working on a WordPress widget right now that has dynamic checkboxes that the user can add. The checkboxes are used to create different categories for the widget. The problem I'm having is saving the state of these checkboxes (whether they're checked or not). Current I have it setup so the label is saved in the WordPress database, but when I try to save the state it just doesn't work.
Here is the full widget class:
It should be saving the state in the update method, but for some reason it's not. I tried placing the for loop both before and after the call to parseAndCombineCategories() but it didn't make a difference. If I hard code the option (i.e. $instance['categories']['selected'] = 1) it works, but if I try to set instance equal to new_instance like I do in the for loop nothing is saved in the selected node of the array. Something I actually noticed too is if there was already a 0 saved in the selected node and it runs through that loop 0 is no longer there, it's replaced with nothing.