diff options
| author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-04-04 16:44:15 +0000 |
|---|---|---|
| committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-04-04 16:44:15 +0000 |
| commit | 7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc (patch) | |
| tree | c6fd23b598f3994eddb18cb1c0f2e8d95ff054fa /wp-admin/includes/user.php | |
| parent | f650f48c048bfbbb2ae702b6425d87e39358d748 (diff) | |
| download | wordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.tar.gz wordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.tar.xz wordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.zip | |
Merged with WordPress 2.5, unstable, only for testing
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1218 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/includes/user.php')
| -rw-r--r-- | wp-admin/includes/user.php | 141 |
1 files changed, 127 insertions, 14 deletions
diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index ca15057..e423465 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -73,6 +73,13 @@ function edit_user( $user_id = 0 ) { else $user->rich_editing = 'false'; + if ( !$update ) + $user->admin_color = 'fresh'; // Default to fresh for new users. + else if ( isset( $_POST['admin_color'] ) ) + $user->admin_color = $_POST['admin_color']; + else + $user->admin_color = 'fresh'; + $errors = new WP_Error(); /* checking that username has been typed */ @@ -82,37 +89,41 @@ function edit_user( $user_id = 0 ) { /* checking the password has been typed twice */ do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); - if (!$update ) { - if ( $pass1 == '' || $pass2 == '' ) - $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' )); + if ( $update ) { + if ( empty($pass1) && !empty($pass2) ) + $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass1' ) ); + elseif ( !empty($pass1) && empty($pass2) ) + $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass2' ) ); } else { - if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) ) - $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." )); + if ( empty($pass1) ) + $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password.' ), array( 'form-field' => 'pass1' ) ); + elseif ( empty($pass2) ) + $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ), array( 'form-field' => 'pass2' ) ); } /* Check for "\" in password */ if( strpos( " ".$pass1, "\\" ) ) - $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' )); + $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) ); /* checking the password has been typed twice the same */ if ( $pass1 != $pass2 ) - $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' )); + $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' ), array( 'form-field' => 'pass1' ) ); if (!empty ( $pass1 )) $user->user_pass = $pass1; if ( !$update && !validate_username( $user->user_login ) ) - $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); + $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); if (!$update && username_exists( $user->user_login )) - $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' )); + $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' )); /* checking e-mail address */ if ( empty ( $user->user_email ) ) { - $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" )); + $errors->add( 'user_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) ); } else if (!is_email( $user->user_email ) ) { - $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" )); + $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) ); } if ( $errors->get_error_codes() ) @@ -186,8 +197,6 @@ function get_nonauthor_user_ids() { function get_others_unpublished_posts($user_id, $type='any') { global $wpdb; - $user = get_userdata( $user_id ); - $level_key = $wpdb->prefix . 'user_level'; $editable = get_editable_user_ids( $user_id ); @@ -245,7 +254,6 @@ function wp_delete_user($id, $reassign = 'novalue') { global $wpdb; $id = (int) $id; - $user = get_userdata($id); if ($reassign == 'novalue') { $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id"); @@ -270,6 +278,7 @@ function wp_delete_user($id, $reassign = 'novalue') { wp_cache_delete($id, 'users'); wp_cache_delete($user->user_login, 'userlogins'); + wp_cache_delete($user->user_email, 'useremail'); return true; } @@ -281,4 +290,108 @@ function wp_revoke_user($id) { $user->remove_all_caps(); } +// WP_User_Search class +// by Mark Jaquith + +if ( !class_exists('WP_User_Search') ) : +class WP_User_Search { + var $results; + var $search_term; + var $page; + var $role; + var $raw_page; + var $users_per_page = 50; + var $first_user; + var $last_user; + var $query_limit; + var $query_sort; + var $query_from_where; + var $total_users_for_query = 0; + var $too_many_total_users = false; + var $search_errors; + + function WP_User_Search ($search_term = '', $page = '', $role = '') { // constructor + $this->search_term = $search_term; + $this->raw_page = ( '' == $page ) ? false : (int) $page; + $this->page = (int) ( '' == $page ) ? 1 : $page; + $this->role = $role; + + $this->prepare_query(); + $this->query(); + $this->prepare_vars_for_template_usage(); + $this->do_paging(); + } + + function prepare_query() { + global $wpdb; + $this->first_user = ($this->page - 1) * $this->users_per_page; + $this->query_limit = ' LIMIT ' . $this->first_user . ',' . $this->users_per_page; + $this->query_sort = ' ORDER BY user_login'; + $search_sql = ''; + if ( $this->search_term ) { + $searches = array(); + $search_sql = 'AND ('; + foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) + $searches[] = $col . " LIKE '%$this->search_term%'"; + $search_sql .= implode(' OR ', $searches); + $search_sql .= ')'; + } + + $this->query_from_where = "FROM $wpdb->users"; + if ( $this->role ) + $this->query_from_where .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE '%$this->role%'"; + else + $this->query_from_where .= " WHERE 1=1"; + $this->query_from_where .= " $search_sql"; + + } + + function query() { + global $wpdb; + $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_sort . $this->query_limit); + + if ( $this->results ) + $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit + else + $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!')); + } + + function prepare_vars_for_template_usage() { + $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone + } + + function do_paging() { + if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results + $this->paging_text = paginate_links( array( + 'total' => ceil($this->total_users_for_query / $this->users_per_page), + 'current' => $this->page, + 'base' => 'users.php?%_%', + 'format' => 'userspage=%#%', + 'add_args' => array( 'usersearch' => urlencode($this->search_term) ) + ) ); + } + } + + function get_results() { + return (array) $this->results; + } + + function page_links() { + echo $this->paging_text; + } + + function results_are_paged() { + if ( $this->paging_text ) + return true; + return false; + } + + function is_search() { + if ( $this->search_term ) + return true; + return false; + } +} +endif; + ?> |
