possible to make sections in theme customizer sortable and saveable at publish button clicked?

by seeker   Last Updated July 12, 2018 05:08 AM

We do have kirki(a theme customizer toolkit) sortable field. But i want to apply the same logic on the sections itself instead of creating another section with sortable fields. I'm using options instead of theme mods, just for better visualization right now. The things i tried so far: in functions.php I have this code below to create an option row in option table:

$sortable_sections = get_option('sortable_sections');
  if(!isset($sortable_sections) OR empty($sortable_sections)){
  add_option('sortable_sections', array('eat', 'pray','love'));
}

The code to create sections in a file named kirki-config.php which is required in functions.php as below

$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', 'airspace' ),
    'panel'          => 'frontpage_panel',
) );
}

the above code creates three sections with id eat, pray, love respectively.

the code in js is as below:(file hooked to admin_enqueue_scripts)

jQuery( document ).ready(function($) {

  $('#sub-accordion-panel-frontpage_panel').sortable({
    items: '.control-section-kirki-default',
    axis : 'y',
    cursor: 'move,
   update: function(){
      //here i want the code which gets the updated reordered array and passed to a  
      //php file using .sortable('serialize'), only after clicking the publish
     // button. the problem is the publish button is disabled even after
    // sections got new positions.
   }
  });
});

and in php file i want code something like as below:

$new_array = $_POST['accordion-section'];
update_option('sortable_sections', $new_array);

So there are two steps which i'm having problem to finish. 1. enabling and disabling the publish button 2.after clicking the button js variable goes to php file and updates the option.

How to achieve it, and is there any better method to achieve it?



Related Questions


Options page only saving 1 tab

Updated November 20, 2018 22:08 PM


set_theme_mod doesn't update option (help)

Updated December 12, 2016 08:03 AM

Using jQuery to retrieve customizer value

Updated January 23, 2019 09:08 AM