WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#15054 closed enhancement (worksforme)

Add filter hook to get_option

Reported by: leogermani Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: General Keywords: has-patch
Focuses: Cc:

Description

Add a filter hook to get_option function to allow plugins to filter options.

Current filter 'pre_option_$option' does not pass the option name as a parameter, so you need to have one specific function for each option you want to filter. This does not allow you to filter dynamically created options, nor lets you filter all options if you want to do so.

Attachments (1)

get_option_filter.patch (1.0 KB) - added by leogermani 10 years ago.
add filter to get_option function

Download all attachments as: .zip

Change History (7)

@leogermani
10 years ago

add filter to get_option function

#1 @scribu
10 years ago

  • Keywords has-patch added; get_option filter hook removed

#2 @bireme
10 years ago

+1 this can be very useful

#3 @Mvied
10 years ago

+1 Definitely need this.

#4 @chrisbliss18
10 years ago

  • Cc gaarai@… added

Since this does have performance implications, can you clarify the value of adding this filter with some examples of when code would need to be able to filter any and all options even when it doesn't know what the options are.

#5 @westi
10 years ago

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

If you need context please use current_filter().

#6 @leogermani
10 years ago

I wanted it to use in a multi language plugin Im writing.

For instance, I want to filter all options, and, if Im visiting other language than the default, I will return 'myplugin_$language_$option' value instead of $option value.

Using current_filter() is a valid workaround. The only thing is that I have to do a foreach in all existing opions to add a filter for each one.

Anyways, current_filter is fine

cheers

Note: See TracTickets for help on using tickets.