Let's say i am having three sections in wordpress customizer. I'm enqueueing the js file with admin_enqueue_scripts action.(should i enqueue it with customize_controls_enqueue_scripts ? )
I'm creating an array using get_option('section_names') and then using foreach loop to create the three sections.
in js file i'm using jquery UI's sortable('serialize') and sending the new order of the sections using ajax to a php file . That php file then uses update_option('option_name', $_POST['list_items']) to update the database.
So the database is getting updated whenever the change in order of the sections is happening. But what i want is the permanent change(database change) should happen upon clicking the publish button. What is the procedure?
Here is the code below that is being used to populate sections in customizer(kirki toolkit is being used):
$sortable_sections = get_option('sortable_sections');
foreach ($sortable_sections as $sortable_section) {
Kirki::add_section( $sortable_section, array(
'title' => esc_attr__( strtoupper($sortable_section), 'airspace' ),
'description' => esc_attr__( 'Insert content about this section', 'airspace' ),
'panel' => 'frontpage_panel',
) );
}