WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#34769 closed feature request (invalid)

Function in register_sidebar do not change value in customizer

Reported by: rinkuyadav999 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3.1
Component: Customize Keywords: has-screenshots close
Focuses: Cc:

Description

Hi

I have a function mytheme_dynamic_panel in before_widget like:

'before_widget' => '<div id="%1$s" class=" '. mytheme_dynamic_panel() . ' widget_sidebar_main clearfix %2$s">',

Actually it changes class base on user input through customizer. it works fine when i save options and visit live website.

But it do not work in live customize preview.

Thank you
Regards
Rinku Y

Attachments (1)

register_sidebar-bugs.png (151.0 KB) - added by rinkuyadav999 5 years ago.

Download all attachments as: .zip

Change History (6)

#1 @nullvariable
5 years ago

  • Keywords has-screenshots reporter-feedback added

Hi Rinku,

Can you share the code that you're using to create your option(s)?

There are two options for the transport setting, postMessage and refresh, if you're using refresh then your preview will not live update.

Here's how it works in the twentyfifteen theme:

$wp_customize->add_setting( 'header_background_color', array(
		'default'           => $color_scheme[1],
		'sanitize_callback' => 'sanitize_hex_color',
		'transport'         => 'postMessage',
	) );

And the Javascript that makes it happen, from the js/customize-preview.js file:

api.bind( 'preview-ready', function() {
		api.preview.bind( 'update-color-scheme-css', function( css ) {
			$style.html( css );
		} );
	} );

Here's some useful documentation about the postMessage option: https://developer.wordpress.org/themes/advanced-topics/customizer-api/#using-postmessage-for-improved-setting-previewing

#2 @rinkuyadav999
5 years ago

Yes i know about postMessage.

I will use 'transport' => 'postMessage', for this option. However this should also work for 'transport' => 'refresh', . Because 'transport' => 'refresh', is default and it should work in customize. I do not care about page refresh.

Please think better for it.

Thank you
Regards
Rinku Y

#3 @nullvariable
5 years ago

  • Keywords close added; reporter-feedback removed
  • Resolution set to invalid
  • Status changed from new to closed

refresh means that the change is not applied until the preview is refreshed. If you want the preview to update without a refresh you must use the postMessage option and you must implement the JavaScript to update the preview or it will not work. WordPress has no way of knowing what element in your theme must be updated without the JavaScript implementation so a refresh is needed to render the page with the change intact.

#4 @rinkuyadav999
5 years ago

  • Type changed from defect (bug) to feature request

Ok I will do so. Thank you very much.

#5 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.