Make WordPress Core

Opened 8 years ago

Last modified 10 months ago

#37928 new enhancement

add `pre_add_option` filter

Reported by: flixos90's profile flixos90 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch needs-refresh
Focuses: Cc:

Description

get_option() and update_option() already have filters to short-circuit their respective processes, so I think a similar filter should be added to add_option() as well.

Attachments (2)

37928.diff (1.2 KB) - added by flixos90 8 years ago.
37928.2.diff (1.0 KB) - added by flixos90 8 years ago.

Download all attachments as: .zip

Change History (10)

@flixos90
8 years ago

#1 @flixos90
8 years ago

37928.diff is a first take on introducing the filter. I used null as a return value to skip since null is very unlikely to be stored as option. However, it is not a perfect solution I think. I was wondering whether it might make sense to declare a WP_DEFAULT_VALUE constant, fill it with some random value, and use that in such cases.

#2 @flixos90
8 years ago

  • Keywords has-patch added; needs-patch removed

#3 follow-up: @jipmoors
8 years ago

I would prefer to have a separate filter to allow a short-cicuit instead of abusing a return value to imply such a behaviour.

And a random value really sounds like a terrible idea :)

#4 in reply to: ↑ 3 @flixos90
8 years ago

  • Keywords needs-refresh added

Replying to jipmoors:

I would prefer to have a separate filter to allow a short-cicuit instead of abusing a return value to imply such a behaviour.

Definitely makes sense. I patched this way too quickly. :)

@flixos90
8 years ago

#5 @flixos90
8 years ago

37928.2.diff adds a dedicated filter to short-circuit the process of adding an option.

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


8 years ago

#8 @gerardreches
10 months ago

Was this enhancement never added?

Note: See TracTickets for help on using tickets.