Opened 9 years ago
Last modified 8 months ago
#20439 reopened enhancement
Introduce __return_one function
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | close |
Focuses: | Cc: |
Attachments (1)
Change History (9)
#2
@
9 years ago
I've had to create my own __return_zero()
in order to set defaults (which cannot be overwritten by users) with filters pre_option_default_pingback_flag
, pre_option_enable_xmlrpc
, pre_option_use_trackback
, etc., but I could just as easily see someone wanting to force open certain options as well with a __return_one()
, which is why I decided to add this patch. Many of the options listed at http://codex.wordpress.org/Option_Reference use 0 or 1 as their value, so quick returns for their filter would be at least useful to some.
#3
@
9 years ago
We use 1 and 0 because it is easy to store in a DB field. In reality you can simply use __return_true
and __return_false
.
#4
@
9 years ago
It should be noted that will work for most situations. blog_public and a few other options could hypothetically have meaningful values > 1.
#5
in reply to:
↑ 1
@
9 years ago
Replying to scribu:
I would argue that even
__return_zero()
isn't common enough.
I just had a pretty good use case for __return_zero()
— I wanted to hook into pre_option_{$option} and turn an option off. Normally I would use __return_false
but that is the value passed in that needs to be changed for the bypass to work (rather than null). So 0 it is.
#6
@
7 years ago
- Milestone Awaiting Review deleted
- Resolution set to maybelater
- Status changed from new to closed
#7
@
8 months ago
- Resolution maybelater deleted
- Status changed from closed to reopened
- Version set to trunk
I am aware this is old but I have lost track of the number of times I had to create a dummy function for this purpose when the calling code does a typecheck (true !== 1).
So I vote for this to be added as its simple and will get a lot of use I feel. as for __return_zero
, I have used this plenty of times as well.
Let's not get carried away with these.
I would argue that even
__return_zero()
isn't common enough.