reduxframework / customizer-integration

0 stars 0 forks source link

Customizer API partial /selective refresh #22

Open MihaiCraciun opened 6 years ago

MihaiCraciun commented 6 years ago

Hi,

I'm trying to get an existing Redux field to work with selective refresh in customizer but can't find any documentation or examples on the web.

I've managed to figure out that the 'id' used by $wp_customize->selective_refresh->add_partial() is $opt_name['field-id'] and got the Edit button to appear and link to the correct section in the Customizer, but that's as far as I got.

I'm trying to get a sortable field type to work but I have no clue what to do to stop it from refreshing the page and to reflect the value of the checkbox.

function my_customizer_options(WP_Customize_Manager $wp_customize) {
  $wp_customize->add_setting( 'my_opt[my-sortable-field]' , array(
    'transport' => 'postMessage'
  ) );
  $wp_customize->selective_refresh->add_partial('my_opt[my-sortable-field]', [
    'selector' => '.sortable_container',
    'render_callback'     => 'callback_fn',
  ]);
}

add_action('customize_register', 'my_customizer_options');

and the callback

function callback_fn(){
  $my_opt = get_option('my_opt');
  $items = $my_opt['my-sortable-field'];
  foreach ($items as $key => $value){
    echo 'item: '. $key .' ; value : '.$value .'<br>';
  }
}

and outputting with

<div class='sortable-container'>
   <?php callback_fn(); ?>
</div>