PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | php/Utils/options.php +25 -1 3.10.04.0.0-beta.2 View file →
@@ -7,8 +7,32 @@
7 7
8 8 namespace Code_Snippets\Utils;
9 9
10 10 /**
11 + * Resolve whether an operation should apply to the network or the current site.
12 + *
13 + * A null value is resolved from the current admin screen, so a caller that has
14 + * no explicit preference follows whichever admin the request is being made from.
15 + *
16 + * @param bool|null $network Whether the operation is network-wide, or null to infer it.
17 + *
18 + * @return bool
19 + */
20 +function validate_network_param( ?bool $network = null ): bool {
21 + // If multisite is not active, then assume the value is false.
22 + if ( ! is_multisite() ) {
23 + return false;
24 + }
25 +
26 + // If the value is null, try to base it on the current admin page.
27 + if ( is_null( $network ) && function_exists( 'is_network_admin' ) ) {
28 + return is_network_admin();
29 + }
30 +
31 + return (bool) $network;
32 +}
33 +
34 +/**
11 35 * Retrieves an option value based on an option name from either the current site or the current network.
12 36 *
13 37 * @param bool $network Whether to get a network-wide option.
14 38 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
@@ -22,9 +46,9 @@
22 46 : get_option( $option, $default_value );
23 47 }
24 48
25 49 /**
26 - * Adds a new option option value for either the current site or the current network.
50 + * Adds a new option value for either the current site or the current network.
27 51 *
28 52 * @param bool $network Whether to get a network-wide option.
29 53 * @param string $option Name of the option to add. Expected to not be SQL-escaped.
30 54 * @param mixed $value Option value, can be anything. Expected to not be SQL-escaped.