[wp-trac] [WordPress Trac] #25368: Add temp hooks for Widgets UI Refresh plugin-as-feature
WordPress Trac
noreply at wordpress.org
Sat Sep 21 08:57:24 UTC 2013
#25368: Add temp hooks for Widgets UI Refresh plugin-as-feature
-------------------------+-----------------------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: 3.0
Severity: normal | Keywords: has-patch
-------------------------+-----------------------------
In the Widgets UI Refresh feature-as-plugin group, one of the things we've
discussed is using the Customizer to manage the widgets: to add them, edit
them, re-arrange them, and remove them. In order for a widget to be
draggable into the Customizer preview to drop onto a sidebar, there must
first be a sidebar container element to serve as the drop zone.
Unfortunately, the `dynamic_sidebar` action only fires if there are
widgets populating that sidebar (and in fact, it fires once per widget as
they are looped over). If a sidebar is empty you cannot introspect where
the sidebar is located in the template. Similarly to `dynamic_sidebar` is
`is_active_sidebar`, which theme authors may use to wrap an element
containing the `dynamic_sidebar`, but this function has no filter at all.
So we need a total of 4 temp hooks added:
* `temp_is_active_sidebar`
* `temp_dynamic_sidebar_did_one` — filter to make sure `dynamic_sidebar`
returns true, as otherwise fallback content may be rendered.
* `temp_before_dynamic_sidebar`
* `temp_after_dynamic_sidebar`
With these hooks in place, it is then possible for a plugin to force a
sidebar to appear and then to create a widget drop-zone:
{{{
add_action( 'customize_preview_init', function () {
add_filter( 'temp_is_active_sidebar', '__return_true' );
add_filter( 'temp_dynamic_sidebar_did_one', '__return_true' );
add_action( 'temp_before_dynamic_sidebar', function ( $index ) {
printf( '<div class="%s" data-index="%s">', 'widget-drop-
zone', esc_attr( $index ) );
} );
add_action( 'temp_after_dynamic_sidebar', function ( $index ) {
printf( '</div><!-- /.widget-drop-zone.%s -->', $index );
} );
} );
}}}
Patch has been attached to this ticket, and commits for this feature have
also been pushed to GitHub: https://github.com/x-team/WordPress/compare
/widgets-ui-refresh-temp-hooks?w=1
/cc @shaunandrews
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25368>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list