WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#34942 closed enhancement (duplicate)

Add a filter for $index in dynamic_sidebar() function

Reported by: ShinichiN Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6
Component: Widgets Keywords: has-patch
Focuses: Cc:
PR Number:

Description

It would be nice if plugins can filter the index (the name of the widget area) in dynamic_sidebar() function.

While there are a lot of hooks inside this function, it is not possible to switch an area to another.

A lot of plugins try to offer WordPress users the ability to create and switch areas dynamically, but all of them (,which I found) has to offer a custom template tag to render the desired widget area. Users need to edit their files like sidebar.php.

Attachments (2)

34942.diff (978 bytes) - added by ShinichiN 4 years ago.
Adds a filter "dynamic_sidebar_index"
34942-2.diff (1.1 KB) - added by ShinichiN 4 years ago.
Includes the set of widget areas with allocated widgets as an argument. Implement @azaozz 's comment.

Download all attachments as: .zip

Change History (9)

@ShinichiN
4 years ago

Adds a filter "dynamic_sidebar_index"

#1 @ShinichiN
4 years ago

  • Keywords has-patch added

#2 @azaozz
4 years ago

Wondering if it will be a bit more useful if the filter is after $sidebars_widgets = wp_get_sidebars_widgets(); and then pass $sidebars_widgets as argument to it.

@ShinichiN
4 years ago

Includes the set of widget areas with allocated widgets as an argument. Implement @azaozz 's comment.

#3 follow-up: @ShinichiN
4 years ago

@azaozz Do we still need the other 2 arguments, $wp_registered_sidebars and $wp_registered_widgets when we have the $sidebars_widgets, which is a combination of the 2?

#4 in reply to: ↑ 3 @DrewAPicture
4 years ago

Replying to ShinichiN:

@azaozz Do we still need the other 2 arguments, $wp_registered_sidebars and $wp_registered_widgets when we have the $sidebars_widgets, which is a combination of the 2?

Yes, we still need the other two. $wp_registered_sidebars and $wp_registered_widgets are stored in memory and $sidebars_widgets is derived from the database. Fun times.

#5 @SergeyBiryukov
4 years ago

  • Component changed from General to Widgets

#6 @SergeyBiryukov
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #33915.

@ShinichiN, could you add your patch to the other ticket? Thanks!

#7 @ShinichiN
4 years ago

@SergeyBiryukov I will.

@DrewAPicture Thank you for the clarification.

Note: See TracTickets for help on using tickets.