[wp-trac] [WordPress Trac] #37930: Introduce a general `pre_option` filter in `get_option()`

WordPress Trac noreply at wordpress.org
Fri Mar 24 02:14:52 UTC 2017


#37930: Introduce a general `pre_option` filter in `get_option()`
--------------------------------+------------------------------
 Reporter:  flixos90            |       Owner:
     Type:  enhancement         |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:
 Severity:  normal              |  Resolution:
 Keywords:  has-patch           |     Focuses:
--------------------------------+------------------------------

Comment (by desrosj):

 I looked at this one first of the three, of course (#37929 and #37928),
 and the other two check for `null`.

 I did some digging because I feel like most of the "short circuit" filters
 I have used in core have a truthy check for `false !== $value` instead of
 `null`. It seems there is a pretty equal number throughout core for each.
 Here are some examples.

 Truthy check
 - Shortcodes: [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/shortcodes.php#L338]
 - `pre_get_lastpostmodified`:
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/post.php#L5571]
 - `pre_option_{$option}` above current new filter.
 - `pre_site_option_{$option}`:
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/option.php#L1124]
 - `pre_site_transient_{$transient}`:
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/option.php#L1594]
 - `pre_transient_{$transient}`:
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/option.php#L641]
 - When retrieving `WP_Cache` items this is appropriate.

 Locations using a `null !== $value` check:
 - `wp_save_image_editor_file`:
 [https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes
 /image-edit.php#L317]
 - `wp_save_image_file`: [https://core.trac.wordpress.org/browser/trunk/src
 /wp-admin/includes/image-edit.php#L344]
 - 'pre_get_table_charset':
 [https://core.trac.wordpress.org/browser/trunk/src/wp-includes/wp-
 db.php#L2451]
 - `pre_get_blogs_of_user`:
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/user.php?rev=37326#L594]
 - `pre_delete_post`: [https://core.trac.wordpress.org/browser/trunk/src
 /wp-includes/post.php#L2446]

 I think that we should at least remain consistent in the options API.

 Looking through `options.php`, I see the following:

 Truthy checks already in core:
 - `pre_site_transient_{$transient}`
 - `pre_option_{$option}`
 - `pre_get_option` - '''addressed in this patch'''
 - `pre_transient_{$transient}`,
 - `pre_site_option_{$option}`

 There are currently only two `null !== $value` or `! is_null()` checks in
 `options.php`, and both follow database queries that more than likely
 return `null`.

 I vote for `false !==` checks, unless there are reasons why `null` is
 beter that I don't know of.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37930#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list