Не обновляются данные
Решил кастомизировать настройки:
Описал секцию:
$wp_customize->add_setting( 'test_show_phone' , array( 'default' => true, 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'test_show_phone', array( 'label' => 'Показывать телефон', 'section' => 'test_site_data', 'type' => 'checkbox', ) );
Функция подключения js:
function test_customize_js(){
wp_enqueue_script('test_customizer', get_template_directory_uri() .'/assets/js/test-customize.js', array( 'test-jquery','customize-preview'), null, true);
}
add_action('customize_preview_init', 'test_customize_js');
Сам js файл:
(function( $ ) {
//Update site link color in real time...
wp.customize( 'test_link_color', function( value ) {
value.bind( function( newVal ) {
//Do stuff (newval variable contains your "new" setting data)
$('a').css('color', newVal );
} );
} );
//Update site link color in real time...
wp.customize( 'test_phone', function( value ) {
value.bind( function( newVal ) {
//Do stuff (newval variable contains your "new" setting data)
$('.test-phone span').text( newVal );
} );
} );
//Update site link color in real time...
wp.customize( 'test_show_phone', function( value ) {
value.bind( function( newVal ) {
//Do stuff (newval variable contains your "new" setting data)
false === newVal ? $('.test-phone').fadeOut() : $('.test-phone').fadeIn() ;
} );
} );
}) (jQuery);
Вызов функции в header.php:
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<?php wp_nav_menu(array(
'theme_location' => 'header_menu',
'container' => '',
'container_id' => 'navbarSupportedContent',
'menu_class' => 'navbar-nav mr-auto',
'walker' => new Test_Walker_Nav_Menu,
)); ?>
<p class="test-phone" <?php
if (false === get_theme_mod('test_show_phone')){
echo 'style="display: none;"';
} else {
echo 'style="display: block;"';
}
?>>
Телефон: <span><?php echo get_theme_mod('test_phone');?></span>
</p>
</div>
При клике на чекбокс номер телефона должен появляться, при повторном клике исчезать. Но вместо этого в консоли появляется сообщение: "Свойство MouseEvent.mozPressure является устаревшим. Для его замены используйте PointerEvent.pressure.". При этом изменения сохраняются при перезагрузке страницы, а "вживую" не работает