Edit File by line
/home/barbar84/www/wp-inclu...
File: option.php
}
[1000] Fix | Delete
}
[1001] Fix | Delete
[1002] Fix | Delete
/**
[1003] Fix | Delete
* Saves and restores user interface settings stored in a cookie.
[1004] Fix | Delete
*
[1005] Fix | Delete
* Checks if the current user-settings cookie is updated and stores it. When no
[1006] Fix | Delete
* cookie exists (different browser used), adds the last saved cookie restoring
[1007] Fix | Delete
* the settings.
[1008] Fix | Delete
*
[1009] Fix | Delete
* @since 2.7.0
[1010] Fix | Delete
*/
[1011] Fix | Delete
function wp_user_settings() {
[1012] Fix | Delete
[1013] Fix | Delete
if ( ! is_admin() || wp_doing_ajax() ) {
[1014] Fix | Delete
return;
[1015] Fix | Delete
}
[1016] Fix | Delete
[1017] Fix | Delete
$user_id = get_current_user_id();
[1018] Fix | Delete
if ( ! $user_id ) {
[1019] Fix | Delete
return;
[1020] Fix | Delete
}
[1021] Fix | Delete
[1022] Fix | Delete
if ( ! is_user_member_of_blog() ) {
[1023] Fix | Delete
return;
[1024] Fix | Delete
}
[1025] Fix | Delete
[1026] Fix | Delete
$settings = (string) get_user_option( 'user-settings', $user_id );
[1027] Fix | Delete
[1028] Fix | Delete
if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
[1029] Fix | Delete
$cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
[1030] Fix | Delete
[1031] Fix | Delete
// No change or both empty.
[1032] Fix | Delete
if ( $cookie == $settings ) {
[1033] Fix | Delete
return;
[1034] Fix | Delete
}
[1035] Fix | Delete
[1036] Fix | Delete
$last_saved = (int) get_user_option( 'user-settings-time', $user_id );
[1037] Fix | Delete
$current = isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] ) : 0;
[1038] Fix | Delete
[1039] Fix | Delete
// The cookie is newer than the saved value. Update the user_option and leave the cookie as-is.
[1040] Fix | Delete
if ( $current > $last_saved ) {
[1041] Fix | Delete
update_user_option( $user_id, 'user-settings', $cookie, false );
[1042] Fix | Delete
update_user_option( $user_id, 'user-settings-time', time() - 5, false );
[1043] Fix | Delete
return;
[1044] Fix | Delete
}
[1045] Fix | Delete
}
[1046] Fix | Delete
[1047] Fix | Delete
// The cookie is not set in the current browser or the saved value is newer.
[1048] Fix | Delete
$secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) );
[1049] Fix | Delete
setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
[1050] Fix | Delete
setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
[1051] Fix | Delete
$_COOKIE[ 'wp-settings-' . $user_id ] = $settings;
[1052] Fix | Delete
}
[1053] Fix | Delete
[1054] Fix | Delete
/**
[1055] Fix | Delete
* Retrieves user interface setting value based on setting name.
[1056] Fix | Delete
*
[1057] Fix | Delete
* @since 2.7.0
[1058] Fix | Delete
*
[1059] Fix | Delete
* @param string $name The name of the setting.
[1060] Fix | Delete
* @param string|false $default Optional. Default value to return when $name is not set. Default false.
[1061] Fix | Delete
* @return mixed The last saved user setting or the default value/false if it doesn't exist.
[1062] Fix | Delete
*/
[1063] Fix | Delete
function get_user_setting( $name, $default = false ) {
[1064] Fix | Delete
$all_user_settings = get_all_user_settings();
[1065] Fix | Delete
[1066] Fix | Delete
return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default;
[1067] Fix | Delete
}
[1068] Fix | Delete
[1069] Fix | Delete
/**
[1070] Fix | Delete
* Adds or updates user interface setting.
[1071] Fix | Delete
*
[1072] Fix | Delete
* Both $name and $value can contain only ASCII letters, numbers, hyphens, and underscores.
[1073] Fix | Delete
*
[1074] Fix | Delete
* This function has to be used before any output has started as it calls setcookie().
[1075] Fix | Delete
*
[1076] Fix | Delete
* @since 2.8.0
[1077] Fix | Delete
*
[1078] Fix | Delete
* @param string $name The name of the setting.
[1079] Fix | Delete
* @param string $value The value for the setting.
[1080] Fix | Delete
* @return bool|null True if set successfully, false otherwise.
[1081] Fix | Delete
* Null if the current user is not a member of the site.
[1082] Fix | Delete
*/
[1083] Fix | Delete
function set_user_setting( $name, $value ) {
[1084] Fix | Delete
if ( headers_sent() ) {
[1085] Fix | Delete
return false;
[1086] Fix | Delete
}
[1087] Fix | Delete
[1088] Fix | Delete
$all_user_settings = get_all_user_settings();
[1089] Fix | Delete
$all_user_settings[ $name ] = $value;
[1090] Fix | Delete
[1091] Fix | Delete
return wp_set_all_user_settings( $all_user_settings );
[1092] Fix | Delete
}
[1093] Fix | Delete
[1094] Fix | Delete
/**
[1095] Fix | Delete
* Deletes user interface settings.
[1096] Fix | Delete
*
[1097] Fix | Delete
* Deleting settings would reset them to the defaults.
[1098] Fix | Delete
*
[1099] Fix | Delete
* This function has to be used before any output has started as it calls setcookie().
[1100] Fix | Delete
*
[1101] Fix | Delete
* @since 2.7.0
[1102] Fix | Delete
*
[1103] Fix | Delete
* @param string $names The name or array of names of the setting to be deleted.
[1104] Fix | Delete
* @return bool|null True if deleted successfully, false otherwise.
[1105] Fix | Delete
* Null if the current user is not a member of the site.
[1106] Fix | Delete
*/
[1107] Fix | Delete
function delete_user_setting( $names ) {
[1108] Fix | Delete
if ( headers_sent() ) {
[1109] Fix | Delete
return false;
[1110] Fix | Delete
}
[1111] Fix | Delete
[1112] Fix | Delete
$all_user_settings = get_all_user_settings();
[1113] Fix | Delete
$names = (array) $names;
[1114] Fix | Delete
$deleted = false;
[1115] Fix | Delete
[1116] Fix | Delete
foreach ( $names as $name ) {
[1117] Fix | Delete
if ( isset( $all_user_settings[ $name ] ) ) {
[1118] Fix | Delete
unset( $all_user_settings[ $name ] );
[1119] Fix | Delete
$deleted = true;
[1120] Fix | Delete
}
[1121] Fix | Delete
}
[1122] Fix | Delete
[1123] Fix | Delete
if ( $deleted ) {
[1124] Fix | Delete
return wp_set_all_user_settings( $all_user_settings );
[1125] Fix | Delete
}
[1126] Fix | Delete
[1127] Fix | Delete
return false;
[1128] Fix | Delete
}
[1129] Fix | Delete
[1130] Fix | Delete
/**
[1131] Fix | Delete
* Retrieves all user interface settings.
[1132] Fix | Delete
*
[1133] Fix | Delete
* @since 2.7.0
[1134] Fix | Delete
*
[1135] Fix | Delete
* @global array $_updated_user_settings
[1136] Fix | Delete
*
[1137] Fix | Delete
* @return array The last saved user settings or empty array.
[1138] Fix | Delete
*/
[1139] Fix | Delete
function get_all_user_settings() {
[1140] Fix | Delete
global $_updated_user_settings;
[1141] Fix | Delete
[1142] Fix | Delete
$user_id = get_current_user_id();
[1143] Fix | Delete
if ( ! $user_id ) {
[1144] Fix | Delete
return array();
[1145] Fix | Delete
}
[1146] Fix | Delete
[1147] Fix | Delete
if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) {
[1148] Fix | Delete
return $_updated_user_settings;
[1149] Fix | Delete
}
[1150] Fix | Delete
[1151] Fix | Delete
$user_settings = array();
[1152] Fix | Delete
[1153] Fix | Delete
if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
[1154] Fix | Delete
$cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
[1155] Fix | Delete
[1156] Fix | Delete
if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char.
[1157] Fix | Delete
parse_str( $cookie, $user_settings );
[1158] Fix | Delete
}
[1159] Fix | Delete
} else {
[1160] Fix | Delete
$option = get_user_option( 'user-settings', $user_id );
[1161] Fix | Delete
[1162] Fix | Delete
if ( $option && is_string( $option ) ) {
[1163] Fix | Delete
parse_str( $option, $user_settings );
[1164] Fix | Delete
}
[1165] Fix | Delete
}
[1166] Fix | Delete
[1167] Fix | Delete
$_updated_user_settings = $user_settings;
[1168] Fix | Delete
return $user_settings;
[1169] Fix | Delete
}
[1170] Fix | Delete
[1171] Fix | Delete
/**
[1172] Fix | Delete
* Private. Sets all user interface settings.
[1173] Fix | Delete
*
[1174] Fix | Delete
* @since 2.8.0
[1175] Fix | Delete
* @access private
[1176] Fix | Delete
*
[1177] Fix | Delete
* @global array $_updated_user_settings
[1178] Fix | Delete
*
[1179] Fix | Delete
* @param array $user_settings User settings.
[1180] Fix | Delete
* @return bool|null True if set successfully, false if the current user could not be found.
[1181] Fix | Delete
* Null if the current user is not a member of the site.
[1182] Fix | Delete
*/
[1183] Fix | Delete
function wp_set_all_user_settings( $user_settings ) {
[1184] Fix | Delete
global $_updated_user_settings;
[1185] Fix | Delete
[1186] Fix | Delete
$user_id = get_current_user_id();
[1187] Fix | Delete
if ( ! $user_id ) {
[1188] Fix | Delete
return false;
[1189] Fix | Delete
}
[1190] Fix | Delete
[1191] Fix | Delete
if ( ! is_user_member_of_blog() ) {
[1192] Fix | Delete
return;
[1193] Fix | Delete
}
[1194] Fix | Delete
[1195] Fix | Delete
$settings = '';
[1196] Fix | Delete
foreach ( $user_settings as $name => $value ) {
[1197] Fix | Delete
$_name = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name );
[1198] Fix | Delete
$_value = preg_replace( '/[^A-Za-z0-9_-]+/', '', $value );
[1199] Fix | Delete
[1200] Fix | Delete
if ( ! empty( $_name ) ) {
[1201] Fix | Delete
$settings .= $_name . '=' . $_value . '&';
[1202] Fix | Delete
}
[1203] Fix | Delete
}
[1204] Fix | Delete
[1205] Fix | Delete
$settings = rtrim( $settings, '&' );
[1206] Fix | Delete
parse_str( $settings, $_updated_user_settings );
[1207] Fix | Delete
[1208] Fix | Delete
update_user_option( $user_id, 'user-settings', $settings, false );
[1209] Fix | Delete
update_user_option( $user_id, 'user-settings-time', time(), false );
[1210] Fix | Delete
[1211] Fix | Delete
return true;
[1212] Fix | Delete
}
[1213] Fix | Delete
[1214] Fix | Delete
/**
[1215] Fix | Delete
* Deletes the user settings of the current user.
[1216] Fix | Delete
*
[1217] Fix | Delete
* @since 2.7.0
[1218] Fix | Delete
*/
[1219] Fix | Delete
function delete_all_user_settings() {
[1220] Fix | Delete
$user_id = get_current_user_id();
[1221] Fix | Delete
if ( ! $user_id ) {
[1222] Fix | Delete
return;
[1223] Fix | Delete
}
[1224] Fix | Delete
[1225] Fix | Delete
update_user_option( $user_id, 'user-settings', '', false );
[1226] Fix | Delete
setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
[1227] Fix | Delete
}
[1228] Fix | Delete
[1229] Fix | Delete
/**
[1230] Fix | Delete
* Retrieve an option value for the current network based on name of option.
[1231] Fix | Delete
*
[1232] Fix | Delete
* @since 2.8.0
[1233] Fix | Delete
* @since 4.4.0 The `$use_cache` parameter was deprecated.
[1234] Fix | Delete
* @since 4.4.0 Modified into wrapper for get_network_option()
[1235] Fix | Delete
*
[1236] Fix | Delete
* @see get_network_option()
[1237] Fix | Delete
*
[1238] Fix | Delete
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
[1239] Fix | Delete
* @param mixed $default Optional. Value to return if the option doesn't exist. Default false.
[1240] Fix | Delete
* @param bool $deprecated Whether to use cache. Multisite only. Always set to true.
[1241] Fix | Delete
* @return mixed Value set for the option.
[1242] Fix | Delete
*/
[1243] Fix | Delete
function get_site_option( $option, $default = false, $deprecated = true ) {
[1244] Fix | Delete
return get_network_option( null, $option, $default );
[1245] Fix | Delete
}
[1246] Fix | Delete
[1247] Fix | Delete
/**
[1248] Fix | Delete
* Adds a new option for the current network.
[1249] Fix | Delete
*
[1250] Fix | Delete
* Existing options will not be updated. Note that prior to 3.3 this wasn't the case.
[1251] Fix | Delete
*
[1252] Fix | Delete
* @since 2.8.0
[1253] Fix | Delete
* @since 4.4.0 Modified into wrapper for add_network_option()
[1254] Fix | Delete
*
[1255] Fix | Delete
* @see add_network_option()
[1256] Fix | Delete
*
[1257] Fix | Delete
* @param string $option Name of the option to add. Expected to not be SQL-escaped.
[1258] Fix | Delete
* @param mixed $value Option value, can be anything. Expected to not be SQL-escaped.
[1259] Fix | Delete
* @return bool True if the option was added, false otherwise.
[1260] Fix | Delete
*/
[1261] Fix | Delete
function add_site_option( $option, $value ) {
[1262] Fix | Delete
return add_network_option( null, $option, $value );
[1263] Fix | Delete
}
[1264] Fix | Delete
[1265] Fix | Delete
/**
[1266] Fix | Delete
* Removes a option by name for the current network.
[1267] Fix | Delete
*
[1268] Fix | Delete
* @since 2.8.0
[1269] Fix | Delete
* @since 4.4.0 Modified into wrapper for delete_network_option()
[1270] Fix | Delete
*
[1271] Fix | Delete
* @see delete_network_option()
[1272] Fix | Delete
*
[1273] Fix | Delete
* @param string $option Name of the option to delete. Expected to not be SQL-escaped.
[1274] Fix | Delete
* @return bool True if the option was deleted, false otherwise.
[1275] Fix | Delete
*/
[1276] Fix | Delete
function delete_site_option( $option ) {
[1277] Fix | Delete
return delete_network_option( null, $option );
[1278] Fix | Delete
}
[1279] Fix | Delete
[1280] Fix | Delete
/**
[1281] Fix | Delete
* Updates the value of an option that was already added for the current network.
[1282] Fix | Delete
*
[1283] Fix | Delete
* @since 2.8.0
[1284] Fix | Delete
* @since 4.4.0 Modified into wrapper for update_network_option()
[1285] Fix | Delete
*
[1286] Fix | Delete
* @see update_network_option()
[1287] Fix | Delete
*
[1288] Fix | Delete
* @param string $option Name of the option. Expected to not be SQL-escaped.
[1289] Fix | Delete
* @param mixed $value Option value. Expected to not be SQL-escaped.
[1290] Fix | Delete
* @return bool True if the value was updated, false otherwise.
[1291] Fix | Delete
*/
[1292] Fix | Delete
function update_site_option( $option, $value ) {
[1293] Fix | Delete
return update_network_option( null, $option, $value );
[1294] Fix | Delete
}
[1295] Fix | Delete
[1296] Fix | Delete
/**
[1297] Fix | Delete
* Retrieves a network's option value based on the option name.
[1298] Fix | Delete
*
[1299] Fix | Delete
* @since 4.4.0
[1300] Fix | Delete
*
[1301] Fix | Delete
* @see get_option()
[1302] Fix | Delete
*
[1303] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1304] Fix | Delete
*
[1305] Fix | Delete
* @param int $network_id ID of the network. Can be null to default to the current network ID.
[1306] Fix | Delete
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
[1307] Fix | Delete
* @param mixed $default Optional. Value to return if the option doesn't exist. Default false.
[1308] Fix | Delete
* @return mixed Value set for the option.
[1309] Fix | Delete
*/
[1310] Fix | Delete
function get_network_option( $network_id, $option, $default = false ) {
[1311] Fix | Delete
global $wpdb;
[1312] Fix | Delete
[1313] Fix | Delete
if ( $network_id && ! is_numeric( $network_id ) ) {
[1314] Fix | Delete
return false;
[1315] Fix | Delete
}
[1316] Fix | Delete
[1317] Fix | Delete
$network_id = (int) $network_id;
[1318] Fix | Delete
[1319] Fix | Delete
// Fallback to the current network if a network ID is not specified.
[1320] Fix | Delete
if ( ! $network_id ) {
[1321] Fix | Delete
$network_id = get_current_network_id();
[1322] Fix | Delete
}
[1323] Fix | Delete
[1324] Fix | Delete
/**
[1325] Fix | Delete
* Filters the value of an existing network option before it is retrieved.
[1326] Fix | Delete
*
[1327] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the option name.
[1328] Fix | Delete
*
[1329] Fix | Delete
* Returning a truthy value from the filter will effectively short-circuit retrieval
[1330] Fix | Delete
* and return the passed value instead.
[1331] Fix | Delete
*
[1332] Fix | Delete
* @since 2.9.0 As 'pre_site_option_' . $key
[1333] Fix | Delete
* @since 3.0.0
[1334] Fix | Delete
* @since 4.4.0 The `$option` parameter was added.
[1335] Fix | Delete
* @since 4.7.0 The `$network_id` parameter was added.
[1336] Fix | Delete
* @since 4.9.0 The `$default` parameter was added.
[1337] Fix | Delete
*
[1338] Fix | Delete
* @param mixed $pre_option The value to return instead of the option value. This differs
[1339] Fix | Delete
* from `$default`, which is used as the fallback value in the event
[1340] Fix | Delete
* the option doesn't exist elsewhere in get_network_option().
[1341] Fix | Delete
* Default false (to skip past the short-circuit).
[1342] Fix | Delete
* @param string $option Option name.
[1343] Fix | Delete
* @param int $network_id ID of the network.
[1344] Fix | Delete
* @param mixed $default The fallback value to return if the option does not exist.
[1345] Fix | Delete
* Default false.
[1346] Fix | Delete
*/
[1347] Fix | Delete
$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default );
[1348] Fix | Delete
[1349] Fix | Delete
if ( false !== $pre ) {
[1350] Fix | Delete
return $pre;
[1351] Fix | Delete
}
[1352] Fix | Delete
[1353] Fix | Delete
// Prevent non-existent options from triggering multiple queries.
[1354] Fix | Delete
$notoptions_key = "$network_id:notoptions";
[1355] Fix | Delete
$notoptions = wp_cache_get( $notoptions_key, 'site-options' );
[1356] Fix | Delete
[1357] Fix | Delete
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
[1358] Fix | Delete
[1359] Fix | Delete
/**
[1360] Fix | Delete
* Filters a specific default network option.
[1361] Fix | Delete
*
[1362] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the option name.
[1363] Fix | Delete
*
[1364] Fix | Delete
* @since 3.4.0
[1365] Fix | Delete
* @since 4.4.0 The `$option` parameter was added.
[1366] Fix | Delete
* @since 4.7.0 The `$network_id` parameter was added.
[1367] Fix | Delete
*
[1368] Fix | Delete
* @param mixed $default The value to return if the site option does not exist
[1369] Fix | Delete
* in the database.
[1370] Fix | Delete
* @param string $option Option name.
[1371] Fix | Delete
* @param int $network_id ID of the network.
[1372] Fix | Delete
*/
[1373] Fix | Delete
return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );
[1374] Fix | Delete
}
[1375] Fix | Delete
[1376] Fix | Delete
if ( ! is_multisite() ) {
[1377] Fix | Delete
/** This filter is documented in wp-includes/option.php */
[1378] Fix | Delete
$default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
[1379] Fix | Delete
$value = get_option( $option, $default );
[1380] Fix | Delete
} else {
[1381] Fix | Delete
$cache_key = "$network_id:$option";
[1382] Fix | Delete
$value = wp_cache_get( $cache_key, 'site-options' );
[1383] Fix | Delete
[1384] Fix | Delete
if ( ! isset( $value ) || false === $value ) {
[1385] Fix | Delete
$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
[1386] Fix | Delete
[1387] Fix | Delete
// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values.
[1388] Fix | Delete
if ( is_object( $row ) ) {
[1389] Fix | Delete
$value = $row->meta_value;
[1390] Fix | Delete
$value = maybe_unserialize( $value );
[1391] Fix | Delete
wp_cache_set( $cache_key, $value, 'site-options' );
[1392] Fix | Delete
} else {
[1393] Fix | Delete
if ( ! is_array( $notoptions ) ) {
[1394] Fix | Delete
$notoptions = array();
[1395] Fix | Delete
}
[1396] Fix | Delete
[1397] Fix | Delete
$notoptions[ $option ] = true;
[1398] Fix | Delete
wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
[1399] Fix | Delete
[1400] Fix | Delete
/** This filter is documented in wp-includes/option.php */
[1401] Fix | Delete
$value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
[1402] Fix | Delete
}
[1403] Fix | Delete
}
[1404] Fix | Delete
}
[1405] Fix | Delete
[1406] Fix | Delete
if ( ! is_array( $notoptions ) ) {
[1407] Fix | Delete
$notoptions = array();
[1408] Fix | Delete
wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
[1409] Fix | Delete
}
[1410] Fix | Delete
[1411] Fix | Delete
/**
[1412] Fix | Delete
* Filters the value of an existing network option.
[1413] Fix | Delete
*
[1414] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the option name.
[1415] Fix | Delete
*
[1416] Fix | Delete
* @since 2.9.0 As 'site_option_' . $key
[1417] Fix | Delete
* @since 3.0.0
[1418] Fix | Delete
* @since 4.4.0 The `$option` parameter was added.
[1419] Fix | Delete
* @since 4.7.0 The `$network_id` parameter was added.
[1420] Fix | Delete
*
[1421] Fix | Delete
* @param mixed $value Value of network option.
[1422] Fix | Delete
* @param string $option Option name.
[1423] Fix | Delete
* @param int $network_id ID of the network.
[1424] Fix | Delete
*/
[1425] Fix | Delete
return apply_filters( "site_option_{$option}", $value, $option, $network_id );
[1426] Fix | Delete
}
[1427] Fix | Delete
[1428] Fix | Delete
/**
[1429] Fix | Delete
* Adds a new network option.
[1430] Fix | Delete
*
[1431] Fix | Delete
* Existing options will not be updated.
[1432] Fix | Delete
*
[1433] Fix | Delete
* @since 4.4.0
[1434] Fix | Delete
*
[1435] Fix | Delete
* @see add_option()
[1436] Fix | Delete
*
[1437] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1438] Fix | Delete
*
[1439] Fix | Delete
* @param int $network_id ID of the network. Can be null to default to the current network ID.
[1440] Fix | Delete
* @param string $option Name of the option to add. Expected to not be SQL-escaped.
[1441] Fix | Delete
* @param mixed $value Option value, can be anything. Expected to not be SQL-escaped.
[1442] Fix | Delete
* @return bool True if the option was added, false otherwise.
[1443] Fix | Delete
*/
[1444] Fix | Delete
function add_network_option( $network_id, $option, $value ) {
[1445] Fix | Delete
global $wpdb;
[1446] Fix | Delete
[1447] Fix | Delete
if ( $network_id && ! is_numeric( $network_id ) ) {
[1448] Fix | Delete
return false;
[1449] Fix | Delete
}
[1450] Fix | Delete
[1451] Fix | Delete
$network_id = (int) $network_id;
[1452] Fix | Delete
[1453] Fix | Delete
// Fallback to the current network if a network ID is not specified.
[1454] Fix | Delete
if ( ! $network_id ) {
[1455] Fix | Delete
$network_id = get_current_network_id();
[1456] Fix | Delete
}
[1457] Fix | Delete
[1458] Fix | Delete
wp_protect_special_option( $option );
[1459] Fix | Delete
[1460] Fix | Delete
/**
[1461] Fix | Delete
* Filters the value of a specific network option before it is added.
[1462] Fix | Delete
*
[1463] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the option name.
[1464] Fix | Delete
*
[1465] Fix | Delete
* @since 2.9.0 As 'pre_add_site_option_' . $key
[1466] Fix | Delete
* @since 3.0.0
[1467] Fix | Delete
* @since 4.4.0 The `$option` parameter was added.
[1468] Fix | Delete
* @since 4.7.0 The `$network_id` parameter was added.
[1469] Fix | Delete
*
[1470] Fix | Delete
* @param mixed $value Value of network option.
[1471] Fix | Delete
* @param string $option Option name.
[1472] Fix | Delete
* @param int $network_id ID of the network.
[1473] Fix | Delete
*/
[1474] Fix | Delete
$value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id );
[1475] Fix | Delete
[1476] Fix | Delete
$notoptions_key = "$network_id:notoptions";
[1477] Fix | Delete
[1478] Fix | Delete
if ( ! is_multisite() ) {
[1479] Fix | Delete
$result = add_option( $option, $value, '', 'no' );
[1480] Fix | Delete
} else {
[1481] Fix | Delete
$cache_key = "$network_id:$option";
[1482] Fix | Delete
[1483] Fix | Delete
// Make sure the option doesn't already exist.
[1484] Fix | Delete
// We can check the 'notoptions' cache before we ask for a DB query.
[1485] Fix | Delete
$notoptions = wp_cache_get( $notoptions_key, 'site-options' );
[1486] Fix | Delete
[1487] Fix | Delete
if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
[1488] Fix | Delete
if ( false !== get_network_option( $network_id, $option, false ) ) {
[1489] Fix | Delete
return false;
[1490] Fix | Delete
}
[1491] Fix | Delete
}
[1492] Fix | Delete
[1493] Fix | Delete
$value = sanitize_option( $option, $value );
[1494] Fix | Delete
[1495] Fix | Delete
$serialized_value = maybe_serialize( $value );
[1496] Fix | Delete
$result = $wpdb->insert(
[1497] Fix | Delete
$wpdb->sitemeta,
[1498] Fix | Delete
array(
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function