WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#41254 closed enhancement (fixed)

Add $default to pre_option_{$option} filter

Reported by: sc0ttkclark Owned by: DrewAPicture
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.4
Component: Options, Meta APIs Keywords: has-patch commit
Focuses: Cc:

Description

Currently the pre_option_{$option} filter passes two options:

	/**
	 * Filters the value of an existing option before it is retrieved.
	 *
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
	 *
	 * Passing a truthy value to the filter will short-circuit retrieving
	 * the option value, returning the passed value instead.
	 *
	 * @since 1.5.0
	 * @since 4.4.0 The `$option` parameter was added.
	 *
	 * @param bool|mixed $pre_option Value to return instead of the option value.
	 *                               Default false to skip it.
	 * @param string     $option     Option name.
	 */
	$pre = apply_filters( "pre_option_{$option}", false, $option );

What I believe that is needed here is to add $default as well, which could be valuable to the callback hooking in (assuming $default is not false in those use cases).

Attachments (4)

41254.patch (609 bytes) - added by sc0ttkclark 5 years ago.
41254.2.patch (828 bytes) - added by sc0ttkclark 5 years ago.
41254.3.patch (828 bytes) - added by sc0ttkclark 5 years ago.
41254.png (208.5 KB) - added by ramiy 4 years ago.

Download all attachments as: .zip

Change History (10)

@sc0ttkclark
5 years ago

@sc0ttkclark
5 years ago

@sc0ttkclark
5 years ago

#1 @sc0ttkclark
5 years ago

Example use case:

I want to override certain options (from a plugin) for sites on a multisite install to use an option that is instead network-wide.

Last edited 5 years ago by sc0ttkclark (previous) (diff)

#2 @DrewAPicture
5 years ago

  • Keywords has-patch commit added
  • Milestone changed from Awaiting Review to 4.9

I'm on board with this. Having access to the value of $default here would be useful, and actually also in the pre_site_option_{$option} hook as well.

#3 @DrewAPicture
5 years ago

  • Owner set to DrewAPicture
  • Resolution set to fixed
  • Status changed from new to closed

In 41013:

Options: Pass $default as a new parameter to the pre_option_{$option} and pre_site_option_{$option} filters.

This change standardizes some language in the parameter descriptions between the two hook docs in an effort to reduce confusion between the $pre_option pseudo-parameters and the new $default ones. $pre_option is the truthy value used to short-circuit the get_*option() call, $default is the value passed to the get_*option() returned in the event that 1) a short circuit isn't performed, 2) the option doesn't exist.

Props sc0ttkclark.
Fixes #41254.

#4 @johnbillion
4 years ago

In 41617:

Options, Meta APIs: Require a confirmation link in an email to be clicked when a user attempts to change the network
admin email address on Multisite.

This mirrors the same functionality for the site admin email address and user profile email address.

Fixes #41254

@ramiy
4 years ago

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


4 years ago

Note: See TracTickets for help on using tickets.