diff --git wp-includes/user.php wp-includes/user.php
index 9a60cd2..1bab48f 100644
|
|
|
function wp_signon( $credentials = '', $secure_cookie = '' ) {
|
| 38 | 38 | $credentials['remember'] = false; |
| 39 | 39 | |
| 40 | 40 | // TODO do we deprecate the wp_authentication action? |
| | 41 | /** |
| | 42 | * Triggered before the user is logged in. |
| | 43 | * |
| | 44 | * The variables passed to the callbacks are passed by reference and can be modified by callback functions. |
| | 45 | * @since 1.5.2 |
| | 46 | * |
| | 47 | * @param string $user_login |
| | 48 | * @param string $user_password |
| | 49 | */ |
| 41 | 50 | do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password'])); |
| 42 | 51 | |
| 43 | 52 | if ( '' === $secure_cookie ) |
| 44 | 53 | $secure_cookie = is_ssl(); |
| 45 | 54 | |
| | 55 | /** |
| | 56 | * Filters whether the sign-on cookie should only be transmitted over a secure HTTPS |
| | 57 | * connection from the client. |
| | 58 | * |
| | 59 | * @since 3.1.0 |
| | 60 | * |
| | 61 | * @param bool $secure_cookie When set to true, the cookie will only be set if a secure connection exists. |
| | 62 | * @param array $args { |
| | 63 | * User credentials, |
| | 64 | * |
| | 65 | * @type string $user_login Username. |
| | 66 | * @type string $user_password Password entered. |
| | 67 | * @type bool $remember Whether to 'remember' the user. Increases the time that the cookie will be kept. |
| | 68 | * } |
| | 69 | */ |
| 46 | 70 | $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials); |
| 47 | 71 | |
| 48 | 72 | global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie |
| … |
… |
function wp_signon( $credentials = '', $secure_cookie = '' ) {
|
| 61 | 85 | } |
| 62 | 86 | |
| 63 | 87 | wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie); |
| | 88 | |
| | 89 | /** |
| | 90 | * Triggered after the user has successfully logged in. |
| | 91 | * |
| | 92 | * @since 1.5.2 |
| | 93 | * |
| | 94 | * @param string $user_login The user's usersname |
| | 95 | * @param WP_User $user The logged-in user |
| | 96 | */ |
| 64 | 97 | do_action('wp_login', $user->user_login, $user); |
| 65 | 98 | return $user; |
| 66 | 99 | } |
| … |
… |
function wp_authenticate_username_password($user, $username, $password) {
|
| 92 | 125 | if ( !$user ) |
| 93 | 126 | return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() ) ); |
| 94 | 127 | |
| | 128 | /** |
| | 129 | * Returns either a WP_User or WP_Error object depending on whether the given user can be authenticated with the provided $password. |
| | 130 | * |
| | 131 | * This allows plug-ins to add additional authentication conditions. Please note that the filtered value is originally a WP_User, |
| | 132 | * but hooked callbacks may recieve a WP_Error if authentication has failed in an earlier callback. |
| | 133 | * |
| | 134 | * @since 2.5.0 |
| | 135 | * |
| | 136 | * @param WP_User|WP_Error The user to authenticate as a WP_User object or a WP_Error object if a previous callback as 'failed' the authentication. |
| | 137 | * @param string $password The password to check against the user. |
| | 138 | */ |
| 95 | 139 | $user = apply_filters('wp_authenticate_user', $user, $password); |
| 96 | 140 | if ( is_wp_error($user) ) |
| 97 | 141 | return $user; |
| … |
… |
function wp_authenticate_cookie($user, $username, $password) {
|
| 138 | 182 | */ |
| 139 | 183 | function wp_authenticate_spam_check( $user ) { |
| 140 | 184 | if ( $user && is_a( $user, 'WP_User' ) && is_multisite() ) { |
| | 185 | /** |
| | 186 | * Filters whether the user has been marked as a spammer. |
| | 187 | * |
| | 188 | * @since 3.7.0 |
| | 189 | * |
| | 190 | * @param bool $spammed True if the user is considered a spammer. |
| | 191 | * @param WP_User $user The user to check against. |
| | 192 | */ |
| 141 | 193 | $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user ); |
| 142 | 194 | |
| 143 | 195 | if ( $spammed ) |
| … |
… |
function count_user_posts($userid) {
|
| 162 | 214 | |
| 163 | 215 | $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); |
| 164 | 216 | |
| | 217 | /** |
| | 218 | * Filters the number of posts a user has written. |
| | 219 | * |
| | 220 | * @since 2.7.0 |
| | 221 | * |
| | 222 | * @param int $count The number of posts the user has posted. |
| | 223 | * @param int $userid The ID of the user. |
| | 224 | */ |
| 165 | 225 | return apply_filters('get_usernumposts', $count, $userid); |
| 166 | 226 | } |
| 167 | 227 | |
| … |
… |
function get_user_option( $option, $user = 0, $deprecated = '' ) {
|
| 256 | 316 | else |
| 257 | 317 | $result = false; |
| 258 | 318 | |
| | 319 | /** |
| | 320 | * Filter a specific option value for a user. |
| | 321 | * |
| | 322 | * @since 2.5.0 |
| | 323 | * |
| | 324 | * @param mixed The value for the user's option. |
| | 325 | * @param string $option The name of the option being retrieved. |
| | 326 | * @param WP_User $user User object of the user whose option is being retrieved. |
| | 327 | */ |
| 259 | 328 | return apply_filters("get_user_option_{$option}", $result, $option, $user); |
| 260 | 329 | } |
| 261 | 330 | |
| … |
… |
class WP_User_Query {
|
| 494 | 563 | $search_columns = array('user_login', 'user_nicename'); |
| 495 | 564 | } |
| 496 | 565 | |
| | 566 | /** |
| | 567 | * Filters the columns which are searched in a WP_User_Query search. |
| | 568 | * |
| | 569 | * @since 3.6.0 |
| | 570 | * |
| | 571 | * @param array $search_columns Array of column names to be searched. |
| | 572 | * @param string $search The term being searched. |
| | 573 | * @param WP_User_Query $this The user query. |
| | 574 | */ |
| 497 | 575 | $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this ); |
| 498 | 576 | |
| 499 | 577 | $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); |
| … |
… |
class WP_User_Query {
|
| 546 | 624 | $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)"; |
| 547 | 625 | } |
| 548 | 626 | |
| | 627 | /** |
| | 628 | * Triggered after the WP_User_Query has been parsed and before the query is executed. |
| | 629 | * |
| | 630 | * The WP_User_Query is passed by reference and can be modified. It contains SQL |
| | 631 | * parts formed from parsing WP_User_Query. |
| | 632 | * |
| | 633 | * @since 1.5.2 |
| | 634 | * |
| | 635 | * @param WP_User_Query $this The user query. |
| | 636 | */ |
| 549 | 637 | do_action_ref_array( 'pre_user_query', array( &$this ) ); |
| 550 | 638 | } |
| 551 | 639 | |
| … |
… |
class WP_User_Query {
|
| 566 | 654 | $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); |
| 567 | 655 | } |
| 568 | 656 | |
| | 657 | /** |
| | 658 | * Filters the SQL command for number of users matching the WP_User_Query |
| | 659 | * |
| | 660 | * @since 3.2.0 |
| | 661 | * |
| | 662 | * @param string $sql |
| | 663 | */ |
| 569 | 664 | if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
| 570 | 665 | $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); |
| 571 | 666 | |
| … |
… |
function get_blogs_of_user( $user_id, $all = false ) {
|
| 774 | 869 | } |
| 775 | 870 | } |
| 776 | 871 | |
| | 872 | /** |
| | 873 | * Filters the blogs belonging to the specified user. |
| | 874 | * |
| | 875 | * @since 3.1.0 |
| | 876 | * |
| | 877 | * @param array An array of blog objects belonging to the user. |
| | 878 | * @param int $user_id The ID of the user. |
| | 879 | * @param bool $all True if $blogs should conain all blogs, false if it should only contain blogs that are not marked as deleted, archived, or spam. |
| | 880 | */ |
| 777 | 881 | return apply_filters( 'get_blogs_of_user', $blogs, $user_id, $all ); |
| 778 | 882 | } |
| 779 | 883 | |
| … |
… |
function wp_dropdown_users( $args = '' ) {
|
| 1092 | 1196 | |
| 1093 | 1197 | $output .= "</select>"; |
| 1094 | 1198 | } |
| 1095 | | |
| | 1199 | |
| | 1200 | /** |
| | 1201 | * Filters the HTML of a dropdown of users. |
| | 1202 | * |
| | 1203 | * @since 2.3.0 |
| | 1204 | * |
| | 1205 | * @param string HTML generated by `wp_dropdown_users()`. |
| | 1206 | */ |
| 1096 | 1207 | $output = apply_filters('wp_dropdown_users', $output); |
| 1097 | 1208 | |
| 1098 | 1209 | if ( $echo ) |
| … |
… |
function sanitize_user_field($field, $value, $user_id, $context) {
|
| 1138 | 1249 | |
| 1139 | 1250 | if ( 'edit' == $context ) { |
| 1140 | 1251 | if ( $prefixed ) { |
| | 1252 | /** |
| | 1253 | * Filter and sanitize the value of the prefixed field (for editing). |
| | 1254 | * |
| | 1255 | * @since 2.3.0 |
| | 1256 | * |
| | 1257 | * @param mixed $value The user object value to sanitize. |
| | 1258 | * @param int $user_id The user ID. |
| | 1259 | */ |
| 1141 | 1260 | $value = apply_filters("edit_{$field}", $value, $user_id); |
| 1142 | 1261 | } else { |
| | 1262 | /** |
| | 1263 | * Non prefixed version... |
| | 1264 | * @since 2.9.0 |
| | 1265 | * @see edit_user_{$field} filter above |
| | 1266 | */ |
| 1143 | 1267 | $value = apply_filters("edit_user_{$field}", $value, $user_id); |
| 1144 | 1268 | } |
| 1145 | 1269 | |
| … |
… |
function sanitize_user_field($field, $value, $user_id, $context) {
|
| 1149 | 1273 | $value = esc_attr($value); |
| 1150 | 1274 | } else if ( 'db' == $context ) { |
| 1151 | 1275 | if ( $prefixed ) { |
| | 1276 | /** |
| | 1277 | * Filter and sanitize the value of the prefixed field (for database use). |
| | 1278 | * |
| | 1279 | * @since 2.3.0 |
| | 1280 | * |
| | 1281 | * @param mixed $value The user object value to sanitize. |
| | 1282 | */ |
| 1152 | 1283 | $value = apply_filters("pre_{$field}", $value); |
| 1153 | 1284 | } else { |
| | 1285 | /** |
| | 1286 | * Non prefixed version... |
| | 1287 | * @see pre_user_{$field} filter above |
| | 1288 | * @since 2.9.0 |
| | 1289 | */ |
| 1154 | 1290 | $value = apply_filters("pre_user_{$field}", $value); |
| 1155 | 1291 | } |
| 1156 | 1292 | } else { |
| 1157 | 1293 | // Use display filters by default. |
| 1158 | | if ( $prefixed ) |
| | 1294 | if ( $prefixed ){ |
| | 1295 | /** |
| | 1296 | * Filter and sanitize the value of the prefixed field (for other contexts). |
| | 1297 | * |
| | 1298 | * @since 2.3.0 |
| | 1299 | * |
| | 1300 | * @param mixed $value The user object value to sanitize. |
| | 1301 | * @param int $user_id The User ID. |
| | 1302 | * @param string $context The context to filter for. |
| | 1303 | */ |
| 1159 | 1304 | $value = apply_filters($field, $value, $user_id, $context); |
| 1160 | | else |
| | 1305 | }else{ |
| | 1306 | /** |
| | 1307 | * Non prefixed version... |
| | 1308 | * @see user_{$field} filter above |
| | 1309 | * @since 2.9.0 |
| | 1310 | */ |
| 1161 | 1311 | $value = apply_filters("user_{$field}", $value, $user_id, $context); |
| | 1312 | } |
| 1162 | 1313 | } |
| 1163 | 1314 | |
| 1164 | 1315 | if ( 'user_url' == $field ) |
| … |
… |
function email_exists( $email ) {
|
| 1250 | 1401 | function validate_username( $username ) { |
| 1251 | 1402 | $sanitized = sanitize_user( $username, true ); |
| 1252 | 1403 | $valid = ( $sanitized == $username ); |
| | 1404 | /** |
| | 1405 | * Filters whether the provided username is valid or not. |
| | 1406 | * |
| | 1407 | * @since 2.0.11 |
| | 1408 | * |
| | 1409 | * @param bool Whether username given is valid. |
| | 1410 | * @param string The username to check. |
| | 1411 | */ |
| 1253 | 1412 | return apply_filters( 'validate_username', $valid, $username ); |
| 1254 | 1413 | } |
| 1255 | 1414 | |
| … |
… |
function wp_insert_user( $userdata ) {
|
| 1321 | 1480 | } |
| 1322 | 1481 | |
| 1323 | 1482 | $user_login = sanitize_user($user_login, true); |
| | 1483 | /** |
| | 1484 | * Filters the username after it has been sanitized, but before the user is created or updated. |
| | 1485 | * |
| | 1486 | * This hook is called before the user is created or updated. |
| | 1487 | * |
| | 1488 | * @since 2.0.11 |
| | 1489 | * |
| | 1490 | * @param string $user_login The username after it has been sanitized. |
| | 1491 | */ |
| 1324 | 1492 | $user_login = apply_filters('pre_user_login', $user_login); |
| 1325 | 1493 | |
| 1326 | 1494 | //Remove any non-printable chars from the login string to see if we have ended up with an empty username |
| … |
… |
function wp_insert_user( $userdata ) {
|
| 1334 | 1502 | |
| 1335 | 1503 | if ( empty($user_nicename) ) |
| 1336 | 1504 | $user_nicename = sanitize_title( $user_login ); |
| | 1505 | |
| | 1506 | /** |
| | 1507 | * Filters the user's nicename before the user is created or updated. |
| | 1508 | * |
| | 1509 | * This hook is called before the user is created or updated. |
| | 1510 | * |
| | 1511 | * @since 2.0.11 |
| | 1512 | * |
| | 1513 | * @param string $user_nicename |
| | 1514 | */ |
| 1337 | 1515 | $user_nicename = apply_filters('pre_user_nicename', $user_nicename); |
| 1338 | 1516 | |
| 1339 | 1517 | if ( empty($user_url) ) |
| 1340 | 1518 | $user_url = ''; |
| | 1519 | |
| | 1520 | /** |
| | 1521 | * Filters the user's url before the user is created or updated. |
| | 1522 | * |
| | 1523 | * @since 2.0.11 |
| | 1524 | * |
| | 1525 | * @param string $user_url |
| | 1526 | */ |
| 1341 | 1527 | $user_url = apply_filters('pre_user_url', $user_url); |
| 1342 | 1528 | |
| 1343 | 1529 | if ( empty($user_email) ) |
| 1344 | 1530 | $user_email = ''; |
| | 1531 | |
| | 1532 | /** |
| | 1533 | * Filters the user's email before the user is created or updated. |
| | 1534 | * |
| | 1535 | * @since 2.0.11 |
| | 1536 | * |
| | 1537 | * @param string $user_email |
| | 1538 | */ |
| 1345 | 1539 | $user_email = apply_filters('pre_user_email', $user_email); |
| 1346 | 1540 | |
| 1347 | 1541 | if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) ) |
| … |
… |
function wp_insert_user( $userdata ) {
|
| 1349 | 1543 | |
| 1350 | 1544 | if ( empty($nickname) ) |
| 1351 | 1545 | $nickname = $user_login; |
| | 1546 | |
| | 1547 | /** |
| | 1548 | * Filters the user's nickname before the user is created or updated. |
| | 1549 | * |
| | 1550 | * @since 2.0.11 |
| | 1551 | * |
| | 1552 | * @param string $nickname The user's nickname. |
| | 1553 | */ |
| 1352 | 1554 | $nickname = apply_filters('pre_user_nickname', $nickname); |
| 1353 | 1555 | |
| 1354 | 1556 | if ( empty($first_name) ) |
| 1355 | 1557 | $first_name = ''; |
| | 1558 | |
| | 1559 | /** |
| | 1560 | * Filters the user's first name before the user is created or updated. |
| | 1561 | * |
| | 1562 | * @since 2.0.11 |
| | 1563 | * |
| | 1564 | * @param string $first_name |
| | 1565 | */ |
| 1356 | 1566 | $first_name = apply_filters('pre_user_first_name', $first_name); |
| 1357 | 1567 | |
| 1358 | 1568 | if ( empty($last_name) ) |
| 1359 | 1569 | $last_name = ''; |
| | 1570 | |
| | 1571 | /** |
| | 1572 | * Filters the user's last name before the user is created or updated. |
| | 1573 | * |
| | 1574 | * @since 2.0.11 |
| | 1575 | * |
| | 1576 | * @param string $last_name |
| | 1577 | */ |
| 1360 | 1578 | $last_name = apply_filters('pre_user_last_name', $last_name); |
| 1361 | 1579 | |
| 1362 | 1580 | if ( empty( $display_name ) ) { |
| … |
… |
function wp_insert_user( $userdata ) {
|
| 1372 | 1590 | else |
| 1373 | 1591 | $display_name = $user_login; |
| 1374 | 1592 | } |
| | 1593 | |
| | 1594 | /** |
| | 1595 | * Filters the user's display name before the user is created or updated. |
| | 1596 | * |
| | 1597 | * @since 2.0.11 |
| | 1598 | * |
| | 1599 | * @param string $display_name |
| | 1600 | */ |
| 1375 | 1601 | $display_name = apply_filters( 'pre_user_display_name', $display_name ); |
| 1376 | 1602 | |
| 1377 | 1603 | if ( empty($description) ) |
| 1378 | 1604 | $description = ''; |
| | 1605 | |
| | 1606 | /** |
| | 1607 | * Filters the user's description before the user is created or updated. |
| | 1608 | * |
| | 1609 | * @since 2.0.11 |
| | 1610 | * |
| | 1611 | * @param string $description |
| | 1612 | */ |
| 1379 | 1613 | $description = apply_filters('pre_user_description', $description); |
| 1380 | 1614 | |
| 1381 | 1615 | if ( empty($rich_editing) ) |
| … |
… |
function wp_insert_user( $userdata ) {
|
| 1435 | 1669 | wp_cache_delete($user_id, 'users'); |
| 1436 | 1670 | wp_cache_delete($user_login, 'userlogins'); |
| 1437 | 1671 | |
| 1438 | | if ( $update ) |
| | 1672 | if ( $update ){ |
| | 1673 | /** |
| | 1674 | * Triggered after the user is updated. |
| | 1675 | * |
| | 1676 | * @since 2.0.0 |
| | 1677 | * |
| | 1678 | * @param int $user_id The user ID |
| | 1679 | * @param object $old_user_data User's data prior to update as a raw object |
| | 1680 | */ |
| 1439 | 1681 | do_action('profile_update', $user_id, $old_user_data); |
| 1440 | | else |
| | 1682 | }else{ |
| | 1683 | /** |
| | 1684 | * Triggered after the user is created. |
| | 1685 | * |
| | 1686 | * @since 1.5.2 |
| | 1687 | * |
| | 1688 | * @param int $user_id The user ID |
| | 1689 | */ |
| 1441 | 1690 | do_action('user_register', $user_id); |
| | 1691 | } |
| 1442 | 1692 | |
| 1443 | 1693 | return $user_id; |
| 1444 | 1694 | } |
| … |
… |
function check_password_reset_key($key, $login) {
|
| 1648 | 1898 | * @param string $new_pass New password for the user in plaintext |
| 1649 | 1899 | */ |
| 1650 | 1900 | function reset_password( $user, $new_pass ) { |
| | 1901 | |
| | 1902 | /** |
| | 1903 | * Triggered before the user's password is reset to $new_pass |
| | 1904 | * |
| | 1905 | * @since Unknown |
| | 1906 | * |
| | 1907 | * @param int $user_id The user ID |
| | 1908 | * @param object $old_user_data User's data prior to update as a raw object |
| | 1909 | */ |
| 1651 | 1910 | do_action( 'password_reset', $user, $new_pass ); |
| 1652 | | |
| | 1911 | //@since is uknown but exists before 1.5 |
| 1653 | 1912 | wp_set_password( $new_pass, $user->ID ); |
| 1654 | 1913 | update_user_option( $user->ID, 'default_password_nag', false, true ); |
| 1655 | 1914 | |
| … |
… |
function register_new_user( $user_login, $user_email ) {
|
| 1667 | 1926 | $errors = new WP_Error(); |
| 1668 | 1927 | |
| 1669 | 1928 | $sanitized_user_login = sanitize_user( $user_login ); |
| | 1929 | /** |
| | 1930 | * Filters the email address of a user being registered. |
| | 1931 | * |
| | 1932 | * This hooks is triggered before the user is created. |
| | 1933 | * |
| | 1934 | * @since 2.1.0 |
| | 1935 | * |
| | 1936 | * @param string $user_email The email of the new user. |
| | 1937 | */ |
| 1670 | 1938 | $user_email = apply_filters( 'user_registration_email', $user_email ); |
| 1671 | 1939 | |
| 1672 | 1940 | // Check the username |
| … |
… |
function register_new_user( $user_login, $user_email ) {
|
| 1689 | 1957 | $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); |
| 1690 | 1958 | } |
| 1691 | 1959 | |
| | 1960 | /** |
| | 1961 | * Triggered when registration form data is submitted, and before the user has been created. |
| | 1962 | * |
| | 1963 | * @since 2.1.0 |
| | 1964 | * |
| | 1965 | * @param string $sanitized_user_login The submitted username after sanitization. |
| | 1966 | * @param string $user_email The submitted email. |
| | 1967 | * @param WP_Error $errors Contains any errors with the submitted username and email (e.g. invalid, already exists). |
| | 1968 | */ |
| 1692 | 1969 | do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); |
| 1693 | 1970 | |
| | 1971 | /** |
| | 1972 | * Filters the errors encountered when a new user is beng registerered. |
| | 1973 | * |
| | 1974 | * The filtered WP_Error object may, for example, contain errors for an invalid or existing username or email. |
| | 1975 | * A WP_Error object should always returned, but may or may not contain errors. |
| | 1976 | * |
| | 1977 | * If any errors are present in $errors, this will abort the user's registration. |
| | 1978 | * |
| | 1979 | * @since 2.1.0 |
| | 1980 | * |
| | 1981 | * @param WP_Error $errors A WP_Error object which contains any errors encountered during registration. |
| | 1982 | * @param string $sanitized_user_login The user's username after it has been sanitized. |
| | 1983 | * @param string $user_email The user's email. |
| | 1984 | */ |
| 1694 | 1985 | $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
| 1695 | 1986 | |
| 1696 | 1987 | if ( $errors->get_error_code() ) |