Make WordPress Core

Opened 3 years ago

Closed 5 weeks ago

Last modified 4 days ago

#56870 closed enhancement (fixed)

Introduce a general `pre_site_option` filter in `get_network_option()`

Reported by: drivingralle's profile Drivingralle Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: has-patch has-unit-tests commit
Focuses: multisite Cc:

Description

Similar to the new filter from #37930 I suggest to also add a general pre_site_option filter.

I attach a patch to add the filter.
Don't know how to create the test for it.

Attachments (1)

Introduce_a_general_`pre_site_option`_filter_in_`get_network_option()`.patch (1.5 KB) - added by Drivingralle 3 years ago.

Download all attachments as: .zip

Change History (12)

#1 @hellofromTonya
3 years ago

  • Version trunk deleted

Removing trunk as the Version given this is a request for a new filter.

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


2 months ago

#3 @audrasjb
2 months ago

  • Milestone changed from Awaiting Review to 6.9

As per today's devchat: this proposal sounds quite reasonable given we already introduced pre_option previously.

I'm moving it to milestone 6.9. Patch refresh coming soon.

This ticket was mentioned in PR #10030 on WordPress/wordpress-develop by @audrasjb.


2 months ago
#4

  • Keywords has-patch added

This ticket was mentioned in PR #10053 on WordPress/wordpress-develop by @nimeshatxecurify.


8 weeks ago
#5

  • Keywords has-unit-tests added

Adding unit test and making changes in @audrasjb 's PR (#10030) as per suggestions from @jorbin

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


6 weeks ago

#7 @welcher
6 weeks ago

@audrasjb we're getting close to the 6.9 Beta 1 cutoff, is there anything else that needs to happen on this ticket to get it over the finish line?

#8 @jorbin
5 weeks ago

  • Keywords commit added

There is a minor update to the test as noted by @westonruter on the PR. Otherwise https://github.com/WordPress/wordpress-develop/pull/10053/files looks ready. Planning to commit this in the next few days unless there is an objection.

#9 @rollybueno
5 weeks ago

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/10053

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.2
  • Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 140.0.0.0
  • OS: Linux
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 21.7.0
    • Test Reports 1.2.0

Actual Results

  1. ✅ pre_site_option filter correctly
     add_filter( 'pre_site_option', function( $pre, $option, $network_id ) { if ( 'site_name' === $option ) { return 'Filtered Network Name'; } return $pre; }, 10, 3 ); // Output: "Filtered Network Name" echo get_network_option( get_current_network_id(), 'site_name' ); 

Additional Notes

  1. Executed the following commands in a local wordpress-develop clone:
     git fetch upstream pull/10053/head:pr-10053 git checkout pr-10053 npm run env:restart 
  2. Patch successfully introduces the general pre_site_option hook for multisite.
  3. Dynamic filter pre_site_option_{$option} remains functional.

Supplemental Artifacts

⚠️⚠️ Test unit result fails though
https://i.imgur.com/u21a5gX.png

Last edited 5 weeks ago by rollybueno (previous) (diff)

#10 @johnjamesjacoby
5 weeks ago

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

In 60959:

Networks and Sites: add a general pre_site_option filter to get_network_option().

This change brings get_network_option() up-to-speed with get_option() by adding a more generalized way to short-circuit its return value.

It also introduces 2 new unit tests: one to mirror an existing pre_option test, and another to confirm that this new filter is working as intended.

Props audrasjb, Drivingralle, johnjamesjacoby, jorbin, nimeshatxecurify, rollybueno, shailu25, welcher, westonruter.

See #37930, r54145.

Fixes #56870.

#11 @desrosj
4 days ago

The miscellaneous developer-focused changes developer note mentioned the new pre_site_option hook introduced in [60959] but did not cover its usage in depth: https://make.wordpress.org/core/2025/11/17/miscellaneous-developer-focused-changes-in-6-9/.

Note: See TracTickets for help on using tickets.