fields[] = $args; return $args; } /** * 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', URL::get_from_path( __DIR__ . '/postMessage.js' ), [ 'jquery', 'customize-preview', 'wp-hooks' ], '1.0.6', true ); $fields = $this->fields; // Compatibility with v3 API. if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) { $fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields ); } $data = []; 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'] ) ) { $data[] = $field; } } wp_localize_script( 'kirki_auto_postmessage', 'kirkiPostMessageFields', $data ); $extras = apply_filters( 'kirki_postmessage_script', false ); if ( $extras ) { wp_add_inline_script( 'kirki_auto_postmessage', $extras, 'after' ); } } }