[wp-trac] [WordPress Trac] #29790: Widgets don't know the widget area context there in

WordPress Trac noreply at wordpress.org
Wed Oct 1 23:02:37 UTC 2014


#29790: Widgets don't know the widget area context there in
------------------------------+--------------------------------------------
 Reporter:  ruud@…            |       Owner:
     Type:  enhancement       |      Status:  new
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Widgets           |     Version:  trunk
 Severity:  normal            |  Resolution:
 Keywords:  has-patch dev-    |     Focuses:  accessibility, administration
  feedback                    |
------------------------------+--------------------------------------------

Comment (by westonruter):

 I was confused when I first responded to this, so please disregard my
 comment about `$args`.

 Replying to [comment:6 ruud@…]:
 > Another thought: how about a widget being able to request its current
 sidebar via a new function?

 You can actually find out which sidebar a widget belongs to by adding the
 following to a widget's `update`, `form`, or `widget` callbacks (any
 method of the class extending `WP_Widget`):

 {{{
 #!php
 $active_sidebar_id = null;
 foreach( wp_get_sidebars_widgets() as $sidebar_id => $widgets_ids ) {
         if ( in_array( $this->id, $widgets_ids ) ) {
                 $active_sidebar_id = $sidebar_id;
                 break;
         }
 }
 }}}

 Beware of using this in the admin, however, since widgets can be dragged
 around to other widget areas.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29790#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list