保存WordPress小部件实例选项,而不使用保存按钮保存实例值

I have a wordpress widget that has a option list of 'div ids' for a user to choose. Originally this option list was 0 indexed. However it needed to change to name values rather than 0 indexed. The name index is now working perfectly. The trick that I would like to see if it is possible is to updating the current instances that are on the sites with the new named value, swapping it will the 0 indexed value. I tried to use the following:

private function change_numeric_indexes_to_names( $ids_id, $widget_id ) {

    $settings = $this->get_settings();

    /*
     * If the saved div id is indexed using an integer
    * the change it and same it as a name string. This
    * is needed as the old div id implementation used numeric indexes.
    * To solve the issue if the number / position of the ids changed thus
    * rendering the wrong div id. This will need to run only once as subsequent
    * calls to the same ad / div id will use a name string instead.
    */

    if ( is_numeric( $ids_id ) ) {

        $settings['id'] = $ids_id;

        $ids_id = [ $ids_id ];

    }

    $this->update_widgets_ids_with_names( $ids_id ); // Updates the stored widget values with new named id;

    return $ids_id;


}

private function update_widgets_ids_with_names( $id ) {

    /*
     * Get this instances options
     */
    $widget_options_all = get_option( $this->option_name );
    $old_instance = $widget_options_all[ $this->number ];

    $new_instance = $old_instance;


    $new_instance['id'] = $id;

    return $this->update( $new_instance, $old_instance );


}

The change_numeric_indexes_to_names() method is called in the widget method. As it is not running in the form method I am trying to bypass having to go into every website instance, open each widget and save. Instead I'd like to switch the stored database option values after checking for numeric ids.

As you can see with the update_widgets_ids_with_names() method that I tried hooking into the update method. But going into the wp-includes/default-widgets.php I see that that option merely updates the object but no save value occurs.

Can you suggest a way to save the values so each individual instance of the widget will be updated when the site is loaded?

Regards, Steve

So I figured it out.

in the update_widgets_ids_with_names( $id_now_as_name ) method, it took adding the $this->update_callback();. This is a dangerous method because it can really screw things up, but in my case it seems to work cleanly and well. Here is the updated method that works:

private function update_widgets_ids_with_names( $id_now_as_name ) {

    /*
     * Get this instances options
     */
    $widget_options_all = get_option( $this->option_name );
    $old_instance = $widget_options_all[ $this->number ];

    $new_instance = $old_instance;

    $new_instance['id'] = $id_now_as_name;

    $this->update_callback(); // this processes the widget settings prior to the update function, it is needed.

    return $this->update( $new_instance, $old_instance );


}

Regards, Steve