How to add Selective Refresh in the Customizer?
Hello, In WordPress new version 4.7 added a new feature selective refresh for the customizer. like the screenshot http://prntscr.com/dm28tg
Is any option to add it dynamically on unyson? Is not, I request you to add this features in next update. Thanks
Hello,
We haven't inspected this feature yet.
I found this article by a WP dev: https://make.wordpress.org/core/2016/03/22/implementing-selective-refresh-support-for-widgets/
This plugin implements it https://wordpress.org/plugins/customize-partial-refresh/
It works around the concept of partials, using get_template_part() to render the "partial", which is simply a partial block in the frontend, with a set of options in the backend. Pretty much the same thing we have going with shortcodes, where view.php and options.php would be a partial.
The partial displays a link related to the controls in the customizer. Supposedly, the page can then refresh selectively, only the partials involved.
I haven't tried or looked anything into this, but that article seems a good start.
How to enable Selective Refresh for Unyson Customizer Options
-
Enable Twenty Seventeen theme
-
Create
{theme}/framework-customizations/theme/options/customizer.php$options = array( 'test' => array( 'type' => 'text', 'value' => 'Hello World!', 'wp-customizer-setting-args' => array( 'transport' => 'postMessage' ), ) ); -
Edit
{theme}/header.phpand at the end add:<div class="unyson-test"> <?php echo fw_get_db_customizer_option('test'); ?> </div> -
Add in
{theme}/functions.phpfunction _action_theme_partials( WP_Customize_Manager $wp_customize ) { // Abort if selective refresh is not available. if ( ! isset( $wp_customize->selective_refresh ) ) { return; } $wp_customize->selective_refresh->add_partial( 'fw_options[test]', array( 'selector' => '.unyson-test', 'render_callback' => function() { // Anonymous functions don't work in PHP 5.2! return fw_get_db_customizer_option('test'); }, ) ); } add_action( 'customize_register', '_action_theme_partials' );