( isset( $js_vars['element'] ) ) ? sanitize_text_field( $js_vars['element'] ) : '', 'function' => ( isset( $js_vars['function'] ) ) ? esc_js( $js_vars['function'] ) : '', 'property' => ( isset( $js_vars['property'] ) ) ? esc_js( $js_vars['property'] ) : '', 'units' => ( isset( $js_vars['units'] ) ) ? esc_js( $js_vars['units'] ) : '', 'prefix' => ( isset( $js_vars['prefix'] ) ) ? esc_js( $js_vars['prefix'] ) : '', 'suffix' => ( isset( $js_vars['prefix'] ) ) ? esc_js( $js_vars['prefix'] ) : '', ); $units = ( ! empty( $js_vars['units'] ) ) ? " + '" . $js_vars['units'] . "'" : ''; $prefix = ( ! empty( $js_vars['prefix'] ) ) ? "'" . $js_vars['prefix'] . "' + " : ''; $suffix = ( ! empty( $js_vars['suffix'] ) ) ? " + '" . $js_vars['suffix'] . "'" : ''; $script .= 'wp.customize( \'' . Kirki_Field_Sanitize::sanitize_settings( $args ) . '\', function( value ) {'; $script .= 'value.bind( function( newval ) {'; if ( 'html' == $js_vars['function'] ) { $script .= '$(\'' . $js_vars['element'] . '\').html( newval );'; } else { $script .= '$(\'' . $js_vars['element'] . '\').' . $js_vars['function'] . '(\'' . $js_vars['property'] . '\', ' . $prefix . 'newval' . $units . $suffix . ' );'; } $script .= '}); });'; } } self::$postmessage_script .= $script; } /** * Format the script in a way that will be compatible with WordPress. * * @return void (echoes the script) */ public function enqueue_script() { if ( ! self::$script_added && '' != self::$postmessage_script ) { self::$script_added = true; echo ''; } } }