<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[34777] trunk: MS: Introduce `*_network_option` functions.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/34777">34777</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/34777","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jeremyfelt</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-10-02 18:00:30 +0000 (Fri, 02 Oct 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>MS: Introduce `*_network_option` functions.
Introduces `add_network_option()`, `update_network_option()`, `get_network_option()`, and `delete_network_option()`, which use the internals previously found in the `*_site_option()` functions and allow for a network ID to enable cross network storage and retrieval of network options.
* `*_site_option()` functions are now wrappers for `*_network_option()` and will interact with options for the current network in a multisite environment.
* All will continue to fallback to `*_option()` for non-multisite uses.
* Adds basic tests for cross network storage and retrieval.
* Existing tests for `*_site_option()` functions provide coverage for storage and retrieval of current network options.
Props spacedmonkey, DrewAPicture, jeremyfelt.
See <a href="https://core.trac.wordpress.org/ticket/28290">#28290</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesoptionphp">trunk/src/wp-includes/option.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsoptionnetworkOptionphp">trunk/tests/phpunit/tests/option/networkOption.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesoptionphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/option.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/option.php 2015-10-02 16:50:53 UTC (rev 34776)
+++ trunk/src/wp-includes/option.php 2015-10-02 18:00:30 UTC (rev 34777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -972,24 +972,98 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Retrieve site option value based on name of option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieve an option value for the current network based on name of option.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.8.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.4.0 Modified into wrapper for get_network_option()
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see get_network_option()
+ *
+ * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
+ * @param mixed $default Optional value to return if option doesn't exist. Default false.
+ * @param bool $deprecated Whether to use cache. Multisite only. Always set to true.
+ * @return mixed Value set for the option.
+ */
+function get_site_option( $option, $default = false, $deprecated = true ) {
+ return get_network_option( $option, $default );
+}
+
+/**
+ * Add a new option for the current network.
+ *
+ * Existing options will not be updated. Note that prior to 3.3 this wasn't the case.
+ *
+ * @since 2.8.0
+ * @since 4.4.0 Modified into wrapper for add_network_option()
+ *
+ * @see add_network_option()
+ *
+ * @param string $option Name of option to add. Expected to not be SQL-escaped.
+ * @param mixed $value Option value, can be anything. Expected to not be SQL-escaped.
+ * @return bool False if the option was not added. True if the option was added.
+ */
+function add_site_option( $option, $value ) {
+ return add_network_option( $option, $value );
+}
+
+/**
+ * Removes a option by name for the current network.
+ *
+ * @since 2.8.0
+ * @since 4.4.0 Modified into wrapper for delete_network_option()
+ *
+ * @see delete_network_option()
+ *
+ * @param string $option Name of option to remove. Expected to not be SQL-escaped.
+ * @return bool True, if succeed. False, if failure.
+ */
+function delete_site_option( $option ) {
+ return delete_network_option( $option );
+}
+
+/**
+ * Update the value of an option that was already added for the current network.
+ *
+ * @since 2.8.0
+ * @since 4.4.0 Modified into wrapper for update_network_option()
+ *
+ * @see update_network_option()
+ *
+ * @param string $option Name of option. Expected to not be SQL-escaped.
+ * @param mixed $value Option value. Expected to not be SQL-escaped.
+ * @return bool False if value was not updated. True if value was updated.
+ */
+function update_site_option( $option, $value ) {
+ return update_network_option( $option, $value );
+}
+
+/**
+ * Retrieve a network's option value based on the option name.
+ *
+ * @since 4.4.0
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see get_option()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global wpdb $wpdb
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global wpdb $wpdb
+ * @global object $current_site
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
- * @param mixed $default Optional value to return if option doesn't exist. Default false.
- * @param bool $use_cache Whether to use cache. Multisite only. Default true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
+ * @param mixed $default Optional. Value to return if the option doesn't exist. Default false.
+ * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return mixed Value set for the option.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function get_site_option( $option, $default = false, $use_cache = true ) {
- global $wpdb;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function get_network_option( $option, $default = false, $network_id = false ) {
+ global $wpdb, $current_site;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $network_id = (int) $network_id;
+
+ // Fallback to the current network if a network ID is not specified.
+ if ( ! $network_id && is_multisite() ) {
+ $network_id = $current_site->id;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Filter an existing site option before it is retrieved.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter an existing network option before it is retrieved.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1005,17 +1079,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $pre = apply_filters( 'pre_site_option_' . $option, false, $option );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( false !== $pre )
- return $pre;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( false !== $pre ) {
+ return $pre;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // prevent non-existent options from triggering multiple queries
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $notoptions_key = "{$wpdb->siteid}:notoptions";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $notoptions_key = "$network_id:notoptions";
</ins><span class="cx" style="display: block; padding: 0 10px"> $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( isset( $notoptions[$option] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( $notoptions[ $option ] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Filter a specific default site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter a specific default network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1030,17 +1105,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_multisite() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /** This filter is documented in wp-includes/option.php */
</span><span class="cx" style="display: block; padding: 0 10px"> $default = apply_filters( 'default_site_option_' . $option, $default, $option );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value = get_option($option, $default);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $value = get_option( $option, $default );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $cache_key = "{$wpdb->siteid}:$option";
- if ( $use_cache )
- $value = wp_cache_get($cache_key, 'site-options');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $cache_key = "$network_id:$option";
+ $value = wp_cache_get( $cache_key, 'site-options' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !isset($value) || (false === $value) ) {
- $row = $wpdb->get_row( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( $value ) || false === $value ) {
+ $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Has to be get_row instead of get_var because of funkiness with 0, false, null values
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_object( $row ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1049,9 +1122,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $cache_key, $value, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_array( $notoptions ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $notoptions = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $notoptions = array();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $notoptions[$option] = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $notoptions[ $option ] = true;
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /** This filter is documented in wp-includes/option.php */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1061,7 +1134,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Filter the value of an existing site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter the value of an existing network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1069,34 +1142,43 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0 The `$option` parameter was added
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param mixed $value Value of site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $value Value of network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $option Option name.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> return apply_filters( 'site_option_' . $option, $value, $option );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Add a new site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Add a new network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Existing options will not be updated. Note that prior to 3.3 this wasn't the case.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Existing options will not be updated.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.8.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.4.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @see add_option()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global wpdb $wpdb
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global wpdb $wpdb
+ * @global object $current_site
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of option to add. Expected to not be SQL-escaped.
- * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of option to add. Expected to not be SQL-escaped.
+ * @param mixed $value Option value, can be anything. Expected to not be SQL-escaped.
+ * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool False if option was not added and true if option was added.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function add_site_option( $option, $value ) {
- global $wpdb;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function add_network_option( $option, $value, $network_id = false ) {
+ global $wpdb, $current_site;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $network_id = (int) $network_id;
+
+ // Fallback to the current network if a network ID is not specified.
+ if ( ! $network_id && is_multisite() ) {
+ $network_id = $current_site->id;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_protect_special_option( $option );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Filter the value of a specific site option before it is added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter the value of a specific network option before it is added.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1104,38 +1186,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0 The `$option` parameter was added
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param mixed $value Value of site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $value Value of network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $option Option name.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $value = apply_filters( 'pre_add_site_option_' . $option, $value, $option );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $notoptions_key = "{$wpdb->siteid}:notoptions";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $notoptions_key = "$network_id:notoptions";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !is_multisite() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_multisite() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result = add_option( $option, $value );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $cache_key = "{$wpdb->siteid}:$option";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $cache_key = "$network_id:$option";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
</span><span class="cx" style="display: block; padding: 0 10px"> $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_array( $notoptions ) || ! isset( $notoptions[$option] ) )
- if ( false !== get_site_option( $option ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
+ if ( false !== get_network_option( $option, false, $network_id ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $value = sanitize_option( $option, $value );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $serialized_value = maybe_serialize( $value );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $serialized_value ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $result )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $result ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $cache_key, $value, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // This option exists now
</span><span class="cx" style="display: block; padding: 0 10px"> $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
- unset( $notoptions[$option] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
+ unset( $notoptions[ $option ] );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1143,50 +1228,60 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $result ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fires after a specific site option has been successfully added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fires after a specific network option has been successfully added.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0 As "add_site_option_{$key}"
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of site option.
- * @param mixed $value Value of site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of the network option.
+ * @param mixed $value Value of the network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( "add_site_option_{$option}", $option, $value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'add_site_option_' . $option, $option, $value );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fires after a site option has been successfully added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fires after a network option has been successfully added.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of site option.
- * @param mixed $value Value of site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of the network option.
+ * @param mixed $value Value of the network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( "add_site_option", $option, $value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'add_site_option', $option, $value );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Removes site option by name.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Removes a network option by name.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.8.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.4.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @see delete_option()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global wpdb $wpdb
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global wpdb $wpdb
+ * @global object $current_site
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of option to remove. Expected to not be SQL-escaped.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of option to remove. Expected to not be SQL-escaped.
+ * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool True, if succeed. False, if failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function delete_site_option( $option ) {
- global $wpdb;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function delete_network_option( $option, $network_id = false ) {
+ global $wpdb, $current_site;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $network_id = (int) $network_id;
+
+ // Fallback to the current network if a network ID is not specified.
+ if ( ! $network_id && is_multisite() ) {
+ $network_id = $current_site->id;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fires immediately before a specific site option is deleted.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fires immediately before a specific network option is deleted.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1197,68 +1292,79 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'pre_delete_site_option_' . $option, $option );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !is_multisite() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_multisite() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result = delete_option( $option );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) );
- if ( is_null( $row ) || !$row->meta_id )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
+ if ( is_null( $row ) || ! $row->meta_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $cache_key = "{$wpdb->siteid}:$option";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+ $cache_key = "$network_id:$option";
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( $cache_key, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $wpdb->siteid ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $result ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fires after a specific site option has been deleted.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fires after a specific network option has been deleted.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0 As "delete_site_option_{$key}"
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of the site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of the network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( "delete_site_option_{$option}", $option );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'delete_site_option_' . $option, $option );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fires after a site option has been deleted.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fires after a network option has been deleted.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of the site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of the network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( "delete_site_option", $option );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'delete_site_option', $option );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Update the value of a site option that was already added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Update the value of a network option that was already added.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.8.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.4.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @see update_option()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global wpdb $wpdb
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global wpdb $wpdb
+ * @global object $current_site
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of option. Expected to not be SQL-escaped.
- * @param mixed $value Option value. Expected to not be SQL-escaped.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of option. Expected to not be SQL-escaped.
+ * @param mixed $value Option value. Expected to not be SQL-escaped.
+ * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool False if value was not updated and true if value was updated.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function update_site_option( $option, $value ) {
- global $wpdb;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function update_network_option( $option, $value, $network_id = false ) {
+ global $wpdb, $current_site;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $network_id = (int) $network_id;
+
+ // Fallback to the current network if a network ID is not specified.
+ if ( ! $network_id && is_multisite() ) {
+ $network_id = $current_site->id;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_protect_special_option( $option );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $old_value = get_site_option( $option );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $old_value = get_network_option( $option, false, $network_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Filter a specific site option before its value is updated.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter a specific network option before its value is updated.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1266,35 +1372,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.4.0 The `$option` parameter was added
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param mixed $value New value of site option.
- * @param mixed $old_value Old value of site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $value New value of the network option.
+ * @param mixed $old_value Old value of the network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $option Option name.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value, $option );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $value === $old_value )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $value === $old_value ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( false === $old_value )
- return add_site_option( $option, $value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( false === $old_value ) {
+ return add_network_option( $option, $value, $network_id );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $notoptions_key = "{$wpdb->siteid}:notoptions";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $notoptions_key = "$network_id:notoptions";
</ins><span class="cx" style="display: block; padding: 0 10px"> $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
- unset( $notoptions[$option] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
+ unset( $notoptions[ $option ] );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !is_multisite() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_multisite() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result = update_option( $option, $value );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $value = sanitize_option( $option, $value );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $serialized_value = maybe_serialize( $value );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $result ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $cache_key = "{$wpdb->siteid}:$option";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $cache_key = "$network_id:$option";
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $cache_key, $value, 'site-options' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1302,32 +1410,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $result ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fires after the value of a specific site option has been successfully updated.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fires after the value of a specific network option has been successfully updated.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The dynamic portion of the hook name, `$option`, refers to the option name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0 As "update_site_option_{$key}"
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of site option.
- * @param mixed $value Current value of site option.
- * @param mixed $old_value Old value of site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of the network option.
+ * @param mixed $value Current value of the network option.
+ * @param mixed $old_value Old value of the network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( "update_site_option_{$option}", $option, $value, $old_value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'update_site_option_' . $option, $option, $value, $old_value );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fires after the value of a site option has been successfully updated.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fires after the value of a network option has been successfully updated.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $option Name of site option.
- * @param mixed $value Current value of site option.
- * @param mixed $old_value Old value of site option.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $option Name of the network option.
+ * @param mixed $value Current value of the network option.
+ * @param mixed $old_value Old value of the network option.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( "update_site_option", $option, $value, $old_value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'update_site_option', $option, $value, $old_value );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsoptionnetworkOptionphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/option/networkOption.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/option/networkOption.php (rev 0)
+++ trunk/tests/phpunit/tests/option/networkOption.php 2015-10-02 18:00:30 UTC (rev 34777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,43 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+if ( is_multisite() ) :
+
+/**
+ * Tests specific to network options in Multisite.
+ *
+ * @group option
+ * @group ms-option
+ * @group multisite
+ */
+class Tests_Option_NetworkOption extends WP_UnitTestCase {
+ function test_add_network_option_not_available_on_other_network() {
+ $id = $this->factory->network->create();
+ $option = rand_str();
+ $value = rand_str();
+
+ add_network_option( $option, $value );
+ $this->assertFalse( get_network_option( $option, false, $id ) );
+ }
+
+ function test_add_network_option_available_on_same_network() {
+ $id = $this->factory->network->create();
+ $option = rand_str();
+ $value = rand_str();
+
+ add_network_option( $option, $value, $id );
+ $this->assertEquals( $value, get_network_option( $option, false, $id ) );
+ }
+
+ function test_delete_network_option_on_only_one_network() {
+ $id = $this->factory->network->create();
+ $option = rand_str();
+ $value = rand_str();
+
+ add_network_option( $option, $value );
+ add_network_option( $option, $value, $id );
+ delete_network_option( $option );
+ $this->assertEquals( $value, get_network_option( $option, false, $id ) );
+ }
+}
+
+endif;
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>