Ticket #28290: 28290.2a.patch
| File 28290.2a.patch, 19.1 KB (added by , 11 years ago) |
|---|
-
wp-includes/option.php
diff --git a/wp-includes/option.php b/wp-includes/option.php index ab8f81b..903296c 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 } 1010 1094 1011 1095 // prevent non-existent options from triggering multiple queries 1012 $notoptions_key = "{$ wpdb->siteid}:notoptions";1013 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );1096 $notoptions_key = "{$network_id}:notoptions"; 1097 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1014 1098 1015 if ( isset( $notoptions[ $option] ) ) {1099 if ( isset( $notoptions[ $option ] ) ) { 1016 1100 1017 1101 /** 1018 1102 * Filter a specific default site option. … … function get_site_option( $option, $default = false, $use_cache = true ) { 1022 1106 * @since 3.4.0 1023 1107 * @since 4.4.0 The `$option` parameter was added. 1024 1108 * 1025 * @param mixed $default The value to return if the site option does not exist1109 * @param mixed $default The value to return if the site option does not exist 1026 1110 * in the database. 1027 * @param string $option Option name.1111 * @param string $option Option name. 1028 1112 */ 1029 1113 return apply_filters( 'default_site_option_' . $option, $default, $option ); 1030 1114 } … … function get_site_option( $option, $default = false, $use_cache = true ) { 1033 1117 1034 1118 /** This filter is documented in wp-includes/option.php */ 1035 1119 $default = apply_filters( 'default_site_option_' . $option, $default, $option ); 1036 $value = get_option($option, $default);1120 $value = get_option( $option, $default ); 1037 1121 } else { 1038 $cache_key = "{$wpdb->siteid}:$option"; 1039 if ( $use_cache ) 1040 $value = wp_cache_get($cache_key, 'site-options'); 1122 $cache_key = "{$network_id}:$option"; 1123 $value = wp_cache_get( $cache_key, 'site-options' ); 1041 1124 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 ) );1125 if ( false === $value ) { 1126 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1044 1127 1045 1128 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 1046 1129 if ( is_object( $row ) ) { … … function get_site_option( $option, $default = false, $use_cache = true ) { 1049 1132 wp_cache_set( $cache_key, $value, 'site-options' ); 1050 1133 } else { 1051 1134 if ( ! is_array( $notoptions ) ) { 1052 $notoptions = array();1135 $notoptions = array(); 1053 1136 } 1054 $notoptions[ $option] = true;1137 $notoptions[ $option ] = true; 1055 1138 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1056 1139 1057 1140 /** This filter is documented in wp-includes/option.php */ … … function get_site_option( $option, $default = false, $use_cache = true ) { 1069 1152 * @since 3.0.0 1070 1153 * @since 4.4.0 The `$option` parameter was added 1071 1154 * 1072 * @param mixed $valueValue of site option.1155 * @param mixed $value Value of site option. 1073 1156 * @param string $option Option name. 1074 1157 */ 1158 1075 1159 return apply_filters( 'site_option_' . $option, $value, $option ); 1076 1160 } 1077 1161 1078 1162 /** 1079 * Add a new siteoption.1163 * Add a new network option. 1080 1164 * 1081 1165 * Existing options will not be updated. Note that prior to 3.3 this wasn't the case. 1082 1166 * 1083 * @since 2.8.01167 * @since 4.4.0 1084 1168 * 1085 1169 * @see add_option() 1086 1170 * 1087 1171 * @global wpdb $wpdb 1088 1172 * 1089 1173 * @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. 1174 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. 1175 * @param int|bool $network_id ID of the network. 1176 * 1091 1177 * @return bool False if option was not added and true if option was added. 1092 1178 */ 1093 function add_ site_option( $option, $value ) {1179 function add_network_option( $option, $value, $network_id = false ) { 1094 1180 global $wpdb; 1095 1181 1182 /** If network ID not set, get current network. **/ 1183 if ( false === $network_id && is_multisite() ) { 1184 $current_network = get_current_site(); 1185 $network_id = $current_network->id; 1186 } 1187 /** Make sure network id is an int */ 1188 $network_id = (int) $network_id; 1189 1096 1190 wp_protect_special_option( $option ); 1097 1191 1098 1192 /** … … function add_site_option( $option, $value ) { 1104 1198 * @since 3.0.0 1105 1199 * @since 4.4.0 The `$option` parameter was added 1106 1200 * 1107 * @param mixed $valueValue of site option.1201 * @param mixed $value Value of site option. 1108 1202 * @param string $option Option name. 1109 1203 */ 1110 1204 $value = apply_filters( 'pre_add_site_option_' . $option, $value, $option ); 1111 1205 1112 $notoptions_key = "{$ wpdb->siteid}:notoptions";1206 $notoptions_key = "{$network_id}:notoptions"; 1113 1207 1114 if ( ! is_multisite() ) {1208 if ( ! is_multisite() ) { 1115 1209 $result = add_option( $option, $value ); 1116 1210 } else { 1117 $cache_key = "{$ wpdb->siteid}:$option";1211 $cache_key = "{$network_id}:$option"; 1118 1212 1119 1213 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 1120 1214 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1121 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option] ) )1122 if ( false !== get_ site_option( $option ) )1215 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1216 if ( false !== get_network_option( $option, false, $network_id ) ) { 1123 1217 return false; 1218 } 1219 } 1124 1220 1125 1221 $value = sanitize_option( $option, $value ); 1126 1222 1127 1223 $serialized_value = maybe_serialize( $value ); 1128 $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 1224 $result = $wpdb->insert( $wpdb->sitemeta, array( 1225 'site_id' => $network_id, 1226 'meta_key' => $option, 1227 'meta_value' => $serialized_value 1228 ) ); 1129 1229 1130 if ( ! $result ) 1230 if ( ! $result ) { 1131 1231 return false; 1232 } 1132 1233 1133 1234 wp_cache_set( $cache_key, $value, 'site-options' ); 1134 1235 1135 1236 // This option exists now 1136 1237 $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] );1238 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1239 unset( $notoptions[ $option ] ); 1139 1240 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1140 1241 } 1141 1242 } … … function add_site_option( $option, $value ) { 1151 1252 * @since 3.0.0 1152 1253 * 1153 1254 * @param string $option Name of site option. 1154 * @param mixed $valueValue of site option.1255 * @param mixed $value Value of site option. 1155 1256 */ 1156 1257 do_action( "add_site_option_{$option}", $option, $value ); 1157 1258 … … function add_site_option( $option, $value ) { 1161 1262 * @since 3.0.0 1162 1263 * 1163 1264 * @param string $option Name of site option. 1164 * @param mixed $valueValue of site option.1265 * @param mixed $value Value of site option. 1165 1266 */ 1166 1267 do_action( "add_site_option", $option, $value ); 1167 1268 1168 1269 return true; 1169 1270 } 1271 1170 1272 return false; 1171 1273 } 1172 1274 1173 1275 /** 1174 * Removes siteoption by name.1276 * Removes network option by name. 1175 1277 * 1176 * @since 2.8.01278 * @since 4.4.0 1177 1279 * 1178 1280 * @see delete_option() 1179 1281 * 1180 1282 * @global wpdb $wpdb 1181 1283 * 1182 * @param string $option Name of option to remove. Expected to not be SQL-escaped. 1284 * @param string $option Name of option to remove. Expected to not be SQL-escaped. 1285 * @param int|bool $network_id ID of the network. 1286 * 1183 1287 * @return bool True, if succeed. False, if failure. 1184 1288 */ 1185 function delete_ site_option( $option) {1289 function delete_network_option( $option, $network_id = false ) { 1186 1290 global $wpdb; 1187 1291 1292 /** If network ID not set, get current network. **/ 1293 if ( false === $network_id && is_multisite() ) { 1294 $current_network = get_current_site(); 1295 $network_id = $current_network->id; 1296 } 1297 /** Make sure network id is an int */ 1298 $network_id = (int) $network_id; 1299 1188 1300 // ms_protect_special_option( $option ); @todo 1189 1301 1190 1302 /** … … function delete_site_option( $option ) { 1199 1311 */ 1200 1312 do_action( 'pre_delete_site_option_' . $option, $option ); 1201 1313 1202 if ( ! is_multisite() ) {1314 if ( ! is_multisite() ) { 1203 1315 $result = delete_option( $option ); 1204 1316 } 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 )1317 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1318 if ( is_null( $row ) || ! $row->meta_id ) { 1207 1319 return false; 1208 $cache_key = "{$wpdb->siteid}:$option"; 1320 } 1321 $cache_key = "{$network_id}:$option"; 1209 1322 wp_cache_delete( $cache_key, 'site-options' ); 1210 1323 1211 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $ wpdb->siteid ) );1324 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); 1212 1325 } 1213 1326 1214 1327 if ( $result ) { … … function delete_site_option( $option ) { 1234 1347 */ 1235 1348 do_action( "delete_site_option", $option ); 1236 1349 1350 1237 1351 return true; 1238 1352 } 1353 1239 1354 return false; 1240 1355 } 1241 1356 1242 1357 /** 1243 * Update the value of a siteoption that was already added.1358 * Update the value of a network option that was already added. 1244 1359 * 1245 * @since 2.8.01360 * @since 4.4.0 1246 1361 * 1247 1362 * @see update_option() 1248 1363 * 1249 1364 * @global wpdb $wpdb 1250 1365 * 1251 1366 * @param string $option Name of option. Expected to not be SQL-escaped. 1252 * @param mixed $value Option value. Expected to not be SQL-escaped. 1367 * @param mixed $value Option value. Expected to not be SQL-escaped. 1368 * @param int|bool $network_id ID of the network. 1369 * 1253 1370 * @return bool False if value was not updated and true if value was updated. 1254 1371 */ 1255 function update_ site_option( $option, $value ) {1372 function update_network_option( $option, $value, $network_id = false ) { 1256 1373 global $wpdb; 1257 1374 1375 /** If network ID not set, get current network. **/ 1376 if ( false === $network_id && is_multisite() ) { 1377 $current_network = get_current_site(); 1378 $network_id = $current_network->id; 1379 } 1380 /** Make sure network id is an int */ 1381 $network_id = (int) $network_id; 1382 1258 1383 wp_protect_special_option( $option ); 1259 1384 1260 $old_value = get_ site_option( $option);1385 $old_value = get_network_option( $option, false, $network_id ); 1261 1386 1262 1387 /** 1263 1388 * Filter a specific site option before its value is updated. … … function update_site_option( $option, $value ) { 1268 1393 * @since 3.0.0 1269 1394 * @since 4.4.0 The `$option` parameter was added 1270 1395 * 1271 * @param mixed $valueNew value of site option.1272 * @param mixed $old_value Old value of site option.1273 * @param string $option Option name.1396 * @param mixed $value New value of site option. 1397 * @param mixed $old_value Old value of site option. 1398 * @param string $option Option name. 1274 1399 */ 1275 1400 $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value, $option ); 1276 1401 1277 if ( $value === $old_value ) 1402 if ( $value === $old_value ) { 1278 1403 return false; 1404 } 1279 1405 1280 if ( false === $old_value ) 1281 return add_site_option( $option, $value ); 1406 if ( false === $old_value ) { 1407 return add_network_option( $option, $value, $network_id ); 1408 } 1282 1409 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] );1410 $notoptions_key = "{$network_id}:notoptions"; 1411 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1412 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1413 unset( $notoptions[ $option ] ); 1287 1414 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); 1288 1415 } 1289 1416 1290 if ( ! is_multisite() ) {1417 if ( ! is_multisite() ) { 1291 1418 $result = update_option( $option, $value ); 1292 1419 } else { 1293 1420 $value = sanitize_option( $option, $value ); 1294 1421 1295 1422 $serialized_value = maybe_serialize( $value ); 1296 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) ); 1423 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 1424 'site_id' => $network_id, 1425 'meta_key' => $option 1426 ) ); 1297 1427 1298 1428 if ( $result ) { 1299 $cache_key = "{$ wpdb->siteid}:$option";1429 $cache_key = "{$network_id}:$option"; 1300 1430 wp_cache_set( $cache_key, $value, 'site-options' ); 1301 1431 } 1302 1432 } … … function update_site_option( $option, $value ) { 1311 1441 * @since 2.9.0 As "update_site_option_{$key}" 1312 1442 * @since 3.0.0 1313 1443 * 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.1444 * @param string $option Name of site option. 1445 * @param mixed $value Current value of site option. 1446 * @param mixed $old_value Old value of site option. 1317 1447 */ 1318 1448 do_action( "update_site_option_{$option}", $option, $value, $old_value ); 1319 1449 … … function update_site_option( $option, $value ) { 1322 1452 * 1323 1453 * @since 3.0.0 1324 1454 * 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.1455 * @param string $option Name of site option. 1456 * @param mixed $value Current value of site option. 1457 * @param mixed $old_value Old value of site option. 1328 1458 */ 1329 1459 do_action( "update_site_option", $option, $value, $old_value ); 1330 1460 1331 1461 return true; 1332 1462 } 1463 1333 1464 return false; 1334 1465 } 1335 1466 … … function delete_site_transient( $transient ) { 1359 1490 } else { 1360 1491 $option_timeout = '_site_transient_timeout_' . $transient; 1361 1492 $option = '_site_transient_' . $transient; 1362 $result = delete_ site_option( $option );1493 $result = delete_network_option( $option ); 1363 1494 if ( $result ) 1364 delete_ site_option( $option_timeout );1495 delete_network_option( $option_timeout ); 1365 1496 } 1366 1497 if ( $result ) { 1367 1498 … … function get_site_transient( $transient ) { 1422 1553 $transient_option = '_site_transient_' . $transient; 1423 1554 if ( ! in_array( $transient, $no_timeout ) ) { 1424 1555 $transient_timeout = '_site_transient_timeout_' . $transient; 1425 $timeout = get_ site_option( $transient_timeout );1556 $timeout = get_network_option( $transient_timeout ); 1426 1557 if ( false !== $timeout && $timeout < time() ) { 1427 delete_ site_option( $transient_option );1428 delete_ site_option( $transient_timeout );1558 delete_network_option( $transient_option ); 1559 delete_network_option( $transient_timeout ); 1429 1560 $value = false; 1430 1561 } 1431 1562 } 1432 1563 1433 1564 if ( ! isset( $value ) ) 1434 $value = get_ site_option( $transient_option );1565 $value = get_network_option( $transient_option ); 1435 1566 } 1436 1567 1437 1568 /** … … function set_site_transient( $transient, $value, $expiration = 0 ) { 1486 1617 } else { 1487 1618 $transient_timeout = '_site_transient_timeout_' . $transient; 1488 1619 $option = '_site_transient_' . $transient; 1489 if ( false === get_ site_option( $option ) ) {1620 if ( false === get_network_option( $option ) ) { 1490 1621 if ( $expiration ) 1491 add_ site_option( $transient_timeout, time() + $expiration );1492 $result = add_ site_option( $option, $value );1622 add_network_option( $transient_timeout, time() + $expiration ); 1623 $result = add_network_option( $option, $value ); 1493 1624 } else { 1494 1625 if ( $expiration ) 1495 update_ site_option( $transient_timeout, time() + $expiration );1496 $result = update_ site_option( $option, $value );1626 update_network_option( $transient_timeout, time() + $expiration ); 1627 $result = update_network_option( $option, $value ); 1497 1628 } 1498 1629 } 1499 1630 if ( $result ) {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)