wp.customize.controlConstructor['hoo-multicheck'] = wp.customize.Control.extend({ // When we're finished loading continue processing ready: function() { 'use strict'; var control = this; // Init the control. if ( ! _.isUndefined( window.hooControlLoader ) && _.isFunction( hooControlLoader ) ) { hooControlLoader( control ); } else { control.initHooControl(); } }, initHooControl: function() { 'use strict'; var control = this; control.container.find( '.hoo-controls-loading-spinner' ).hide(); // Save the value control.container.on( 'change', 'input', function() { var value = [], i = 0; // Build the value as an object using the sub-values from individual checkboxes. jQuery.each( control.params.choices, function( key ) { if ( control.container.find( 'input[value="' + key + '"]' ).is( ':checked' ) ) { value[ i ] = key; i++; } }); // Update the value in the customizer. control.setting.set( value ); }); } });