for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Automatic postMessage scripts calculation for Kirki controls.
*
* @package Kirki
* @category Modules
* @author Aristeides Stathopoulos
* @copyright Copyright (c) 2016, Aristeides Stathopoulos
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT
* @since 2.4.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
* Adds styles to the customizer.
class Kirki_Modules_PostMessage {
* Constructor.
* @access public
public function __construct() {
add_action( 'customize_preview_init', array( $this, 'postmessage' ) );
* Enqueues the postMessage script
* and adds variables to it using the wp_localize_script function.
* The rest is handled via JS.
public function postmessage() {
wp_enqueue_script( 'kirki_auto_postmessage', trailingslashit( Kirki::$url ) . 'modules/postmessage/postmessage.js', array( 'customize-preview' ), false, true );
$js_vars_fields = array();
$fields = Kirki::$fields;
foreach ( $fields as $field ) {
if ( isset( $field['transport'] ) && 'postMessage' === $field['transport'] && isset( $field['js_vars'] ) && ! empty( $field['js_vars'] ) && is_array( $field['js_vars'] ) && isset( $field['settings'] ) ) {
$js_vars_fields[ $field['settings'] ] = $field['js_vars'];
wp_localize_script( 'kirki_auto_postmessage', 'jsvars', $js_vars_fields );