Edit File by line
/home/barbar84/www/wp-inclu...
File: user.php
* Retrieve user meta field for a user.
[1000] Fix | Delete
*
[1001] Fix | Delete
* @since 3.0.0
[1002] Fix | Delete
*
[1003] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/get_user_meta/
[1004] Fix | Delete
*
[1005] Fix | Delete
* @param int $user_id User ID.
[1006] Fix | Delete
* @param string $key Optional. The meta key to retrieve. By default,
[1007] Fix | Delete
* returns data for all keys.
[1008] Fix | Delete
* @param bool $single Optional. Whether to return a single value.
[1009] Fix | Delete
* This parameter has no effect if $key is not specified.
[1010] Fix | Delete
* Default false.
[1011] Fix | Delete
* @return mixed An array if $single is false. The value of meta data field
[1012] Fix | Delete
* if $single is true. False for an invalid $user_id.
[1013] Fix | Delete
*/
[1014] Fix | Delete
function get_user_meta( $user_id, $key = '', $single = false ) {
[1015] Fix | Delete
return get_metadata( 'user', $user_id, $key, $single );
[1016] Fix | Delete
}
[1017] Fix | Delete
[1018] Fix | Delete
/**
[1019] Fix | Delete
* Update user meta field based on user ID.
[1020] Fix | Delete
*
[1021] Fix | Delete
* Use the $prev_value parameter to differentiate between meta fields with the
[1022] Fix | Delete
* same key and user ID.
[1023] Fix | Delete
*
[1024] Fix | Delete
* If the meta field for the user does not exist, it will be added.
[1025] Fix | Delete
*
[1026] Fix | Delete
* @since 3.0.0
[1027] Fix | Delete
*
[1028] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/update_user_meta/
[1029] Fix | Delete
*
[1030] Fix | Delete
* @param int $user_id User ID.
[1031] Fix | Delete
* @param string $meta_key Metadata key.
[1032] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[1033] Fix | Delete
* @param mixed $prev_value Optional. Previous value to check before updating.
[1034] Fix | Delete
* If specified, only update existing metadata entries with
[1035] Fix | Delete
* this value. Otherwise, update all entries. Default empty.
[1036] Fix | Delete
* @return int|bool Meta ID if the key didn't exist, true on successful update,
[1037] Fix | Delete
* false on failure or if the value passed to the function
[1038] Fix | Delete
* is the same as the one that is already in the database.
[1039] Fix | Delete
*/
[1040] Fix | Delete
function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
[1041] Fix | Delete
return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value );
[1042] Fix | Delete
}
[1043] Fix | Delete
[1044] Fix | Delete
/**
[1045] Fix | Delete
* Count number of users who have each of the user roles.
[1046] Fix | Delete
*
[1047] Fix | Delete
* Assumes there are neither duplicated nor orphaned capabilities meta_values.
[1048] Fix | Delete
* Assumes role names are unique phrases. Same assumption made by WP_User_Query::prepare_query()
[1049] Fix | Delete
* Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users.
[1050] Fix | Delete
* Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see WP Bug #12257.
[1051] Fix | Delete
*
[1052] Fix | Delete
* @since 3.0.0
[1053] Fix | Delete
* @since 4.4.0 The number of users with no role is now included in the `none` element.
[1054] Fix | Delete
* @since 4.9.0 The `$site_id` parameter was added to support multisite.
[1055] Fix | Delete
*
[1056] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1057] Fix | Delete
*
[1058] Fix | Delete
* @param string $strategy Optional. The computational strategy to use when counting the users.
[1059] Fix | Delete
* Accepts either 'time' or 'memory'. Default 'time'.
[1060] Fix | Delete
* @param int|null $site_id Optional. The site ID to count users for. Defaults to the current site.
[1061] Fix | Delete
* @return array {
[1062] Fix | Delete
* User counts.
[1063] Fix | Delete
*
[1064] Fix | Delete
* @type int $total_users Total number of users on the site.
[1065] Fix | Delete
* @type int[] $avail_roles Array of user counts keyed by user role.
[1066] Fix | Delete
* }
[1067] Fix | Delete
*/
[1068] Fix | Delete
function count_users( $strategy = 'time', $site_id = null ) {
[1069] Fix | Delete
global $wpdb;
[1070] Fix | Delete
[1071] Fix | Delete
// Initialize.
[1072] Fix | Delete
if ( ! $site_id ) {
[1073] Fix | Delete
$site_id = get_current_blog_id();
[1074] Fix | Delete
}
[1075] Fix | Delete
[1076] Fix | Delete
/**
[1077] Fix | Delete
* Filters the user count before queries are run.
[1078] Fix | Delete
*
[1079] Fix | Delete
* Return a non-null value to cause count_users() to return early.
[1080] Fix | Delete
*
[1081] Fix | Delete
* @since 5.1.0
[1082] Fix | Delete
*
[1083] Fix | Delete
* @param null|string $result The value to return instead. Default null to continue with the query.
[1084] Fix | Delete
* @param string $strategy Optional. The computational strategy to use when counting the users.
[1085] Fix | Delete
* Accepts either 'time' or 'memory'. Default 'time'.
[1086] Fix | Delete
* @param int|null $site_id Optional. The site ID to count users for. Defaults to the current site.
[1087] Fix | Delete
*/
[1088] Fix | Delete
$pre = apply_filters( 'pre_count_users', null, $strategy, $site_id );
[1089] Fix | Delete
[1090] Fix | Delete
if ( null !== $pre ) {
[1091] Fix | Delete
return $pre;
[1092] Fix | Delete
}
[1093] Fix | Delete
[1094] Fix | Delete
$blog_prefix = $wpdb->get_blog_prefix( $site_id );
[1095] Fix | Delete
$result = array();
[1096] Fix | Delete
[1097] Fix | Delete
if ( 'time' === $strategy ) {
[1098] Fix | Delete
if ( is_multisite() && get_current_blog_id() != $site_id ) {
[1099] Fix | Delete
switch_to_blog( $site_id );
[1100] Fix | Delete
$avail_roles = wp_roles()->get_names();
[1101] Fix | Delete
restore_current_blog();
[1102] Fix | Delete
} else {
[1103] Fix | Delete
$avail_roles = wp_roles()->get_names();
[1104] Fix | Delete
}
[1105] Fix | Delete
[1106] Fix | Delete
// Build a CPU-intensive query that will return concise information.
[1107] Fix | Delete
$select_count = array();
[1108] Fix | Delete
foreach ( $avail_roles as $this_role => $name ) {
[1109] Fix | Delete
$select_count[] = $wpdb->prepare( 'COUNT(NULLIF(`meta_value` LIKE %s, false))', '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%' );
[1110] Fix | Delete
}
[1111] Fix | Delete
$select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))";
[1112] Fix | Delete
$select_count = implode( ', ', $select_count );
[1113] Fix | Delete
[1114] Fix | Delete
// Add the meta_value index to the selection list, then run the query.
[1115] Fix | Delete
$row = $wpdb->get_row(
[1116] Fix | Delete
"
[1117] Fix | Delete
SELECT {$select_count}, COUNT(*)
[1118] Fix | Delete
FROM {$wpdb->usermeta}
[1119] Fix | Delete
INNER JOIN {$wpdb->users} ON user_id = ID
[1120] Fix | Delete
WHERE meta_key = '{$blog_prefix}capabilities'
[1121] Fix | Delete
",
[1122] Fix | Delete
ARRAY_N
[1123] Fix | Delete
);
[1124] Fix | Delete
[1125] Fix | Delete
// Run the previous loop again to associate results with role names.
[1126] Fix | Delete
$col = 0;
[1127] Fix | Delete
$role_counts = array();
[1128] Fix | Delete
foreach ( $avail_roles as $this_role => $name ) {
[1129] Fix | Delete
$count = (int) $row[ $col++ ];
[1130] Fix | Delete
if ( $count > 0 ) {
[1131] Fix | Delete
$role_counts[ $this_role ] = $count;
[1132] Fix | Delete
}
[1133] Fix | Delete
}
[1134] Fix | Delete
[1135] Fix | Delete
$role_counts['none'] = (int) $row[ $col++ ];
[1136] Fix | Delete
[1137] Fix | Delete
// Get the meta_value index from the end of the result set.
[1138] Fix | Delete
$total_users = (int) $row[ $col ];
[1139] Fix | Delete
[1140] Fix | Delete
$result['total_users'] = $total_users;
[1141] Fix | Delete
$result['avail_roles'] =& $role_counts;
[1142] Fix | Delete
} else {
[1143] Fix | Delete
$avail_roles = array(
[1144] Fix | Delete
'none' => 0,
[1145] Fix | Delete
);
[1146] Fix | Delete
[1147] Fix | Delete
$users_of_blog = $wpdb->get_col(
[1148] Fix | Delete
"
[1149] Fix | Delete
SELECT meta_value
[1150] Fix | Delete
FROM {$wpdb->usermeta}
[1151] Fix | Delete
INNER JOIN {$wpdb->users} ON user_id = ID
[1152] Fix | Delete
WHERE meta_key = '{$blog_prefix}capabilities'
[1153] Fix | Delete
"
[1154] Fix | Delete
);
[1155] Fix | Delete
[1156] Fix | Delete
foreach ( $users_of_blog as $caps_meta ) {
[1157] Fix | Delete
$b_roles = maybe_unserialize( $caps_meta );
[1158] Fix | Delete
if ( ! is_array( $b_roles ) ) {
[1159] Fix | Delete
continue;
[1160] Fix | Delete
}
[1161] Fix | Delete
if ( empty( $b_roles ) ) {
[1162] Fix | Delete
$avail_roles['none']++;
[1163] Fix | Delete
}
[1164] Fix | Delete
foreach ( $b_roles as $b_role => $val ) {
[1165] Fix | Delete
if ( isset( $avail_roles[ $b_role ] ) ) {
[1166] Fix | Delete
$avail_roles[ $b_role ]++;
[1167] Fix | Delete
} else {
[1168] Fix | Delete
$avail_roles[ $b_role ] = 1;
[1169] Fix | Delete
}
[1170] Fix | Delete
}
[1171] Fix | Delete
}
[1172] Fix | Delete
[1173] Fix | Delete
$result['total_users'] = count( $users_of_blog );
[1174] Fix | Delete
$result['avail_roles'] =& $avail_roles;
[1175] Fix | Delete
}
[1176] Fix | Delete
[1177] Fix | Delete
return $result;
[1178] Fix | Delete
}
[1179] Fix | Delete
[1180] Fix | Delete
//
[1181] Fix | Delete
// Private helper functions.
[1182] Fix | Delete
//
[1183] Fix | Delete
[1184] Fix | Delete
/**
[1185] Fix | Delete
* Set up global user vars.
[1186] Fix | Delete
*
[1187] Fix | Delete
* Used by wp_set_current_user() for back compat. Might be deprecated in the future.
[1188] Fix | Delete
*
[1189] Fix | Delete
* @since 2.0.4
[1190] Fix | Delete
*
[1191] Fix | Delete
* @global string $user_login The user username for logging in
[1192] Fix | Delete
* @global WP_User $userdata User data.
[1193] Fix | Delete
* @global int $user_level The level of the user
[1194] Fix | Delete
* @global int $user_ID The ID of the user
[1195] Fix | Delete
* @global string $user_email The email address of the user
[1196] Fix | Delete
* @global string $user_url The url in the user's profile
[1197] Fix | Delete
* @global string $user_identity The display name of the user
[1198] Fix | Delete
*
[1199] Fix | Delete
* @param int $for_user_id Optional. User ID to set up global data. Default 0.
[1200] Fix | Delete
*/
[1201] Fix | Delete
function setup_userdata( $for_user_id = 0 ) {
[1202] Fix | Delete
global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity;
[1203] Fix | Delete
[1204] Fix | Delete
if ( ! $for_user_id ) {
[1205] Fix | Delete
$for_user_id = get_current_user_id();
[1206] Fix | Delete
}
[1207] Fix | Delete
$user = get_userdata( $for_user_id );
[1208] Fix | Delete
[1209] Fix | Delete
if ( ! $user ) {
[1210] Fix | Delete
$user_ID = 0;
[1211] Fix | Delete
$user_level = 0;
[1212] Fix | Delete
$userdata = null;
[1213] Fix | Delete
$user_login = '';
[1214] Fix | Delete
$user_email = '';
[1215] Fix | Delete
$user_url = '';
[1216] Fix | Delete
$user_identity = '';
[1217] Fix | Delete
return;
[1218] Fix | Delete
}
[1219] Fix | Delete
[1220] Fix | Delete
$user_ID = (int) $user->ID;
[1221] Fix | Delete
$user_level = (int) $user->user_level;
[1222] Fix | Delete
$userdata = $user;
[1223] Fix | Delete
$user_login = $user->user_login;
[1224] Fix | Delete
$user_email = $user->user_email;
[1225] Fix | Delete
$user_url = $user->user_url;
[1226] Fix | Delete
$user_identity = $user->display_name;
[1227] Fix | Delete
}
[1228] Fix | Delete
[1229] Fix | Delete
/**
[1230] Fix | Delete
* Create dropdown HTML content of users.
[1231] Fix | Delete
*
[1232] Fix | Delete
* The content can either be displayed, which it is by default or retrieved by
[1233] Fix | Delete
* setting the 'echo' argument. The 'include' and 'exclude' arguments do not
[1234] Fix | Delete
* need to be used; all users will be displayed in that case. Only one can be
[1235] Fix | Delete
* used, either 'include' or 'exclude', but not both.
[1236] Fix | Delete
*
[1237] Fix | Delete
* The available arguments are as follows:
[1238] Fix | Delete
*
[1239] Fix | Delete
* @since 2.3.0
[1240] Fix | Delete
* @since 4.5.0 Added the 'display_name_with_login' value for 'show'.
[1241] Fix | Delete
* @since 4.7.0 Added the `$role`, `$role__in`, and `$role__not_in` parameters.
[1242] Fix | Delete
*
[1243] Fix | Delete
* @param array|string $args {
[1244] Fix | Delete
* Optional. Array or string of arguments to generate a drop-down of users.
[1245] Fix | Delete
* See WP_User_Query::prepare_query() for additional available arguments.
[1246] Fix | Delete
*
[1247] Fix | Delete
* @type string $show_option_all Text to show as the drop-down default (all).
[1248] Fix | Delete
* Default empty.
[1249] Fix | Delete
* @type string $show_option_none Text to show as the drop-down default when no
[1250] Fix | Delete
* users were found. Default empty.
[1251] Fix | Delete
* @type int|string $option_none_value Value to use for $show_option_non when no users
[1252] Fix | Delete
* were found. Default -1.
[1253] Fix | Delete
* @type string $hide_if_only_one_author Whether to skip generating the drop-down
[1254] Fix | Delete
* if only one user was found. Default empty.
[1255] Fix | Delete
* @type string $orderby Field to order found users by. Accepts user fields.
[1256] Fix | Delete
* Default 'display_name'.
[1257] Fix | Delete
* @type string $order Whether to order users in ascending or descending
[1258] Fix | Delete
* order. Accepts 'ASC' (ascending) or 'DESC' (descending).
[1259] Fix | Delete
* Default 'ASC'.
[1260] Fix | Delete
* @type int[]|string $include Array or comma-separated list of user IDs to include.
[1261] Fix | Delete
* Default empty.
[1262] Fix | Delete
* @type int[]|string $exclude Array or comma-separated list of user IDs to exclude.
[1263] Fix | Delete
* Default empty.
[1264] Fix | Delete
* @type bool|int $multi Whether to skip the ID attribute on the 'select' element.
[1265] Fix | Delete
* Accepts 1|true or 0|false. Default 0|false.
[1266] Fix | Delete
* @type string $show User data to display. If the selected item is empty
[1267] Fix | Delete
* then the 'user_login' will be displayed in parentheses.
[1268] Fix | Delete
* Accepts any user field, or 'display_name_with_login' to show
[1269] Fix | Delete
* the display name with user_login in parentheses.
[1270] Fix | Delete
* Default 'display_name'.
[1271] Fix | Delete
* @type int|bool $echo Whether to echo or return the drop-down. Accepts 1|true (echo)
[1272] Fix | Delete
* or 0|false (return). Default 1|true.
[1273] Fix | Delete
* @type int $selected Which user ID should be selected. Default 0.
[1274] Fix | Delete
* @type bool $include_selected Whether to always include the selected user ID in the drop-
[1275] Fix | Delete
* down. Default false.
[1276] Fix | Delete
* @type string $name Name attribute of select element. Default 'user'.
[1277] Fix | Delete
* @type string $id ID attribute of the select element. Default is the value of $name.
[1278] Fix | Delete
* @type string $class Class attribute of the select element. Default empty.
[1279] Fix | Delete
* @type int $blog_id ID of blog (Multisite only). Default is ID of the current blog.
[1280] Fix | Delete
* @type string $who Which type of users to query. Accepts only an empty string or
[1281] Fix | Delete
* 'authors'. Default empty.
[1282] Fix | Delete
* @type string|array $role An array or a comma-separated list of role names that users must
[1283] Fix | Delete
* match to be included in results. Note that this is an inclusive
[1284] Fix | Delete
* list: users must match *each* role. Default empty.
[1285] Fix | Delete
* @type string[] $role__in An array of role names. Matched users must have at least one of
[1286] Fix | Delete
* these roles. Default empty array.
[1287] Fix | Delete
* @type string[] $role__not_in An array of role names to exclude. Users matching one or more of
[1288] Fix | Delete
* these roles will not be included in results. Default empty array.
[1289] Fix | Delete
* }
[1290] Fix | Delete
* @return string HTML dropdown list of users.
[1291] Fix | Delete
*/
[1292] Fix | Delete
function wp_dropdown_users( $args = '' ) {
[1293] Fix | Delete
$defaults = array(
[1294] Fix | Delete
'show_option_all' => '',
[1295] Fix | Delete
'show_option_none' => '',
[1296] Fix | Delete
'hide_if_only_one_author' => '',
[1297] Fix | Delete
'orderby' => 'display_name',
[1298] Fix | Delete
'order' => 'ASC',
[1299] Fix | Delete
'include' => '',
[1300] Fix | Delete
'exclude' => '',
[1301] Fix | Delete
'multi' => 0,
[1302] Fix | Delete
'show' => 'display_name',
[1303] Fix | Delete
'echo' => 1,
[1304] Fix | Delete
'selected' => 0,
[1305] Fix | Delete
'name' => 'user',
[1306] Fix | Delete
'class' => '',
[1307] Fix | Delete
'id' => '',
[1308] Fix | Delete
'blog_id' => get_current_blog_id(),
[1309] Fix | Delete
'who' => '',
[1310] Fix | Delete
'include_selected' => false,
[1311] Fix | Delete
'option_none_value' => -1,
[1312] Fix | Delete
'role' => '',
[1313] Fix | Delete
'role__in' => array(),
[1314] Fix | Delete
'role__not_in' => array(),
[1315] Fix | Delete
);
[1316] Fix | Delete
[1317] Fix | Delete
$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
[1318] Fix | Delete
[1319] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[1320] Fix | Delete
[1321] Fix | Delete
$query_args = wp_array_slice_assoc( $parsed_args, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who', 'role', 'role__in', 'role__not_in' ) );
[1322] Fix | Delete
[1323] Fix | Delete
$fields = array( 'ID', 'user_login' );
[1324] Fix | Delete
[1325] Fix | Delete
$show = ! empty( $parsed_args['show'] ) ? $parsed_args['show'] : 'display_name';
[1326] Fix | Delete
if ( 'display_name_with_login' === $show ) {
[1327] Fix | Delete
$fields[] = 'display_name';
[1328] Fix | Delete
} else {
[1329] Fix | Delete
$fields[] = $show;
[1330] Fix | Delete
}
[1331] Fix | Delete
[1332] Fix | Delete
$query_args['fields'] = $fields;
[1333] Fix | Delete
[1334] Fix | Delete
$show_option_all = $parsed_args['show_option_all'];
[1335] Fix | Delete
$show_option_none = $parsed_args['show_option_none'];
[1336] Fix | Delete
$option_none_value = $parsed_args['option_none_value'];
[1337] Fix | Delete
[1338] Fix | Delete
/**
[1339] Fix | Delete
* Filters the query arguments for the list of users in the dropdown.
[1340] Fix | Delete
*
[1341] Fix | Delete
* @since 4.4.0
[1342] Fix | Delete
*
[1343] Fix | Delete
* @param array $query_args The query arguments for get_users().
[1344] Fix | Delete
* @param array $parsed_args The arguments passed to wp_dropdown_users() combined with the defaults.
[1345] Fix | Delete
*/
[1346] Fix | Delete
$query_args = apply_filters( 'wp_dropdown_users_args', $query_args, $parsed_args );
[1347] Fix | Delete
[1348] Fix | Delete
$users = get_users( $query_args );
[1349] Fix | Delete
[1350] Fix | Delete
$output = '';
[1351] Fix | Delete
if ( ! empty( $users ) && ( empty( $parsed_args['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
[1352] Fix | Delete
$name = esc_attr( $parsed_args['name'] );
[1353] Fix | Delete
if ( $parsed_args['multi'] && ! $parsed_args['id'] ) {
[1354] Fix | Delete
$id = '';
[1355] Fix | Delete
} else {
[1356] Fix | Delete
$id = $parsed_args['id'] ? " id='" . esc_attr( $parsed_args['id'] ) . "'" : " id='$name'";
[1357] Fix | Delete
}
[1358] Fix | Delete
$output = "<select name='{$name}'{$id} class='" . $parsed_args['class'] . "'>\n";
[1359] Fix | Delete
[1360] Fix | Delete
if ( $show_option_all ) {
[1361] Fix | Delete
$output .= "\t<option value='0'>$show_option_all</option>\n";
[1362] Fix | Delete
}
[1363] Fix | Delete
[1364] Fix | Delete
if ( $show_option_none ) {
[1365] Fix | Delete
$_selected = selected( $option_none_value, $parsed_args['selected'], false );
[1366] Fix | Delete
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
[1367] Fix | Delete
}
[1368] Fix | Delete
[1369] Fix | Delete
if ( $parsed_args['include_selected'] && ( $parsed_args['selected'] > 0 ) ) {
[1370] Fix | Delete
$found_selected = false;
[1371] Fix | Delete
$parsed_args['selected'] = (int) $parsed_args['selected'];
[1372] Fix | Delete
[1373] Fix | Delete
foreach ( (array) $users as $user ) {
[1374] Fix | Delete
$user->ID = (int) $user->ID;
[1375] Fix | Delete
if ( $user->ID === $parsed_args['selected'] ) {
[1376] Fix | Delete
$found_selected = true;
[1377] Fix | Delete
}
[1378] Fix | Delete
}
[1379] Fix | Delete
[1380] Fix | Delete
if ( ! $found_selected ) {
[1381] Fix | Delete
$selected_user = get_userdata( $parsed_args['selected'] );
[1382] Fix | Delete
if ( $selected_user ) {
[1383] Fix | Delete
$users[] = $selected_user;
[1384] Fix | Delete
}
[1385] Fix | Delete
}
[1386] Fix | Delete
}
[1387] Fix | Delete
[1388] Fix | Delete
foreach ( (array) $users as $user ) {
[1389] Fix | Delete
if ( 'display_name_with_login' === $show ) {
[1390] Fix | Delete
/* translators: 1: User's display name, 2: User login. */
[1391] Fix | Delete
$display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
[1392] Fix | Delete
} elseif ( ! empty( $user->$show ) ) {
[1393] Fix | Delete
$display = $user->$show;
[1394] Fix | Delete
} else {
[1395] Fix | Delete
$display = '(' . $user->user_login . ')';
[1396] Fix | Delete
}
[1397] Fix | Delete
[1398] Fix | Delete
$_selected = selected( $user->ID, $parsed_args['selected'], false );
[1399] Fix | Delete
$output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
[1400] Fix | Delete
}
[1401] Fix | Delete
[1402] Fix | Delete
$output .= '</select>';
[1403] Fix | Delete
}
[1404] Fix | Delete
[1405] Fix | Delete
/**
[1406] Fix | Delete
* Filters the wp_dropdown_users() HTML output.
[1407] Fix | Delete
*
[1408] Fix | Delete
* @since 2.3.0
[1409] Fix | Delete
*
[1410] Fix | Delete
* @param string $output HTML output generated by wp_dropdown_users().
[1411] Fix | Delete
*/
[1412] Fix | Delete
$html = apply_filters( 'wp_dropdown_users', $output );
[1413] Fix | Delete
[1414] Fix | Delete
if ( $parsed_args['echo'] ) {
[1415] Fix | Delete
echo $html;
[1416] Fix | Delete
}
[1417] Fix | Delete
return $html;
[1418] Fix | Delete
}
[1419] Fix | Delete
[1420] Fix | Delete
/**
[1421] Fix | Delete
* Sanitize user field based on context.
[1422] Fix | Delete
*
[1423] Fix | Delete
* Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The
[1424] Fix | Delete
* 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display'
[1425] Fix | Delete
* when calling filters.
[1426] Fix | Delete
*
[1427] Fix | Delete
* @since 2.3.0
[1428] Fix | Delete
*
[1429] Fix | Delete
* @param string $field The user Object field name.
[1430] Fix | Delete
* @param mixed $value The user Object value.
[1431] Fix | Delete
* @param int $user_id User ID.
[1432] Fix | Delete
* @param string $context How to sanitize user fields. Looks for 'raw', 'edit', 'db', 'display',
[1433] Fix | Delete
* 'attribute' and 'js'.
[1434] Fix | Delete
* @return mixed Sanitized value.
[1435] Fix | Delete
*/
[1436] Fix | Delete
function sanitize_user_field( $field, $value, $user_id, $context ) {
[1437] Fix | Delete
$int_fields = array( 'ID' );
[1438] Fix | Delete
if ( in_array( $field, $int_fields, true ) ) {
[1439] Fix | Delete
$value = (int) $value;
[1440] Fix | Delete
}
[1441] Fix | Delete
[1442] Fix | Delete
if ( 'raw' === $context ) {
[1443] Fix | Delete
return $value;
[1444] Fix | Delete
}
[1445] Fix | Delete
[1446] Fix | Delete
if ( ! is_string( $value ) && ! is_numeric( $value ) ) {
[1447] Fix | Delete
return $value;
[1448] Fix | Delete
}
[1449] Fix | Delete
[1450] Fix | Delete
$prefixed = false !== strpos( $field, 'user_' );
[1451] Fix | Delete
[1452] Fix | Delete
if ( 'edit' === $context ) {
[1453] Fix | Delete
if ( $prefixed ) {
[1454] Fix | Delete
[1455] Fix | Delete
/** This filter is documented in wp-includes/post.php */
[1456] Fix | Delete
$value = apply_filters( "edit_{$field}", $value, $user_id );
[1457] Fix | Delete
} else {
[1458] Fix | Delete
[1459] Fix | Delete
/**
[1460] Fix | Delete
* Filters a user field value in the 'edit' context.
[1461] Fix | Delete
*
[1462] Fix | Delete
* The dynamic portion of the hook name, `$field`, refers to the prefixed user
[1463] Fix | Delete
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
[1464] Fix | Delete
*
[1465] Fix | Delete
* @since 2.9.0
[1466] Fix | Delete
*
[1467] Fix | Delete
* @param mixed $value Value of the prefixed user field.
[1468] Fix | Delete
* @param int $user_id User ID.
[1469] Fix | Delete
*/
[1470] Fix | Delete
$value = apply_filters( "edit_user_{$field}", $value, $user_id );
[1471] Fix | Delete
}
[1472] Fix | Delete
[1473] Fix | Delete
if ( 'description' === $field ) {
[1474] Fix | Delete
$value = esc_html( $value ); // textarea_escaped?
[1475] Fix | Delete
} else {
[1476] Fix | Delete
$value = esc_attr( $value );
[1477] Fix | Delete
}
[1478] Fix | Delete
} elseif ( 'db' === $context ) {
[1479] Fix | Delete
if ( $prefixed ) {
[1480] Fix | Delete
/** This filter is documented in wp-includes/post.php */
[1481] Fix | Delete
$value = apply_filters( "pre_{$field}", $value );
[1482] Fix | Delete
} else {
[1483] Fix | Delete
[1484] Fix | Delete
/**
[1485] Fix | Delete
* Filters the value of a user field in the 'db' context.
[1486] Fix | Delete
*
[1487] Fix | Delete
* The dynamic portion of the hook name, `$field`, refers to the prefixed user
[1488] Fix | Delete
* field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
[1489] Fix | Delete
*
[1490] Fix | Delete
* @since 2.9.0
[1491] Fix | Delete
*
[1492] Fix | Delete
* @param mixed $value Value of the prefixed user field.
[1493] Fix | Delete
*/
[1494] Fix | Delete
$value = apply_filters( "pre_user_{$field}", $value );
[1495] Fix | Delete
}
[1496] Fix | Delete
} else {
[1497] Fix | Delete
// Use display filters by default.
[1498] Fix | Delete
if ( $prefixed ) {
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function