Make WordPress Core


Ignore:
Timestamp:
10/17/2025 06:46:42 PM (9 months ago)
Author:
johnjamesjacoby
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r60682 r60959  
    135135         * Filters the value of all existing options before it is retrieved.
    136136         *
    137          * Returning a truthy value from the filter will effectively short-circuit retrieval
    138          * and return the passed value instead.
     137         * Returning a value other than false from the filter will short-circuit retrieval
     138         * and return that value instead.
    139139         *
    140140         * @since 6.1.0
     
    20382038        $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default_value );
    20392039
     2040        /**
     2041         * Filters the value of an existing network options before it is retrieved.
     2042         *
     2043         * Returning a value other than false from the filter will short-circuit retrieval
     2044         * and return that value instead.
     2045         *
     2046         * @since 6.9.0
     2047         *
     2048         * @param mixed  $pre             The value to return instead of the network option value. This differs
     2049         *                                from `$default`, which is used as the fallback value in the event
     2050         *                                the option doesn't exist elsewhere in get_network_option().
     2051         *                                Default false (to skip past the short-circuit).
     2052         * @param string $option          Name of the option.
     2053         * @param int    $network_id      ID of the network.
     2054         * @param mixed  $default_value   The fallback value to return if the option does not exist.
     2055         *                                Default false.
     2056         */
     2057        $pre = apply_filters( 'pre_site_option', $pre, $option, $network_id, $default_value );
     2058
    20402059        if ( false !== $pre ) {
    20412060                return $pre;
Note: See TracChangeset for help on using the changeset viewer.