Ticket #28290: 28290.1.patch
| File 28290.1.patch, 25.5 KB (added by , 10 years ago) |
|---|
-
wp-includes/option.php
diff --git a/wp-includes/option.php b/wp-includes/option.php index ab8f81b..3bd11ad 100644
a b function delete_all_user_settings() { 975 975 * Retrieve site option value based on name of option. 976 976 * 977 977 * @since 2.8.0 978 * @since 4.4.0 Modified into wrapper for get_network_option() 979 * 980 * @see get_network_option() 981 * 982 * 983 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. 984 * @param mixed $default Optional value to return if option doesn't exist. Default false. 985 * @param bool $deprecated Whether to use cache. Multisite only. Always set to true. 986 * 987 * @return mixed Value set for the option. 988 */ 989 function get_site_option( $option, $default = false, $deprecated = true ) { 990 return get_network_option( $option, $default ); 991 } 992 993 /** 994 * Add a new site option. 995 * 996 * Existing options will not be updated. Note that prior to 3.3 this wasn't the case. 997 * 998 * @since 2.8.0 999 * @since 4.4.0 Modified into wrapper for add_network_option() 1000 * 1001 * @see add_network_option() 1002 * 1003 * 1004 * @param string $option Name of option to add. Expected to not be SQL-escaped. 1005 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. 1006 * 1007 * @return bool False if option was not added and true if option was added. 1008 */ 1009 function add_site_option( $option, $value ) { 1010 return add_network_option( $option, $value ); 1011 } 1012 1013 /** 1014 * Removes site option by name. 1015 * 1016 * @since 2.8.0 1017 * @since 4.4.0 Modified into wrapper for delete_network_option() 1018 * 1019 * @see delete_network_option() 1020 * 1021 * 1022 * @param string $option Name of option to remove. Expected to not be SQL-escaped. 1023 * 1024 * @return bool True, if succeed. False, if failure. 1025 */ 1026 function delete_site_option( $option ) { 1027 return delete_network_option( $option ); 1028 } 1029 1030 /** 1031 * Update the value of a site option that was already added. 1032 * 1033 * @since 2.8.0 1034 * @since 4.4.0 Modified into wrapper for update_network_option() 1035 * 1036 * @see update_network_option() 1037 * 1038 * 1039 * @param string $option Name of option. Expected to not be SQL-escaped. 1040 * @param mixed $value Option value. Expected to not be SQL-escaped. 1041 * 1042 * @return bool False if value was not updated and true if value was updated. 1043 */ 1044 function update_site_option( $option, $value ) { 1045 return update_network_option( $option, $value ); 1046 } 1047 1048 /** 1049 * Retrieve site option value based on name of option. 1050 * 1051 * @since 4.4.0 978 1052 * 979 1053 * @see get_option() 980 1054 * 981 1055 * @global wpdb $wpdb 982 1056 * 983 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. 984 * @param mixed $default Optional value to return if option doesn't exist. Default false. 985 * @param bool $use_cache Whether to use cache. Multisite only. Default true. 1057 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. 1058 * @param mixed $default Optional value to return if option doesn't exist. Default false. 1059 * @param int|bool $network_id ID of the network. 1060 * 986 1061 * @return mixed Value set for the option. 987 1062 */ 988 function get_ site_option( $option, $default = false, $use_cache= true ) {1063 function get_network_option( $option, $default = false, $network_id = true ) { 989 1064 global $wpdb; 990 1065 1066 /** If network ID not set, get current network. **/ 1067 if ( false === $network_id && is_multisite() ) { 1068 $current_network = get_current_site(); 1069 $network_id = $current_network->id; 1070 } 1071 /** Make sure network id is an int */ 1072 $network_id = (int) $network_id; 1073 991 1074 /** 992 1075 * Filter an existing site option before it is retrieved. 993 1076 * … … function get_site_option( $option, $default = false, $use_cache = true ) { 1000 1083 * @since 3.0.0 1001 1084 * @since 4.4.0 The `$option` parameter was added 1002 1085 * 1003 * @param mixed $pre_option The default value to return if the option does not exist.1004 * @param string $option Option name.1086 * @param mixed $pre_option The default value to return if the option does not exist. 1087 * @param string $option Option name. 1005 1088 */ 1006 1089 $pre = apply_filters( 'pre_site_option_' . $option, false, $option ); 1007 1090 1008 if ( false !== $pre ) 1009 return $pre; 1091 if ( false !== $pre ) { 1092 return $pre; 1093 } 1094 1095 /** 1096 * Filter an existing network option before it is retrieved. 1097 * 1098 * The dynamic portion of the hook name, `$option`, refers to the option name. 1099 * 1100 * Passing a truthy value to the filter will effectively short-circuit retrieval, 1101 * returning the passed value instead. 1102 * 1103 * @since 4.4.0 1104 * 1105 * @param mixed $pre_option The default value to return if the option does not exist. 1106 * @param string $option Option name. 1107 * @param int $network_id ID of the network. 1108 * 1109 */ 1110 $pre = apply_filters( 'pre_network_option_' . $option, false, $option, $network_id ); 1111 1112 if ( false !== $pre ) { 1113 return $pre; 1114 } 1010 1115 1011 1116 // prevent non-existent options from triggering multiple queries 1012 $notoptions_key = "{$ wpdb->siteid}:notoptions";1013 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1117 $notoptions_key = "{$network_id}:notoptions"; 1118 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1014 1119 1015 if ( isset( $notoptions[ $option] ) ) {1120 if ( isset( $notoptions[ $option ] ) ) { 1016 1121 1017 1122 /** 1018 1123 * Filter a specific default site option. … … function get_site_option( $option, $default = false, $use_cache = true ) { 1022 1127 * @since 3.4.0 1023 1128 * @since 4.4.0 The `$option` parameter was added. 1024 1129 * 1025 * @param mixed $default The value to return if the site option does not exist1130 * @param mixed $default The value to return if the site option does not exist 1026 1131 * in the database. 1027 * @param string $option Option name.1132 * @param string $option Option name. 1028 1133 */ 1029 return apply_filters( 'default_site_option_' . $option, $default, $option ); 1134 $default = apply_filters( 'default_site_option_' . $option, $default, $option ); 1135 1136 /** 1137 * Filter a specific default network option. 1138 * 1139 * The dynamic portion of the hook name, `$option`, refers to the option name. 1140 * 1141 * @since 4.4.0 1142 * 1143 * @param mixed $default The value to return if the site option does not exist 1144 * in the database. 1145 * @param string $option Option name. 1146 * @param int $network_id ID of the network. 1147 */ 1148 1149 return apply_filters( 'default_network_option_' . $option, $default, $option, $network_id ); 1030 1150 } 1031 1151 1032 1152 if ( ! is_multisite() ) { 1033 1153 1034 1154 /** This filter is documented in wp-includes/option.php */ 1035 1155 $default = apply_filters( 'default_site_option_' . $option, $default, $option ); 1036 $value = get_option($option, $default); 1156 /** This filter is documented in wp-includes/option.php */ 1157 $default = apply_filters( 'default_network_option_' . $option, $default, $option, $network_id ); 1158 $value = get_option( $option, $default ); 1037 1159 } else { 1038 $cache_key = "{$wpdb->siteid}:$option"; 1039 if ( $use_cache ) 1040 $value = wp_cache_get($cache_key, 'site-options'); 1160 $cache_key = "{$network_id}:$option"; 1161 $value = wp_cache_get( $cache_key, 'site-options' ); 1041 1162 1042 if ( !isset($value) || (false === $value)) {1043 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) );1163 if ( false === $value ) { 1164 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1044 1165 1045 1166 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 1046 1167 if ( is_object( $row ) ) { … … function get_site_option( $option, $default = false, $use_cache = true ) { 1049 1170 wp_cache_set( $cache_key, $value, 'site-options' ); 1050 1171 } else { 1051 1172 if ( ! is_array( $notoptions ) ) { 1052 $notoptions = array();1173 $notoptions = array(); 1053 1174 } 1054 $notoptions[ $option] = true;1175 $notoptions[ $option ] = true; 1055 1176 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1056 1177 1057 1178 /** This filter is documented in wp-includes/option.php */ 1058 1179 $value = apply_filters( 'default_site_option_' . $option, $default, $option ); 1180 /** This filter is documented in wp-includes/option.php */ 1181 $value = apply_filters( 'default_network_option_' . $option, $value, $option, $network_id ); 1059 1182 } 1060 1183 } 1061 1184 } 1062 1185 1186 1063 1187 /** 1064 1188 * Filter the value of an existing site option. 1065 1189 * … … function get_site_option( $option, $default = false, $use_cache = true ) { 1069 1193 * @since 3.0.0 1070 1194 * @since 4.4.0 The `$option` parameter was added 1071 1195 * 1072 * @param mixed $value Value of site option. 1196 * @param mixed $value Value of site option. 1197 * @param string $option Option name. 1198 */ 1199 $value = apply_filters( 'site_option_' . $option, $value, $option ); 1200 1201 /** 1202 * Filter the value of an existing network option. 1203 * 1204 * The dynamic portion of the hook name, `$option`, refers to the option name. 1205 * 1206 * @since 4.4.0 1207 * 1208 * @param mixed $value Value of site option. 1073 1209 * @param string $option Option name. 1210 * @param int $network_id ID of the network. 1074 1211 */ 1075 return apply_filters( 'site_option_' . $option, $value, $option ); 1212 1213 return apply_filters( 'network_option_' . $option, $value, $option, $network_id ); 1076 1214 } 1077 1215 1078 1216 /** 1079 * Add a new siteoption.1217 * Add a new network option. 1080 1218 * 1081 1219 * Existing options will not be updated. Note that prior to 3.3 this wasn't the case. 1082 1220 * 1083 * @since 2.8.01221 * @since 4.4.0 1084 1222 * 1085 1223 * @see add_option() 1086 1224 * 1087 1225 * @global wpdb $wpdb 1088 1226 * 1089 1227 * @param string $option Name of option to add. Expected to not be SQL-escaped. 1090 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. 1228 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. 1229 * @param int|bool $network_id ID of the network. 1230 * 1091 1231 * @return bool False if option was not added and true if option was added. 1092 1232 */ 1093 function add_ site_option( $option, $value ) {1233 function add_network_option( $option, $value, $network_id = false ) { 1094 1234 global $wpdb; 1095 1235 1236 /** If network ID not set, get current network. **/ 1237 if ( false === $network_id && is_multisite() ) { 1238 $current_network = get_current_site(); 1239 $network_id = $current_network->id; 1240 } 1241 /** Make sure network id is an int */ 1242 $network_id = (int) $network_id; 1243 1096 1244 wp_protect_special_option( $option ); 1097 1245 1098 1246 /** … … function add_site_option( $option, $value ) { 1104 1252 * @since 3.0.0 1105 1253 * @since 4.4.0 The `$option` parameter was added 1106 1254 * 1107 * @param mixed $valueValue of site option.1255 * @param mixed $value Value of site option. 1108 1256 * @param string $option Option name. 1109 1257 */ 1110 1258 $value = apply_filters( 'pre_add_site_option_' . $option, $value, $option ); 1111 1259 1112 $notoptions_key = "{$wpdb->siteid}:notoptions"; 1260 /** 1261 * Filter the value of a specific network option before it is added. 1262 * 1263 * The dynamic portion of the hook name, `$option`, refers to the option name. 1264 * 1265 * @since 4.4.0 1266 * 1267 * @param mixed $value Value of site option. 1268 * @param string $option Option name. 1269 * @param int $network_id ID of the network. 1270 */ 1271 $value = apply_filters( 'pre_add_network_option_' . $option, $value, $option, $network_id ); 1272 1273 $notoptions_key = "{$network_id}:notoptions"; 1113 1274 1114 if ( ! is_multisite() ) {1275 if ( ! is_multisite() ) { 1115 1276 $result = add_option( $option, $value ); 1116 1277 } else { 1117 $cache_key = "{$ wpdb->siteid}:$option";1278 $cache_key = "{$network_id}:$option"; 1118 1279 1119 1280 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1120 1281 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1121 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option] ) )1122 if ( false !== get_ site_option( $option ) )1282 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1283 if ( false !== get_network_option( $option, false, $network_id ) ) { 1123 1284 return false; 1285 } 1286 } 1124 1287 1125 1288 $value = sanitize_option( $option, $value ); 1126 1289 1127 1290 $serialized_value = maybe_serialize( $value ); 1128 $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 1291 $result = $wpdb->insert( $wpdb->sitemeta, array( 1292 'site_id' => $network_id, 1293 'meta_key' => $option, 1294 'meta_value' => $serialized_value 1295 ) ); 1129 1296 1130 if ( ! $result ) 1297 if ( ! $result ) { 1131 1298 return false; 1299 } 1132 1300 1133 1301 wp_cache_set( $cache_key, $value, 'site-options' ); 1134 1302 1135 1303 // This option exists now 1136 1304 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh 1137 if ( is_array( $notoptions ) && isset( $notoptions[ $option] ) ) {1138 unset( $notoptions[ $option] );1305 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1306 unset( $notoptions[ $option ] ); 1139 1307 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1140 1308 } 1141 1309 } … … function add_site_option( $option, $value ) { 1151 1319 * @since 3.0.0 1152 1320 * 1153 1321 * @param string $option Name of site option. 1154 * @param mixed $valueValue of site option.1322 * @param mixed $value Value of site option. 1155 1323 */ 1156 1324 do_action( "add_site_option_{$option}", $option, $value ); 1157 1325 1158 1326 /** 1327 * Fires after a specific network option has been successfully added. 1328 * 1329 * The dynamic portion of the hook name, `$option`, refers to the option name. 1330 * 1331 * @since 4.4.0 1332 * 1333 * @param string $option Name of site option. 1334 * @param mixed $value Value of site option. 1335 * @param int $network_id ID of the network. 1336 */ 1337 do_action( "add_network_option_{$option}", $option, $value, $network_id ); 1338 1339 /** 1159 1340 * Fires after a site option has been successfully added. 1160 1341 * 1161 1342 * @since 3.0.0 1162 1343 * 1163 1344 * @param string $option Name of site option. 1164 * @param mixed $valueValue of site option.1345 * @param mixed $value Value of site option. 1165 1346 */ 1166 1347 do_action( "add_site_option", $option, $value ); 1167 1348 1349 /** 1350 * Fires after a network option has been successfully added. 1351 * 1352 * @since 4.4.0 1353 * 1354 * @param string $option Name of site option. 1355 * @param mixed $value Value of site option. 1356 * @param int $network_id ID of the network. 1357 */ 1358 do_action( "add_network_option", $option, $value, $network_id ); 1359 1168 1360 return true; 1169 1361 } 1362 1170 1363 return false; 1171 1364 } 1172 1365 1173 1366 /** 1174 * Removes siteoption by name.1367 * Removes network option by name. 1175 1368 * 1176 * @since 2.8.01369 * @since 4.4.0 1177 1370 * 1178 1371 * @see delete_option() 1179 1372 * 1180 1373 * @global wpdb $wpdb 1181 1374 * 1182 * @param string $option Name of option to remove. Expected to not be SQL-escaped. 1375 * @param string $option Name of option to remove. Expected to not be SQL-escaped. 1376 * @param int|bool $network_id ID of the network. 1377 * 1183 1378 * @return bool True, if succeed. False, if failure. 1184 1379 */ 1185 function delete_ site_option( $option) {1380 function delete_network_option( $option, $network_id = false ) { 1186 1381 global $wpdb; 1187 1382 1383 /** If network ID not set, get current network. **/ 1384 if ( false === $network_id && is_multisite() ) { 1385 $current_network = get_current_site(); 1386 $network_id = $current_network->id; 1387 } 1388 /** Make sure network id is an int */ 1389 $network_id = (int) $network_id; 1390 1188 1391 // ms_protect_special_option( $option ); @todo 1189 1392 1190 1393 /** … … function delete_site_option( $option ) { 1199 1402 */ 1200 1403 do_action( 'pre_delete_site_option_' . $option, $option ); 1201 1404 1202 if ( !is_multisite() ) { 1405 /** 1406 * Fires immediately before a specific network option is deleted. 1407 * 1408 * The dynamic portion of the hook name, `$option`, refers to the option name. 1409 * 1410 * @since 4.4.0 1411 * 1412 * @param string $option Option name. 1413 * @param int $network_id ID of the network. 1414 */ 1415 do_action( 'pre_delete_network_option_' . $option, $option, $network_id ); 1416 1417 if ( ! is_multisite() ) { 1203 1418 $result = delete_option( $option ); 1204 1419 } else { 1205 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $ wpdb->siteid ) );1206 if ( is_null( $row ) || ! $row->meta_id )1420 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1421 if ( is_null( $row ) || ! $row->meta_id ) { 1207 1422 return false; 1208 $cache_key = "{$wpdb->siteid}:$option"; 1423 } 1424 $cache_key = "{$network_id}:$option"; 1209 1425 wp_cache_delete( $cache_key, 'site-options' ); 1210 1426 1211 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $ wpdb->siteid ) );1427 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); 1212 1428 } 1213 1429 1214 1430 if ( $result ) { … … function delete_site_option( $option ) { 1226 1442 do_action( "delete_site_option_{$option}", $option ); 1227 1443 1228 1444 /** 1445 * Fires after a specific network option has been deleted. 1446 * 1447 * The dynamic portion of the hook name, `$option`, refers to the option name. 1448 * 1449 * @since 4.4.0 1450 * 1451 * @param string $option Name of the site option. 1452 * @param int $network_id ID of the network. 1453 */ 1454 do_action( "delete_network_option_{$option}", $option, $network_id ); 1455 1456 /** 1229 1457 * Fires after a site option has been deleted. 1230 1458 * 1231 1459 * @since 3.0.0 … … function delete_site_option( $option ) { 1234 1462 */ 1235 1463 do_action( "delete_site_option", $option ); 1236 1464 1465 /** 1466 * Fires after a network option has been deleted. 1467 * 1468 * @since 4.4.0 1469 * 1470 * @param string $option Name of the site option. 1471 * @param int $network_id ID of the network. 1472 */ 1473 do_action( "delete_network_option", $option, $network_id ); 1474 1237 1475 return true; 1238 1476 } 1477 1239 1478 return false; 1240 1479 } 1241 1480 1242 1481 /** 1243 * Update the value of a siteoption that was already added.1482 * Update the value of a network option that was already added. 1244 1483 * 1245 * @since 2.8.01484 * @since 4.4.0 1246 1485 * 1247 1486 * @see update_option() 1248 1487 * 1249 1488 * @global wpdb $wpdb 1250 1489 * 1251 1490 * @param string $option Name of option. Expected to not be SQL-escaped. 1252 * @param mixed $value Option value. Expected to not be SQL-escaped. 1491 * @param mixed $value Option value. Expected to not be SQL-escaped. 1492 * @param int|bool $network_id ID of the network. 1493 * 1253 1494 * @return bool False if value was not updated and true if value was updated. 1254 1495 */ 1255 function update_ site_option( $option, $value ) {1496 function update_network_option( $option, $value, $network_id = false ) { 1256 1497 global $wpdb; 1257 1498 1499 /** If network ID not set, get current network. **/ 1500 if ( false === $network_id && is_multisite() ) { 1501 $current_network = get_current_site(); 1502 $network_id = $current_network->id; 1503 } 1504 /** Make sure network id is an int */ 1505 $network_id = (int) $network_id; 1506 1258 1507 wp_protect_special_option( $option ); 1259 1508 1260 $old_value = get_ site_option( $option);1509 $old_value = get_network_option( $option, false, $network_id ); 1261 1510 1262 1511 /** 1263 1512 * Filter a specific site option before its value is updated. … … function update_site_option( $option, $value ) { 1268 1517 * @since 3.0.0 1269 1518 * @since 4.4.0 The `$option` parameter was added 1270 1519 * 1271 * @param mixed $valueNew value of site option.1272 * @param mixed $old_value Old value of site option.1273 * @param string $option Option name.1520 * @param mixed $value New value of site option. 1521 * @param mixed $old_value Old value of site option. 1522 * @param string $option Option name. 1274 1523 */ 1275 1524 $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value, $option ); 1276 1525 1277 if ( $value === $old_value ) 1526 if ( $value === $old_value ) { 1278 1527 return false; 1528 } 1279 1529 1280 if ( false === $old_value ) 1281 return add_site_option( $option, $value ); 1530 /** 1531 * Filter a specific network option before its value is updated. 1532 * 1533 * The dynamic portion of the hook name, `$option`, refers to the option name. 1534 * 1535 * @since 4.4.0 1536 * 1537 * @param mixed $value New value of site option. 1538 * @param mixed $old_value Old value of site option. 1539 * @param string $option Option name. 1540 * @param int $network_id ID of the network. 1541 */ 1542 $value = apply_filters( 'pre_update_network_option_' . $option, $value, $old_value, $option, $network_id ); 1282 1543 1283 $notoptions_key = "{$wpdb->siteid}:notoptions"; 1284 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1285 if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { 1286 unset( $notoptions[$option] ); 1544 if ( $value === $old_value ) { 1545 return false; 1546 } 1547 1548 if ( false === $old_value ) { 1549 return add_network_option( $option, $value, $network_id ); 1550 } 1551 1552 $notoptions_key = "{$network_id}:notoptions"; 1553 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1554 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1555 unset( $notoptions[ $option ] ); 1287 1556 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1288 1557 } 1289 1558 1290 if ( ! is_multisite() ) {1559 if ( ! is_multisite() ) { 1291 1560 $result = update_option( $option, $value ); 1292 1561 } else { 1293 1562 $value = sanitize_option( $option, $value ); 1294 1563 1295 1564 $serialized_value = maybe_serialize( $value ); 1296 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) ); 1565 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 1566 'site_id' => $network_id, 1567 'meta_key' => $option 1568 ) ); 1297 1569 1298 1570 if ( $result ) { 1299 $cache_key = "{$ wpdb->siteid}:$option";1571 $cache_key = "{$network_id}:$option"; 1300 1572 wp_cache_set( $cache_key, $value, 'site-options' ); 1301 1573 } 1302 1574 } … … function update_site_option( $option, $value ) { 1311 1583 * @since 2.9.0 As "update_site_option_{$key}" 1312 1584 * @since 3.0.0 1313 1585 * 1314 * @param string $option Name of site option.1315 * @param mixed $valueCurrent value of site option.1316 * @param mixed $old_value Old value of site option.1586 * @param string $option Name of site option. 1587 * @param mixed $value Current value of site option. 1588 * @param mixed $old_value Old value of site option. 1317 1589 */ 1318 1590 do_action( "update_site_option_{$option}", $option, $value, $old_value ); 1319 1591 1592 1593 /** 1594 * Fires after the value of a specific network option has been successfully updated. 1595 * 1596 * The dynamic portion of the hook name, `$option`, refers to the option name. 1597 * 1598 * @since 4.4.0 1599 * 1600 * @param string $option Name of site option. 1601 * @param mixed $value Current value of site option. 1602 * @param mixed $old_value Old value of site option. 1603 * @param int $network_id ID of the network. 1604 */ 1605 do_action( "update_network_option_{$option}", $option, $value, $old_value, $network_id ); 1606 1607 /** 1608 * Fires after the value of a specific network option has been successfully updated. 1609 * 1610 * The dynamic portion of the hook name, `$option`, refers to the option name. 1611 * 1612 * @since 4.4.0 1613 * 1614 * @param string $option Name of site option. 1615 * @param mixed $value Current value of site option. 1616 * @param mixed $old_value Old value of site option. 1617 * @param int $network_id ID of the network. 1618 */ 1619 do_action( "update_network_option_{$option}", $option, $value, $old_value, $network_id ); 1620 1320 1621 /** 1321 1622 * Fires after the value of a site option has been successfully updated. 1322 1623 * 1323 1624 * @since 3.0.0 1324 1625 * 1325 * @param string $option Name of site option.1326 * @param mixed $valueCurrent value of site option.1327 * @param mixed $old_value Old value of site option.1626 * @param string $option Name of site option. 1627 * @param mixed $value Current value of site option. 1628 * @param mixed $old_value Old value of site option. 1328 1629 */ 1329 1630 do_action( "update_site_option", $option, $value, $old_value ); 1330 1631 1632 /** 1633 * Fires after the value of a network option has been successfully updated. 1634 * 1635 * @since 4.4.0 1636 * 1637 * @param string $option Name of site option. 1638 * @param mixed $value Current value of site option. 1639 * @param mixed $old_value Old value of site option. 1640 * @param int $network_id ID of the network. 1641 */ 1642 do_action( "update_network_option", $option, $value, $old_value, $network_id ); 1643 1331 1644 return true; 1332 1645 } 1646 1333 1647 return false; 1334 1648 } 1335 1649 … … function delete_site_transient( $transient ) { 1359 1673 } else { 1360 1674 $option_timeout = '_site_transient_timeout_' . $transient; 1361 1675 $option = '_site_transient_' . $transient; 1362 $result = delete_ site_option( $option );1676 $result = delete_network_option( $option ); 1363 1677 if ( $result ) 1364 delete_ site_option( $option_timeout );1678 delete_network_option( $option_timeout ); 1365 1679 } 1366 1680 if ( $result ) { 1367 1681 … … function get_site_transient( $transient ) { 1422 1736 $transient_option = '_site_transient_' . $transient; 1423 1737 if ( ! in_array( $transient, $no_timeout ) ) { 1424 1738 $transient_timeout = '_site_transient_timeout_' . $transient; 1425 $timeout = get_ site_option( $transient_timeout );1739 $timeout = get_network_option( $transient_timeout ); 1426 1740 if ( false !== $timeout && $timeout < time() ) { 1427 delete_ site_option( $transient_option );1428 delete_ site_option( $transient_timeout );1741 delete_network_option( $transient_option ); 1742 delete_network_option( $transient_timeout ); 1429 1743 $value = false; 1430 1744 } 1431 1745 } 1432 1746 1433 1747 if ( ! isset( $value ) ) 1434 $value = get_ site_option( $transient_option );1748 $value = get_network_option( $transient_option ); 1435 1749 } 1436 1750 1437 1751 /** … … function set_site_transient( $transient, $value, $expiration = 0 ) { 1486 1800 } else { 1487 1801 $transient_timeout = '_site_transient_timeout_' . $transient; 1488 1802 $option = '_site_transient_' . $transient; 1489 if ( false === get_ site_option( $option ) ) {1803 if ( false === get_network_option( $option ) ) { 1490 1804 if ( $expiration ) 1491 add_ site_option( $transient_timeout, time() + $expiration );1492 $result = add_ site_option( $option, $value );1805 add_network_option( $transient_timeout, time() + $expiration ); 1806 $result = add_network_option( $option, $value ); 1493 1807 } else { 1494 1808 if ( $expiration ) 1495 update_ site_option( $transient_timeout, time() + $expiration );1496 $result = update_ site_option( $option, $value );1809 update_network_option( $transient_timeout, time() + $expiration ); 1810 $result = update_network_option( $option, $value ); 1497 1811 } 1498 1812 } 1499 1813 if ( $result ) {