WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#32987 new enhancement

Adding filters to allow alternate sidebar storage for registered sidebars

Reported by: welcher Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.3
Component: Widgets Keywords: has-patch dev-feedback
Focuses: Cc:

Description

Currently sidebars are stored in the sidebars_widgets option in the database which for site with many sidebars can be very inefficient.

I would like to propose a means of being able to change how the information is stored.

I have introduced two filters that allow a user to have access to the information being saved or requested. This is backwards compatible but gives the option of using, for example ,a post type to store the data.

Attachments (6)

32987.diff (2.0 KB) - added by welcher 3 years ago.
32987.2.diff (2.5 KB) - added by welcher 3 years ago.
Updated patch for better hook names, inline doc corrections and a more integrated approach to retrieving the widgets
32987.3.diff (2.6 KB) - added by wonderboymusic 3 years ago.
32987.4.diff (2.6 KB) - added by welcher 3 years ago.
Updated docs and corrected logic for checking for boolean filter results
32987-tests.diff (2.0 KB) - added by welcher 3 years ago.
Adding unit tests
32987-tests.2.diff (2.9 KB) - added by welcher 3 years ago.
Updated unit tests with doc block and better method naming

Download all attachments as: .zip

Change History (16)

@welcher
3 years ago

#2 @welcher
3 years ago

  • Keywords has-patch dev-feedback added

#3 @DrewAPicture
3 years ago

Some notes:

  • These filter names need a little bit of work. They evaluate as booleans but the filter names don't really reflect that
  • If we do end up keeping the boolean returns by default, the check on what is currently the 'sidebars_widgets_custom_storage' hook could just easily be a strict boolean check

On the hook docs:

  • The duplicate hook comment should be one line, e.g. /** This filter is documented in ... */
  • The duplicate hook comment only needs to mention the path to the file
  • Hook doc summaries should end with a period
  • @since versions should be the 3-digit x.x.x style, e.g. 4.4.0
  • Multiple types in phpDoc should use a pipe, e.g. |
Last edited 3 years ago by DrewAPicture (previous) (diff)

#4 follow-up: @westonruter
3 years ago

@welcher As opposed to introducing new filters, why not just utilize pre_option_sidebars_widgets filters?

#5 in reply to: ↑ 4 @welcher
3 years ago

Replying to westonruter:

@welcher As opposed to introducing new filters, why not just utilize pre_option_sidebars_widgets filters?

Currently that would be the best approach, however I like the idea of having a hook before the get_option() call happens so we can decouple the get/set process completely from the calls to the *_option methods. I think this provides more flexibility moving forward.

I also found the storage process with the pre_update_option_sidebars_widgets filter to be a little counter-intuitive as you have to return $old_value to short circuit the update_option call. .

Last edited 3 years ago by welcher (previous) (diff)

@welcher
3 years ago

Updated patch for better hook names, inline doc corrections and a more integrated approach to retrieving the widgets

This ticket was mentioned in Slack in #core by welcher. View the logs.


3 years ago

@welcher
3 years ago

Updated docs and corrected logic for checking for boolean filter results

@welcher
3 years ago

Adding unit tests

#8 @welcher
3 years ago

I have added some unit tests as per the Slack discussion. Am happy to add more or make any further changes as needed.

This ticket was mentioned in Slack in #core by welcher. View the logs.


3 years ago

@welcher
3 years ago

Updated unit tests with doc block and better method naming

This ticket was mentioned in Slack in #core by welcher. View the logs.


3 years ago

Note: See TracTickets for help on using tickets.