diff --git a/wp-includes/option.php b/wp-includes/option.php
index 5749f8b..3a0dc0d 100644
a
|
b
|
function delete_all_user_settings() { |
980 | 980 | * |
981 | 981 | * @global wpdb $wpdb |
982 | 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 $use_cache Whether to use cache. Multisite only. Default true. |
| 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. |
| 986 | * @param bool|int $network_id The ID of the network for the option to retrieve. Multisite only. Default false. |
986 | 987 | * @return mixed Value set for the option. |
987 | 988 | */ |
988 | | function get_site_option( $option, $default = false, $use_cache = true ) { |
| 989 | function get_site_option( $option, $default = false, $use_cache = true, $network_id = false ) { |
989 | 990 | global $wpdb; |
990 | 991 | |
| 992 | if( ! $network_id ){ |
| 993 | $network_id = $wpdb->siteid; |
| 994 | } |
| 995 | |
991 | 996 | /** |
992 | 997 | * Filter an existing site option before it is retrieved. |
993 | 998 | * |
… |
… |
function get_site_option( $option, $default = false, $use_cache = true ) { |
999 | 1004 | * @since 2.9.0 As 'pre_site_option_' . $key |
1000 | 1005 | * @since 3.0.0 |
1001 | 1006 | * @since 4.4.0 The `$option` parameter was added |
| 1007 | * @since 4.4.0 The `$network_id` parameter was added |
1002 | 1008 | * |
1003 | 1009 | * @param mixed $pre_option The default value to return if the option does not exist. |
1004 | 1010 | * @param string $option Option name. |
1005 | 1011 | */ |
1006 | | $pre = apply_filters( 'pre_site_option_' . $option, false, $option ); |
| 1012 | $pre = apply_filters( 'pre_site_option_' . $option, false, $option, $network_id ); |
1007 | 1013 | |
1008 | 1014 | if ( false !== $pre ) |
1009 | 1015 | return $pre; |
1010 | 1016 | |
1011 | 1017 | // prevent non-existent options from triggering multiple queries |
1012 | | $notoptions_key = "{$wpdb->siteid}:notoptions"; |
| 1018 | $notoptions_key = "{$network_id}:notoptions"; |
1013 | 1019 | $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
1014 | 1020 | |
1015 | 1021 | if ( isset( $notoptions[$option] ) ) { |
… |
… |
function get_site_option( $option, $default = false, $use_cache = true ) { |
1021 | 1027 | * |
1022 | 1028 | * @since 3.4.0 |
1023 | 1029 | * @since 4.4.0 The `$option` parameter was added. |
| 1030 | * @since 4.4.0 The `$network_id` parameter was added |
1024 | 1031 | * |
1025 | 1032 | * @param mixed $default The value to return if the site option does not exist |
1026 | 1033 | * in the database. |
1027 | 1034 | * @param string $option Option name. |
1028 | 1035 | */ |
1029 | | return apply_filters( 'default_site_option_' . $option, $default, $option ); |
| 1036 | return apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); |
1030 | 1037 | } |
1031 | 1038 | |
1032 | 1039 | if ( ! is_multisite() ) { |
1033 | 1040 | |
1034 | 1041 | /** This filter is documented in wp-includes/option.php */ |
1035 | | $default = apply_filters( 'default_site_option_' . $option, $default, $option ); |
| 1042 | $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); |
1036 | 1043 | $value = get_option($option, $default); |
1037 | 1044 | } else { |
1038 | | $cache_key = "{$wpdb->siteid}:$option"; |
| 1045 | $cache_key = "{$network_id}:$option"; |
1039 | 1046 | if ( $use_cache ) |
1040 | 1047 | $value = wp_cache_get($cache_key, 'site-options'); |
1041 | 1048 | |
1042 | 1049 | 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 ) ); |
| 1050 | $row = $wpdb->get_row( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); |
1044 | 1051 | |
1045 | 1052 | // Has to be get_row instead of get_var because of funkiness with 0, false, null values |
1046 | 1053 | if ( is_object( $row ) ) { |
… |
… |
function get_site_option( $option, $default = false, $use_cache = true ) { |
1055 | 1062 | wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
1056 | 1063 | |
1057 | 1064 | /** This filter is documented in wp-includes/option.php */ |
1058 | | $value = apply_filters( 'default_site_option_' . $option, $default, $option ); |
| 1065 | $value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); |
1059 | 1066 | } |
1060 | 1067 | } |
1061 | 1068 | } |
… |
… |
function get_site_option( $option, $default = false, $use_cache = true ) { |
1068 | 1075 | * @since 2.9.0 As 'site_option_' . $key |
1069 | 1076 | * @since 3.0.0 |
1070 | 1077 | * @since 4.4.0 The `$option` parameter was added |
| 1078 | * @since 4.4.0 The `$network_id` parameter was added |
1071 | 1079 | * |
1072 | 1080 | * @param mixed $value Value of site option. |
1073 | 1081 | * @param string $option Option name. |
1074 | 1082 | */ |
1075 | | return apply_filters( 'site_option_' . $option, $value, $option ); |
| 1083 | return apply_filters( 'site_option_' . $option, $value, $option, $network_id ); |
1076 | 1084 | } |
1077 | 1085 | |
1078 | 1086 | /** |
… |
… |
function get_site_option( $option, $default = false, $use_cache = true ) { |
1086 | 1094 | * |
1087 | 1095 | * @global wpdb $wpdb |
1088 | 1096 | * |
1089 | | * @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. |
| 1097 | * @param string $option Name of option to add. Expected to not be SQL-escaped. |
| 1098 | * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. |
| 1099 | * @param bool|int $network_id The ID of the network for the option to retrieve. Multisite only. Default false. |
1091 | 1100 | * @return bool False if option was not added and true if option was added. |
1092 | 1101 | */ |
1093 | | function add_site_option( $option, $value ) { |
| 1102 | function add_site_option( $option, $value, $network_id = false ) { |
1094 | 1103 | global $wpdb; |
1095 | 1104 | |
1096 | 1105 | wp_protect_special_option( $option ); |
1097 | 1106 | |
| 1107 | if( ! $network_id ){ |
| 1108 | $network_id = $wpdb->siteid; |
| 1109 | } |
| 1110 | |
1098 | 1111 | /** |
1099 | 1112 | * Filter the value of a specific site option before it is added. |
1100 | 1113 | * |
… |
… |
function add_site_option( $option, $value ) { |
1103 | 1116 | * @since 2.9.0 As 'pre_add_site_option_' . $key |
1104 | 1117 | * @since 3.0.0 |
1105 | 1118 | * @since 4.4.0 The `$option` parameter was added |
| 1119 | * @since 4.4.0 The `$network_id` parameter was added |
1106 | 1120 | * |
1107 | 1121 | * @param mixed $value Value of site option. |
1108 | 1122 | * @param string $option Option name. |
1109 | 1123 | */ |
1110 | | $value = apply_filters( 'pre_add_site_option_' . $option, $value, $option ); |
| 1124 | $value = apply_filters( 'pre_add_site_option_' . $option, $value, $option, $network_id ); |
1111 | 1125 | |
1112 | | $notoptions_key = "{$wpdb->siteid}:notoptions"; |
| 1126 | $notoptions_key = "{$network_id}:notoptions"; |
1113 | 1127 | |
1114 | 1128 | if ( !is_multisite() ) { |
1115 | 1129 | $result = add_option( $option, $value ); |
1116 | 1130 | } else { |
1117 | | $cache_key = "{$wpdb->siteid}:$option"; |
| 1131 | $cache_key = "{$network_id}:$option"; |
1118 | 1132 | |
1119 | 1133 | // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query |
1120 | 1134 | $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
1121 | 1135 | if ( ! is_array( $notoptions ) || ! isset( $notoptions[$option] ) ) |
1122 | | if ( false !== get_site_option( $option ) ) |
| 1136 | if ( false !== get_site_option( $option, false, true, $network_id ) ) |
1123 | 1137 | return false; |
1124 | 1138 | |
1125 | 1139 | $value = sanitize_option( $option, $value ); |
1126 | 1140 | |
1127 | 1141 | $serialized_value = maybe_serialize( $value ); |
1128 | | $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); |
| 1142 | $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); |
1129 | 1143 | |
1130 | 1144 | if ( ! $result ) |
1131 | 1145 | return false; |
… |
… |
function add_site_option( $option, $value ) { |
1149 | 1163 | * |
1150 | 1164 | * @since 2.9.0 As "add_site_option_{$key}" |
1151 | 1165 | * @since 3.0.0 |
| 1166 | * @since 4.4.0 The `$network_id` parameter was added |
1152 | 1167 | * |
1153 | 1168 | * @param string $option Name of site option. |
1154 | 1169 | * @param mixed $value Value of site option. |
| 1170 | * |
1155 | 1171 | */ |
1156 | | do_action( "add_site_option_{$option}", $option, $value ); |
| 1172 | do_action( "add_site_option_{$option}", $option, $value, $network_id ); |
1157 | 1173 | |
1158 | 1174 | /** |
1159 | 1175 | * Fires after a site option has been successfully added. |
1160 | 1176 | * |
1161 | 1177 | * @since 3.0.0 |
| 1178 | * @since 4.4.0 The `$network_id` parameter was added |
1162 | 1179 | * |
1163 | 1180 | * @param string $option Name of site option. |
1164 | 1181 | * @param mixed $value Value of site option. |
1165 | 1182 | */ |
1166 | | do_action( "add_site_option", $option, $value ); |
| 1183 | do_action( "add_site_option", $option, $value, $network_id ); |
1167 | 1184 | |
1168 | 1185 | return true; |
1169 | 1186 | } |
… |
… |
function add_site_option( $option, $value ) { |
1180 | 1197 | * @global wpdb $wpdb |
1181 | 1198 | * |
1182 | 1199 | * @param string $option Name of option to remove. Expected to not be SQL-escaped. |
| 1200 | * @param bool|int $network_id The ID of the network for the option to retrieve. Multisite only. Default false. |
1183 | 1201 | * @return bool True, if succeed. False, if failure. |
1184 | 1202 | */ |
1185 | | function delete_site_option( $option ) { |
| 1203 | function delete_site_option( $option, $network_id = false ) { |
1186 | 1204 | global $wpdb; |
1187 | 1205 | |
1188 | 1206 | // ms_protect_special_option( $option ); @todo |
1189 | 1207 | |
| 1208 | if( ! $network_id ){ |
| 1209 | $network_id = $wpdb->siteid; |
| 1210 | } |
| 1211 | |
1190 | 1212 | /** |
1191 | 1213 | * Fires immediately before a specific site option is deleted. |
1192 | 1214 | * |
… |
… |
function delete_site_option( $option ) { |
1194 | 1216 | * |
1195 | 1217 | * @since 3.0.0 |
1196 | 1218 | * @since 4.4.0 The `$option` parameter was added |
| 1219 | * @since 4.4.0 The `$network_id` parameter was added |
1197 | 1220 | * |
1198 | 1221 | * @param string $option Option name. |
1199 | 1222 | */ |
1200 | | do_action( 'pre_delete_site_option_' . $option, $option ); |
| 1223 | do_action( 'pre_delete_site_option_' . $option, $option, $network_id ); |
1201 | 1224 | |
1202 | 1225 | if ( !is_multisite() ) { |
1203 | 1226 | $result = delete_option( $option ); |
1204 | 1227 | } 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 ) ); |
| 1228 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); |
1206 | 1229 | if ( is_null( $row ) || !$row->meta_id ) |
1207 | 1230 | return false; |
1208 | | $cache_key = "{$wpdb->siteid}:$option"; |
| 1231 | $cache_key = "{$network_id}:$option"; |
1209 | 1232 | wp_cache_delete( $cache_key, 'site-options' ); |
1210 | 1233 | |
1211 | | $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $wpdb->siteid ) ); |
| 1234 | $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); |
1212 | 1235 | } |
1213 | 1236 | |
1214 | 1237 | if ( $result ) { |
… |
… |
function delete_site_option( $option ) { |
1220 | 1243 | * |
1221 | 1244 | * @since 2.9.0 As "delete_site_option_{$key}" |
1222 | 1245 | * @since 3.0.0 |
| 1246 | * @since 4.4.0 The `$network_id` parameter was added |
1223 | 1247 | * |
1224 | 1248 | * @param string $option Name of the site option. |
1225 | 1249 | */ |
1226 | | do_action( "delete_site_option_{$option}", $option ); |
| 1250 | do_action( "delete_site_option_{$option}", $option, $network_id ); |
1227 | 1251 | |
1228 | 1252 | /** |
1229 | 1253 | * Fires after a site option has been deleted. |
1230 | 1254 | * |
1231 | 1255 | * @since 3.0.0 |
| 1256 | * @since 4.4.0 The `$network_id` parameter was added |
1232 | 1257 | * |
1233 | 1258 | * @param string $option Name of the site option. |
1234 | 1259 | */ |
1235 | | do_action( "delete_site_option", $option ); |
| 1260 | do_action( "delete_site_option", $option, $network_id ); |
1236 | 1261 | |
1237 | 1262 | return true; |
1238 | 1263 | } |
… |
… |
function delete_site_option( $option ) { |
1250 | 1275 | * |
1251 | 1276 | * @param string $option Name of option. Expected to not be SQL-escaped. |
1252 | 1277 | * @param mixed $value Option value. Expected to not be SQL-escaped. |
| 1278 | * @param bool|int $network_id The ID of the network for the option to retrieve. Multisite only. Default false. |
1253 | 1279 | * @return bool False if value was not updated and true if value was updated. |
1254 | 1280 | */ |
1255 | | function update_site_option( $option, $value ) { |
| 1281 | function update_site_option( $option, $value, $network_id = false ) { |
1256 | 1282 | global $wpdb; |
1257 | 1283 | |
1258 | 1284 | wp_protect_special_option( $option ); |
1259 | 1285 | |
1260 | | $old_value = get_site_option( $option ); |
| 1286 | if( ! $network_id ){ |
| 1287 | $network_id = $wpdb->siteid; |
| 1288 | } |
| 1289 | |
| 1290 | $old_value = get_site_option( $option, false, true, $network_id ); |
1261 | 1291 | |
1262 | 1292 | /** |
1263 | 1293 | * Filter a specific site option before its value is updated. |
… |
… |
function update_site_option( $option, $value ) { |
1267 | 1297 | * @since 2.9.0 As 'pre_update_site_option_' . $key |
1268 | 1298 | * @since 3.0.0 |
1269 | 1299 | * @since 4.4.0 The `$option` parameter was added |
| 1300 | * @since 4.4.0 The `$network_id` parameter was added |
1270 | 1301 | * |
1271 | 1302 | * @param mixed $value New value of site option. |
1272 | 1303 | * @param mixed $old_value Old value of site option. |
1273 | 1304 | * @param string $option Option name. |
1274 | 1305 | */ |
1275 | | $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value, $option ); |
| 1306 | $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value, $option, $network_id ); |
1276 | 1307 | |
1277 | 1308 | if ( $value === $old_value ) |
1278 | 1309 | return false; |
1279 | 1310 | |
1280 | 1311 | if ( false === $old_value ) |
1281 | | return add_site_option( $option, $value ); |
| 1312 | return add_site_option( $option, $value, $network_id ); |
1282 | 1313 | |
1283 | | $notoptions_key = "{$wpdb->siteid}:notoptions"; |
| 1314 | $notoptions_key = "{$network_id}:notoptions"; |
1284 | 1315 | $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
1285 | 1316 | if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { |
1286 | 1317 | unset( $notoptions[$option] ); |
… |
… |
function update_site_option( $option, $value ) { |
1293 | 1324 | $value = sanitize_option( $option, $value ); |
1294 | 1325 | |
1295 | 1326 | $serialized_value = maybe_serialize( $value ); |
1296 | | $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) ); |
| 1327 | $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) ); |
1297 | 1328 | |
1298 | 1329 | if ( $result ) { |
1299 | | $cache_key = "{$wpdb->siteid}:$option"; |
| 1330 | $cache_key = "{$network_id}:$option"; |
1300 | 1331 | wp_cache_set( $cache_key, $value, 'site-options' ); |
1301 | 1332 | } |
1302 | 1333 | } |
… |
… |
function update_site_option( $option, $value ) { |
1310 | 1341 | * |
1311 | 1342 | * @since 2.9.0 As "update_site_option_{$key}" |
1312 | 1343 | * @since 3.0.0 |
| 1344 | * @since 4.4.0 The `$network_id` parameter was added |
1313 | 1345 | * |
1314 | 1346 | * @param string $option Name of site option. |
1315 | 1347 | * @param mixed $value Current value of site option. |
1316 | 1348 | * @param mixed $old_value Old value of site option. |
1317 | 1349 | */ |
1318 | | do_action( "update_site_option_{$option}", $option, $value, $old_value ); |
| 1350 | do_action( "update_site_option_{$option}", $option, $value, $old_value, $network_id ); |
1319 | 1351 | |
1320 | 1352 | /** |
1321 | 1353 | * Fires after the value of a site option has been successfully updated. |
1322 | 1354 | * |
1323 | 1355 | * @since 3.0.0 |
| 1356 | * @since 4.4.0 The `$network_id` parameter was added |
1324 | 1357 | * |
1325 | 1358 | * @param string $option Name of site option. |
1326 | 1359 | * @param mixed $value Current value of site option. |
1327 | 1360 | * @param mixed $old_value Old value of site option. |
1328 | 1361 | */ |
1329 | | do_action( "update_site_option", $option, $value, $old_value ); |
| 1362 | do_action( "update_site_option", $option, $value, $old_value, $network_id ); |
1330 | 1363 | |
1331 | 1364 | return true; |
1332 | 1365 | } |