154 $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' ), array( 'form-field' => 'pass1' ) ); |
131 $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' ), array( 'form-field' => 'pass1' ) ); |
155 |
132 |
156 if ( !empty( $pass1 ) ) |
133 if ( !empty( $pass1 ) ) |
157 $user->user_pass = $pass1; |
134 $user->user_pass = $pass1; |
158 |
135 |
159 if ( !$update && !validate_username( $user->user_login ) ) |
136 if ( !$update && isset( $_POST['user_login'] ) && !validate_username( $_POST['user_login'] ) ) |
160 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); |
137 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' )); |
161 |
138 |
162 if ( !$update && username_exists( $user->user_login ) ) |
139 if ( !$update && username_exists( $user->user_login ) ) |
163 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' )); |
140 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' )); |
164 |
141 |
165 /* checking e-mail address */ |
142 /* checking e-mail address */ |
166 if ( empty( $user->user_email ) ) { |
143 if ( empty( $user->user_email ) ) { |
167 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) ); |
144 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) ); |
168 } elseif ( !is_email( $user->user_email ) ) { |
145 } elseif ( !is_email( $user->user_email ) ) { |
169 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The e-mail address isn’t correct.' ), array( 'form-field' => 'email' ) ); |
146 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The e-mail address isn’t correct.' ), array( 'form-field' => 'email' ) ); |
170 } elseif ( ( $owner_id = email_exists($user->user_email) ) && $owner_id != $user->ID ) { |
147 } elseif ( ( $owner_id = email_exists($user->user_email) ) && ( !$update || ( $owner_id != $user->ID ) ) ) { |
171 $errors->add( 'email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array( 'form-field' => 'email' ) ); |
148 $errors->add( 'email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array( 'form-field' => 'email' ) ); |
172 } |
149 } |
173 |
150 |
174 // Allow plugins to return their own errors. |
151 // Allow plugins to return their own errors. |
175 do_action_ref_array('user_profile_update_errors', array ( &$errors, $update, &$user ) ); |
152 do_action_ref_array('user_profile_update_errors', array ( &$errors, $update, &$user ) ); |
282 |
187 |
283 return $editable_roles; |
188 return $editable_roles; |
284 } |
189 } |
285 |
190 |
286 /** |
191 /** |
287 * {@internal Missing Short Description}} |
|
288 * |
|
289 * {@internal Missing Long Description}} |
|
290 * |
|
291 * @since unknown |
|
292 * |
|
293 * @return unknown |
|
294 */ |
|
295 function get_nonauthor_user_ids() { |
|
296 global $wpdb; |
|
297 $level_key = $wpdb->prefix . 'user_level'; |
|
298 |
|
299 return $wpdb->get_col( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value = '0'", $level_key) ); |
|
300 } |
|
301 |
|
302 /** |
|
303 * Retrieve editable posts from other users. |
|
304 * |
|
305 * @since unknown |
|
306 * |
|
307 * @param int $user_id User ID to not retrieve posts from. |
|
308 * @param string $type Optional, defaults to 'any'. Post type to retrieve, can be 'draft' or 'pending'. |
|
309 * @return array List of posts from others. |
|
310 */ |
|
311 function get_others_unpublished_posts($user_id, $type='any') { |
|
312 global $wpdb; |
|
313 |
|
314 $editable = get_editable_user_ids( $user_id ); |
|
315 |
|
316 if ( in_array($type, array('draft', 'pending')) ) |
|
317 $type_sql = " post_status = '$type' "; |
|
318 else |
|
319 $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) "; |
|
320 |
|
321 $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC'; |
|
322 |
|
323 if( !$editable ) { |
|
324 $other_unpubs = ''; |
|
325 } else { |
|
326 $editable = join(',', $editable); |
|
327 $other_unpubs = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_title, post_author FROM $wpdb->posts WHERE post_type = 'post' AND $type_sql AND post_author IN ($editable) AND post_author != %d ORDER BY post_modified $dir", $user_id) ); |
|
328 } |
|
329 |
|
330 return apply_filters('get_others_drafts', $other_unpubs); |
|
331 } |
|
332 |
|
333 /** |
|
334 * Retrieve drafts from other users. |
|
335 * |
|
336 * @since unknown |
|
337 * |
|
338 * @param int $user_id User ID. |
|
339 * @return array List of drafts from other users. |
|
340 */ |
|
341 function get_others_drafts($user_id) { |
|
342 return get_others_unpublished_posts($user_id, 'draft'); |
|
343 } |
|
344 |
|
345 /** |
|
346 * Retrieve pending review posts from other users. |
|
347 * |
|
348 * @since unknown |
|
349 * |
|
350 * @param int $user_id User ID. |
|
351 * @return array List of posts with pending review post type from other users. |
|
352 */ |
|
353 function get_others_pending($user_id) { |
|
354 return get_others_unpublished_posts($user_id, 'pending'); |
|
355 } |
|
356 |
|
357 /** |
|
358 * Retrieve user data and filter it. |
192 * Retrieve user data and filter it. |
359 * |
193 * |
360 * @since unknown |
194 * @since 2.0.5 |
361 * |
195 * |
362 * @param int $user_id User ID. |
196 * @param int $user_id User ID. |
363 * @return object WP_User object with user data. |
197 * @return object WP_User object with user data. |
364 */ |
198 */ |
365 function get_user_to_edit( $user_id ) { |
199 function get_user_to_edit( $user_id ) { |
366 $user = new WP_User( $user_id ); |
200 $user = new WP_User( $user_id ); |
367 |
201 |
368 $user_contactmethods = _wp_get_user_contactmethods(); |
202 $user->filter = 'edit'; |
369 foreach ($user_contactmethods as $method => $name) { |
|
370 if ( empty( $user->{$method} ) ) |
|
371 $user->{$method} = ''; |
|
372 } |
|
373 |
|
374 if ( empty($user->description) ) |
|
375 $user->description = ''; |
|
376 |
|
377 $user = sanitize_user_object($user, 'edit'); |
|
378 |
203 |
379 return $user; |
204 return $user; |
380 } |
205 } |
381 |
206 |
382 /** |
207 /** |
383 * Retrieve the user's drafts. |
208 * Retrieve the user's drafts. |
384 * |
209 * |
385 * @since unknown |
210 * @since 2.0.0 |
386 * |
211 * |
387 * @param int $user_id User ID. |
212 * @param int $user_id User ID. |
388 * @return array |
213 * @return array |
389 */ |
214 */ |
390 function get_users_drafts( $user_id ) { |
215 function get_users_drafts( $user_id ) { |
400 * If the $reassign parameter is not assigned to an User ID, then all posts will |
225 * If the $reassign parameter is not assigned to an User ID, then all posts will |
401 * be deleted of that user. The action 'delete_user' that is passed the User ID |
226 * be deleted of that user. The action 'delete_user' that is passed the User ID |
402 * being deleted will be run after the posts are either reassigned or deleted. |
227 * being deleted will be run after the posts are either reassigned or deleted. |
403 * The user meta will also be deleted that are for that User ID. |
228 * The user meta will also be deleted that are for that User ID. |
404 * |
229 * |
405 * @since unknown |
230 * @since 2.0.0 |
406 * |
231 * |
407 * @param int $id User ID. |
232 * @param int $id User ID. |
408 * @param int $reassign Optional. Reassign posts and links to new User ID. |
233 * @param int $reassign Optional. Reassign posts and links to new User ID. |
409 * @return bool True when finished. |
234 * @return bool True when finished. |
410 */ |
235 */ |
411 function wp_delete_user($id, $reassign = 'novalue') { |
236 function wp_delete_user( $id, $reassign = 'novalue' ) { |
412 global $wpdb; |
237 global $wpdb; |
413 |
238 |
414 $id = (int) $id; |
239 $id = (int) $id; |
415 $user = new WP_User($id); |
240 $user = new WP_User( $id ); |
416 |
241 |
417 // allow for transaction statement |
242 // allow for transaction statement |
418 do_action('delete_user', $id); |
243 do_action('delete_user', $id); |
419 |
244 |
420 if ($reassign == 'novalue') { |
245 if ( 'novalue' === $reassign || null === $reassign ) { |
421 $post_ids = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id) ); |
246 $post_types_to_delete = array(); |
422 |
247 foreach ( get_post_types( array(), 'objects' ) as $post_type ) { |
423 if ($post_ids) { |
248 if ( $post_type->delete_with_user ) { |
424 foreach ($post_ids as $post_id) |
249 $post_types_to_delete[] = $post_type->name; |
425 wp_delete_post($post_id); |
250 } elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) { |
|
251 $post_types_to_delete[] = $post_type->name; |
|
252 } |
|
253 } |
|
254 |
|
255 $post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id ); |
|
256 $post_types_to_delete = implode( "', '", $post_types_to_delete ); |
|
257 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) ); |
|
258 if ( $post_ids ) { |
|
259 foreach ( $post_ids as $post_id ) |
|
260 wp_delete_post( $post_id ); |
426 } |
261 } |
427 |
262 |
428 // Clean links |
263 // Clean links |
429 $link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) ); |
264 $link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) ); |
430 |
265 |
431 if ( $link_ids ) { |
266 if ( $link_ids ) { |
432 foreach ( $link_ids as $link_id ) |
267 foreach ( $link_ids as $link_id ) |
433 wp_delete_link($link_id); |
268 wp_delete_link($link_id); |
434 } |
269 } |
435 |
|
436 } else { |
270 } else { |
437 $reassign = (int) $reassign; |
271 $reassign = (int) $reassign; |
438 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $id) ); |
272 $wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) ); |
439 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $id) ); |
273 $wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) ); |
440 } |
274 } |
441 |
275 |
442 // FINALLY, delete user |
276 // FINALLY, delete user |
443 |
277 if ( is_multisite() ) { |
444 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) ); |
278 remove_user_from_blog( $id, get_current_blog_id() ); |
445 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) ); |
279 } else { |
446 |
280 $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); |
447 wp_cache_delete($id, 'users'); |
281 foreach ( $meta as $mid ) |
448 wp_cache_delete($user->user_login, 'userlogins'); |
282 delete_metadata_by_mid( 'user', $mid ); |
449 wp_cache_delete($user->user_email, 'useremail'); |
283 |
450 wp_cache_delete($user->user_nicename, 'userslugs'); |
284 $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); |
|
285 } |
|
286 |
|
287 clean_user_cache( $user ); |
451 |
288 |
452 // allow for commit transaction |
289 // allow for commit transaction |
453 do_action('deleted_user', $id); |
290 do_action('deleted_user', $id); |
454 |
291 |
455 return true; |
292 return true; |
456 } |
293 } |
457 |
294 |
458 /** |
295 /** |
459 * Remove all capabilities from user. |
296 * Remove all capabilities from user. |
460 * |
297 * |
461 * @since unknown |
298 * @since 2.1.0 |
462 * |
299 * |
463 * @param int $id User ID. |
300 * @param int $id User ID. |
464 */ |
301 */ |
465 function wp_revoke_user($id) { |
302 function wp_revoke_user($id) { |
466 $id = (int) $id; |
303 $id = (int) $id; |
467 |
304 |
468 $user = new WP_User($id); |
305 $user = new WP_User($id); |
469 $user->remove_all_caps(); |
306 $user->remove_all_caps(); |
470 } |
307 } |
471 |
308 |
472 if ( !class_exists('WP_User_Search') ) : |
|
473 /** |
|
474 * WordPress User Search class. |
|
475 * |
|
476 * @since unknown |
|
477 * @author Mark Jaquith |
|
478 */ |
|
479 class WP_User_Search { |
|
480 |
|
481 /** |
|
482 * {@internal Missing Description}} |
|
483 * |
|
484 * @since unknown |
|
485 * @access private |
|
486 * @var unknown_type |
|
487 */ |
|
488 var $results; |
|
489 |
|
490 /** |
|
491 * {@internal Missing Description}} |
|
492 * |
|
493 * @since unknown |
|
494 * @access private |
|
495 * @var unknown_type |
|
496 */ |
|
497 var $search_term; |
|
498 |
|
499 /** |
|
500 * Page number. |
|
501 * |
|
502 * @since unknown |
|
503 * @access private |
|
504 * @var int |
|
505 */ |
|
506 var $page; |
|
507 |
|
508 /** |
|
509 * Role name that users have. |
|
510 * |
|
511 * @since unknown |
|
512 * @access private |
|
513 * @var string |
|
514 */ |
|
515 var $role; |
|
516 |
|
517 /** |
|
518 * Raw page number. |
|
519 * |
|
520 * @since unknown |
|
521 * @access private |
|
522 * @var int|bool |
|
523 */ |
|
524 var $raw_page; |
|
525 |
|
526 /** |
|
527 * Amount of users to display per page. |
|
528 * |
|
529 * @since unknown |
|
530 * @access public |
|
531 * @var int |
|
532 */ |
|
533 var $users_per_page = 50; |
|
534 |
|
535 /** |
|
536 * {@internal Missing Description}} |
|
537 * |
|
538 * @since unknown |
|
539 * @access private |
|
540 * @var unknown_type |
|
541 */ |
|
542 var $first_user; |
|
543 |
|
544 /** |
|
545 * {@internal Missing Description}} |
|
546 * |
|
547 * @since unknown |
|
548 * @access private |
|
549 * @var int |
|
550 */ |
|
551 var $last_user; |
|
552 |
|
553 /** |
|
554 * {@internal Missing Description}} |
|
555 * |
|
556 * @since unknown |
|
557 * @access private |
|
558 * @var unknown_type |
|
559 */ |
|
560 var $query_limit; |
|
561 |
|
562 /** |
|
563 * {@internal Missing Description}} |
|
564 * |
|
565 * @since unknown |
|
566 * @access private |
|
567 * @var unknown_type |
|
568 */ |
|
569 var $query_sort; |
|
570 |
|
571 /** |
|
572 * {@internal Missing Description}} |
|
573 * |
|
574 * @since unknown |
|
575 * @access private |
|
576 * @var unknown_type |
|
577 */ |
|
578 var $query_from_where; |
|
579 |
|
580 /** |
|
581 * {@internal Missing Description}} |
|
582 * |
|
583 * @since unknown |
|
584 * @access private |
|
585 * @var int |
|
586 */ |
|
587 var $total_users_for_query = 0; |
|
588 |
|
589 /** |
|
590 * {@internal Missing Description}} |
|
591 * |
|
592 * @since unknown |
|
593 * @access private |
|
594 * @var bool |
|
595 */ |
|
596 var $too_many_total_users = false; |
|
597 |
|
598 /** |
|
599 * {@internal Missing Description}} |
|
600 * |
|
601 * @since unknown |
|
602 * @access private |
|
603 * @var unknown_type |
|
604 */ |
|
605 var $search_errors; |
|
606 |
|
607 /** |
|
608 * {@internal Missing Description}} |
|
609 * |
|
610 * @since unknown |
|
611 * @access private |
|
612 * @var unknown_type |
|
613 */ |
|
614 var $paging_text; |
|
615 |
|
616 /** |
|
617 * PHP4 Constructor - Sets up the object properties. |
|
618 * |
|
619 * @since unknown |
|
620 * |
|
621 * @param string $search_term Search terms string. |
|
622 * @param int $page Optional. Page ID. |
|
623 * @param string $role Role name. |
|
624 * @return WP_User_Search |
|
625 */ |
|
626 function WP_User_Search ($search_term = '', $page = '', $role = '') { |
|
627 $this->search_term = $search_term; |
|
628 $this->raw_page = ( '' == $page ) ? false : (int) $page; |
|
629 $this->page = (int) ( '' == $page ) ? 1 : $page; |
|
630 $this->role = $role; |
|
631 |
|
632 $this->prepare_query(); |
|
633 $this->query(); |
|
634 $this->prepare_vars_for_template_usage(); |
|
635 $this->do_paging(); |
|
636 } |
|
637 |
|
638 /** |
|
639 * {@internal Missing Short Description}} |
|
640 * |
|
641 * {@internal Missing Long Description}} |
|
642 * |
|
643 * @since unknown |
|
644 * @access public |
|
645 */ |
|
646 function prepare_query() { |
|
647 global $wpdb; |
|
648 $this->first_user = ($this->page - 1) * $this->users_per_page; |
|
649 $this->query_limit = $wpdb->prepare(" LIMIT %d, %d", $this->first_user, $this->users_per_page); |
|
650 $this->query_sort = ' ORDER BY user_login'; |
|
651 $search_sql = ''; |
|
652 if ( $this->search_term ) { |
|
653 $searches = array(); |
|
654 $search_sql = 'AND ('; |
|
655 foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) |
|
656 $searches[] = $col . " LIKE '%$this->search_term%'"; |
|
657 $search_sql .= implode(' OR ', $searches); |
|
658 $search_sql .= ')'; |
|
659 } |
|
660 |
|
661 $this->query_from_where = "FROM $wpdb->users"; |
|
662 if ( $this->role ) |
|
663 $this->query_from_where .= $wpdb->prepare(" 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 %s", '%' . $this->role . '%'); |
|
664 else |
|
665 $this->query_from_where .= " WHERE 1=1"; |
|
666 $this->query_from_where .= " $search_sql"; |
|
667 |
|
668 } |
|
669 |
|
670 /** |
|
671 * {@internal Missing Short Description}} |
|
672 * |
|
673 * {@internal Missing Long Description}} |
|
674 * |
|
675 * @since unknown |
|
676 * @access public |
|
677 */ |
|
678 function query() { |
|
679 global $wpdb; |
|
680 $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_sort . $this->query_limit); |
|
681 |
|
682 if ( $this->results ) |
|
683 $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit |
|
684 else |
|
685 $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!')); |
|
686 } |
|
687 |
|
688 /** |
|
689 * {@internal Missing Short Description}} |
|
690 * |
|
691 * {@internal Missing Long Description}} |
|
692 * |
|
693 * @since unknown |
|
694 * @access public |
|
695 */ |
|
696 function prepare_vars_for_template_usage() { |
|
697 $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone |
|
698 } |
|
699 |
|
700 /** |
|
701 * {@internal Missing Short Description}} |
|
702 * |
|
703 * {@internal Missing Long Description}} |
|
704 * |
|
705 * @since unknown |
|
706 * @access public |
|
707 */ |
|
708 function do_paging() { |
|
709 if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results |
|
710 $args = array(); |
|
711 if( ! empty($this->search_term) ) |
|
712 $args['usersearch'] = urlencode($this->search_term); |
|
713 if( ! empty($this->role) ) |
|
714 $args['role'] = urlencode($this->role); |
|
715 |
|
716 $this->paging_text = paginate_links( array( |
|
717 'total' => ceil($this->total_users_for_query / $this->users_per_page), |
|
718 'current' => $this->page, |
|
719 'base' => 'users.php?%_%', |
|
720 'format' => 'userspage=%#%', |
|
721 'add_args' => $args |
|
722 ) ); |
|
723 if ( $this->paging_text ) { |
|
724 $this->paging_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s', |
|
725 number_format_i18n( ( $this->page - 1 ) * $this->users_per_page + 1 ), |
|
726 number_format_i18n( min( $this->page * $this->users_per_page, $this->total_users_for_query ) ), |
|
727 number_format_i18n( $this->total_users_for_query ), |
|
728 $this->paging_text |
|
729 ); |
|
730 } |
|
731 } |
|
732 } |
|
733 |
|
734 /** |
|
735 * {@internal Missing Short Description}} |
|
736 * |
|
737 * {@internal Missing Long Description}} |
|
738 * |
|
739 * @since unknown |
|
740 * @access public |
|
741 * |
|
742 * @return unknown |
|
743 */ |
|
744 function get_results() { |
|
745 return (array) $this->results; |
|
746 } |
|
747 |
|
748 /** |
|
749 * Displaying paging text. |
|
750 * |
|
751 * @see do_paging() Builds paging text. |
|
752 * |
|
753 * @since unknown |
|
754 * @access public |
|
755 */ |
|
756 function page_links() { |
|
757 echo $this->paging_text; |
|
758 } |
|
759 |
|
760 /** |
|
761 * Whether paging is enabled. |
|
762 * |
|
763 * @see do_paging() Builds paging text. |
|
764 * |
|
765 * @since unknown |
|
766 * @access public |
|
767 * |
|
768 * @return bool |
|
769 */ |
|
770 function results_are_paged() { |
|
771 if ( $this->paging_text ) |
|
772 return true; |
|
773 return false; |
|
774 } |
|
775 |
|
776 /** |
|
777 * Whether there are search terms. |
|
778 * |
|
779 * @since unknown |
|
780 * @access public |
|
781 * |
|
782 * @return bool |
|
783 */ |
|
784 function is_search() { |
|
785 if ( $this->search_term ) |
|
786 return true; |
|
787 return false; |
|
788 } |
|
789 } |
|
790 endif; |
|
791 |
|
792 add_action('admin_init', 'default_password_nag_handler'); |
309 add_action('admin_init', 'default_password_nag_handler'); |
|
310 /** |
|
311 * @since 2.8.0 |
|
312 */ |
793 function default_password_nag_handler($errors = false) { |
313 function default_password_nag_handler($errors = false) { |
794 global $user_ID; |
314 global $user_ID; |
795 if ( ! get_usermeta($user_ID, 'default_password_nag') ) //Short circuit it. |
315 if ( ! get_user_option('default_password_nag') ) //Short circuit it. |
796 return; |
316 return; |
797 |
317 |
798 //get_user_setting = JS saved UI setting. else no-js-falback code. |
318 //get_user_setting = JS saved UI setting. else no-js-fallback code. |
799 if ( 'hide' == get_user_setting('default_password_nag') || isset($_GET['default_password_nag']) && '0' == $_GET['default_password_nag'] ) { |
319 if ( 'hide' == get_user_setting('default_password_nag') || isset($_GET['default_password_nag']) && '0' == $_GET['default_password_nag'] ) { |
800 delete_user_setting('default_password_nag'); |
320 delete_user_setting('default_password_nag'); |
801 update_usermeta($user_ID, 'default_password_nag', false); |
321 update_user_option($user_ID, 'default_password_nag', false, true); |
802 } |
322 } |
803 } |
323 } |
804 |
324 |
805 add_action('profile_update', 'default_password_nag_edit_user', 10, 2); |
325 add_action('profile_update', 'default_password_nag_edit_user', 10, 2); |
|
326 /** |
|
327 * @since 2.8.0 |
|
328 */ |
806 function default_password_nag_edit_user($user_ID, $old_data) { |
329 function default_password_nag_edit_user($user_ID, $old_data) { |
807 global $user_ID; |
330 if ( ! get_user_option('default_password_nag', $user_ID) ) //Short circuit it. |
808 if ( ! get_usermeta($user_ID, 'default_password_nag') ) //Short circuit it. |
|
809 return; |
331 return; |
810 |
332 |
811 $new_data = get_userdata($user_ID); |
333 $new_data = get_userdata($user_ID); |
812 |
334 |
813 if ( $new_data->user_pass != $old_data->user_pass ) { //Remove the nag if the password has been changed. |
335 if ( $new_data->user_pass != $old_data->user_pass ) { //Remove the nag if the password has been changed. |
814 delete_user_setting('default_password_nag'); |
336 delete_user_setting('default_password_nag', $user_ID); |
815 update_usermeta($user_ID, 'default_password_nag', false); |
337 update_user_option($user_ID, 'default_password_nag', false, true); |
816 } |
338 } |
817 } |
339 } |
818 |
340 |
819 add_action('admin_notices', 'default_password_nag'); |
341 add_action('admin_notices', 'default_password_nag'); |
|
342 /** |
|
343 * @since 2.8.0 |
|
344 */ |
820 function default_password_nag() { |
345 function default_password_nag() { |
821 global $user_ID; |
346 global $pagenow; |
822 if ( ! get_usermeta($user_ID, 'default_password_nag') ) |
347 if ( 'profile.php' == $pagenow || ! get_user_option('default_password_nag') ) //Short circuit it. |
823 return; |
348 return; |
824 |
349 |
825 echo '<div class="error default-password-nag"><p>'; |
350 echo '<div class="error default-password-nag">'; |
826 printf(__("Notice: you're using the auto-generated password for your account. Would you like to change it to something you'll remember easier?<br /> |
351 echo '<p>'; |
827 <a href='%s'>Yes, Take me to my profile page</a> | <a href='%s' id='default-password-nag-no'>No Thanks, Do not remind me again.</a>"), admin_url('profile.php') . '#password', '?default_password_nag=0'); |
352 echo '<strong>' . __('Notice:') . '</strong> '; |
|
353 _e('You’re using the auto-generated password for your account. Would you like to change it to something easier to remember?'); |
|
354 echo '</p><p>'; |
|
355 printf( '<a href="%s">' . __('Yes, take me to my profile page') . '</a> | ', admin_url('profile.php') . '#password' ); |
|
356 printf( '<a href="%s" id="default-password-nag-no">' . __('No thanks, do not remind me again') . '</a>', '?default_password_nag=0' ); |
828 echo '</p></div>'; |
357 echo '</p></div>'; |
829 } |
358 } |
830 |
|
831 ?> |
|