Customize Inline Editing
In WordPress 4.5 the selective refresh framework was introduced in core. One of the key concepts in this framework is the “partial”, the region in a document which is selectively refreshed when a related setting is modified. This means that one or more settings are linked with a given element in the
In WordPress 4.5 the selective refresh framework was introduced in core. One of the key concepts in this framework is the “partial”, the region in a document which is selectively refreshed when a related setting is modified. This means that one or more settings are linked with a given element in the preview. When selective refresh was first was introduced it supported the ability for a user to “shift click” on a partial to jump to and focus on the related control in the pane. In WordPress 4.7 this was then enhanced with visible edit shortcuts so that users could click (touch even) on the icon to be able to reveal the control in the pane.
The Customize Inline Editing plugin builds on edit shortcuts by allowing the setting to be modified inline via direct manipulation in the preview without having focus removed and placed on the controls pane. This is particularly useful on mobile devices on small screens where a user cannot both see the controls and preview at the same time, as can be compared here:
Inline editing in this way is also helpful for accessibility since keyboard focus remains in the preview at the element being edited, as can be seen in this demonstration of inline editing on a desktop browser:
This plugin provides one example implementation of inline editing this can be accomplished in the customizer. Version 0.1 of this plugin from 2014 was a precursor in some ways to selective refresh, specifically in regards to how CSS selectors are associated with customizer settings.
Themes can opt-in to support this plugin’s inline editing within the customizer by assigning the appropriate type to the registered partials:
add_action( 'customize_register', function( $wp_customize ) { $opt_in_partials = array_filter( array( $wp_customize->selective_refresh->get_partial( 'blogname' ), $wp_customize->selective_refresh->get_partial( 'blogdescription' ) ) ); foreach ( $opt_in_partials as $partial ) { $partial->type = 'inline_editable'; } }, 100 );
Click on the edit shortcut to begin editing the element, with keyboard focus then given to the editable element. If the value has a server-side rendered value (e.g. where PHP filters like wptexturize apply to improve typography), the raw value will be supplied when editing starts. Editing can be completed by clicking out of the editable element, tabbing out of the element (blurring it), or clicking the edit icon which then appears as a “done” checkmark icon. You may also shift-click on an element to edit it.
Currently only basic text fields can currently be edited; styling and any tags added to contentEditable areas will be stripped out. Eventually rich text formatting may be allowed, specifically for integrations with the Text widget (via JS Widgets ) or post content (via Customize Posts ).