PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
← All changes | includes/users/functions.php +104 -143 trunk2.6.6 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2
3 3 /**
4 - * bbPress User Functions.
4 + * bbPress User Functions
5 5 *
6 6 * @package bbPress
7 7 * @subpackage Functions
8 8 */
@@ -10,15 +10,15 @@
10 10 // Exit if accessed directly
11 11 defined( 'ABSPATH' ) || exit;
12 12
13 13 /**
14 - * Redirect back to $url when attempting to use the login page.
14 + * Redirect back to $url when attempting to use the login page
15 15 *
16 16 * @since 2.0.0 bbPress (r2815)
17 17 *
18 - * @param string $url The url.
19 - * @param string $raw_url Raw url.
20 - * @param object $user User object.
18 + * @param string $url The url
19 + * @param string $raw_url Raw url
20 + * @param object $user User object
21 21 */
22 22 function bbp_redirect_login( $url = '', $raw_url = '', $user = '' ) {
23 23
24 24 // Raw redirect_to was passed, so use it
@@ -43,9 +43,9 @@
43 43 *
44 44 * @since 2.0.0 bbPress (r2688)
45 45 *
46 46 * @return bool True if anonymous is allowed and user is not logged in, false if
47 - * anonymous is not allowed or user is logged in.
47 + * anonymous is not allowed or user is logged in
48 48 */
49 49 function bbp_is_anonymous() {
50 50 $is_anonymous = ( ! is_user_logged_in() && bbp_allow_anonymous() );
51 51
@@ -53,9 +53,9 @@
53 53 return (bool) apply_filters( 'bbp_is_anonymous', $is_anonymous );
54 54 }
55 55
56 56 /**
57 - * Echoes the values for current poster (uses WP comment cookies).
57 + * Echoes the values for current poster (uses WP comment cookies)
58 58 *
59 59 * @since 2.0.0 bbPress (r2734)
60 60 *
61 61 * @param string $key Which value to echo?
@@ -63,54 +63,54 @@
63 63 function bbp_current_anonymous_user_data( $key = '' ) {
64 64 echo esc_attr( bbp_get_current_anonymous_user_data( $key ) );
65 65 }
66 66
67 -/**
68 - * Get the cookies for current poster (uses WP comment cookies).
69 - *
70 - * @since 2.0.0 bbPress (r2734)
71 - *
72 - * @param string $key Optional. Which value to get? If not given, then
73 - * an array is returned.
74 - * @return string|array Cookie(s) for current poster.
75 - */
76 -function bbp_get_current_anonymous_user_data( $key = '' ) {
67 + /**
68 + * Get the cookies for current poster (uses WP comment cookies).
69 + *
70 + * @since 2.0.0 bbPress (r2734)
71 + *
72 + * @param string $key Optional. Which value to get? If not given, then
73 + * an array is returned.
74 + * @return string|array Cookie(s) for current poster
75 + */
76 + function bbp_get_current_anonymous_user_data( $key = '' ) {
77 77
78 - // Array of allowed cookie names
79 - $cookie_names = array(
80 - 'name' => 'comment_author',
81 - 'email' => 'comment_author_email',
82 - 'url' => 'comment_author_url',
78 + // Array of allowed cookie names
79 + $cookie_names = array(
80 + 'name' => 'comment_author',
81 + 'email' => 'comment_author_email',
82 + 'url' => 'comment_author_url',
83 83
84 - // Here just for the sake of them, use the above ones
85 - 'comment_author' => 'comment_author',
86 - 'comment_author_email' => 'comment_author_email',
87 - 'comment_author_url' => 'comment_author_url',
88 - );
84 + // Here just for the sake of them, use the above ones
85 + 'comment_author' => 'comment_author',
86 + 'comment_author_email' => 'comment_author_email',
87 + 'comment_author_url' => 'comment_author_url',
88 + );
89 89
90 - // Get the current poster's info from the cookies
91 - $bbp_current_poster = wp_get_current_commenter();
90 + // Get the current poster's info from the cookies
91 + $bbp_current_poster = wp_get_current_commenter();
92 92
93 - // Sanitize the cookie key being retrieved
94 - $key = sanitize_key( $key );
93 + // Sanitize the cookie key being retrieved
94 + $key = sanitize_key( $key );
95 95
96 - // Maybe return a specific key
97 - if ( ! empty( $key ) && in_array( $key, array_keys( $cookie_names ), true ) ) {
98 - return $bbp_current_poster[ $cookie_names[ $key ] ];
96 + // Maybe return a specific key
97 + if ( ! empty( $key ) && in_array( $key, array_keys( $cookie_names ), true ) ) {
98 + return $bbp_current_poster[ $cookie_names[ $key ] ];
99 + }
100 +
101 + // Return all keys
102 + return $bbp_current_poster;
99 103 }
100 104
101 - // Return all keys
102 - return $bbp_current_poster;
103 -}
104 -
105 105 /**
106 - * Set the cookies for current poster (uses WP comment cookies).
106 + * Set the cookies for current poster (uses WP comment cookies)
107 107 *
108 108 * @since 2.0.0 bbPress (r2734)
109 109 *
110 110 * @param array $anonymous_data Optional - if it's an anonymous post. Do not
111 111 * supply if supplying $author_id. Should be
112 - * sanitized (see {@link bbp_filter_anonymous_post_data()}.
112 + * sanitized (see {@link bbp_filter_anonymous_post_data()}
113 113 */
114 114 function bbp_set_current_anonymous_user_data( $anonymous_data = array() ) {
115 115
116 116 // Bail if empty or not an array
@@ -120,9 +120,9 @@
120 120
121 121 // Setup cookie expiration
122 122 $lifetime = (int) apply_filters( 'comment_cookie_lifetime', 30000000 );
123 123 $expiry = time() + $lifetime;
124 - $secure = ( 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME ) );
124 + $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
125 125
126 126 // Set the cookies
127 127 setcookie( 'comment_author_' . COOKIEHASH, $anonymous_data['bbp_anonymous_name'], $expiry, COOKIEPATH, COOKIE_DOMAIN, $secure );
128 128 setcookie( 'comment_author_email_' . COOKIEHASH, $anonymous_data['bbp_anonymous_email'], $expiry, COOKIEPATH, COOKIE_DOMAIN, $secure );
@@ -129,9 +129,9 @@
129 129 setcookie( 'comment_author_url_' . COOKIEHASH, $anonymous_data['bbp_anonymous_website'], $expiry, COOKIEPATH, COOKIE_DOMAIN, $secure );
130 130 }
131 131
132 132 /**
133 - * Get the poster IP address.
133 + * Get the poster IP address
134 134 *
135 135 * @since 2.0.0 bbPress (r3120)
136 136 * @since 2.6.0 bbPress (r5609) Added `empty()` check for unit tests
137 137 *
@@ -151,9 +151,9 @@
151 151 return apply_filters( 'bbp_current_author_ip', $retval, $remote_address );
152 152 }
153 153
154 154 /**
155 - * Get the poster user agent.
155 + * Get the poster user agent
156 156 *
157 157 * @since 2.0.0 bbPress (r3446)
158 158 *
159 159 * @return string
@@ -169,13 +169,13 @@
169 169
170 170 /** Edit **********************************************************************/
171 171
172 172 /**
173 - * Handles the front end user editing from POST requests.
173 + * Handles the front end user editing from POST requests
174 174 *
175 175 * @since 2.0.0 bbPress (r2790)
176 176 *
177 - * @param string $action The requested action to compare this function to.
177 + * @param string $action The requested action to compare this function to
178 178 */
179 179 function bbp_edit_user_handler( $action = '' ) {
180 180
181 181 // Bail if action is not `bbp-update-user`
@@ -190,10 +190,10 @@
190 190
191 191 // Get the displayed user ID
192 192 $user_id = bbp_get_displayed_user_id();
193 193
194 - // Request check
195 - if ( ! bbp_is_user_profile_form_post_request( $user_id ) ) {
194 + // Nonce check
195 + if ( ! bbp_verify_nonce_request( 'update-user_' . $user_id ) ) {
196 196 bbp_add_error( 'bbp_update_user_nonce', __( '<strong>Error</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
197 197 return;
198 198 }
199 199
@@ -262,9 +262,9 @@
262 262
263 263 // Handle user edit
264 264 $edit_user = edit_user( $user_id );
265 265
266 - // Error(s) editing the user, so copy them into the global.
266 + // Error(s) editng the user, so copy them into the global
267 267 if ( is_wp_error( $edit_user ) ) {
268 268 bbpress()->errors = $edit_user;
269 269
270 270 // Successful edit to redirect
@@ -286,9 +286,9 @@
286 286 }
287 287 }
288 288
289 289 /**
290 - * Handles user email address updating from GET requests.
290 + * Handles user email address updating from GET requests
291 291 *
292 292 * @since 2.6.0 bbPress (r5660)
293 293 *
294 294 * @param string $action
@@ -386,9 +386,9 @@
386 386 }
387 387 }
388 388
389 389 /**
390 - * Sends an email when an email address change occurs on POST requests.
390 + * Sends an email when an email address change occurs on POST requests
391 391 *
392 392 * @since 2.6.0 bbPress (r5660)
393 393 *
394 394 * @see send_confirmation_on_profile_email()
@@ -395,15 +395,12 @@
395 395 */
396 396 function bbp_edit_user_email_send_notification( $user_id = 0, $args = array() ) {
397 397
398 398 // Parse args
399 - $r = bbp_parse_args(
400 - $args,
401 - array(
402 - 'hash' => '',
403 - 'newemail' => '',
404 - )
405 - );
399 + $r = bbp_parse_args( $args, array(
400 + 'hash' => '',
401 + 'newemail' => '',
402 + ) );
406 403
407 404 // Bail if any relevant parameters are empty
408 405 if ( empty( $user_id ) || empty( $r['hash'] ) || empty( $r['newemail'] ) ) {
409 406 bbp_add_error( 'bbp_user_email_invalid_hash', __( '<strong>Error</strong>: An error occurred while updating your email address.', 'bbpress' ), array( 'form-field' => 'email' ) );
@@ -412,19 +409,14 @@
412 409
413 410 // Build the nonced URL to dismiss the pending change
414 411 $user_login = bbp_get_displayed_user_field( 'user_login', 'raw' );
415 412 $user_url = bbp_get_user_profile_edit_url( $user_id );
416 - $confirm_url = add_query_arg(
417 - array(
418 - 'action' => 'bbp-update-user-email',
419 - 'newuseremail' => $r['hash']
420 - ),
421 - $user_url
422 - );
413 + $confirm_url = add_query_arg( array(
414 + 'action' => 'bbp-update-user-email',
415 + 'newuseremail' => $r['hash']
416 + ), $user_url );
423 417
424 - /* translators: 1: Username, 2: Confirmation URL, 3: New email address, 4: Site name, 5: Site URL */
425 - $email_text = __(
426 - '%1$s
418 + $email_text = __( '%1$s
427 419
428 420 Someone requested a change to the email address on your account.
429 421
430 422 Please click the following link to confirm this change:
@@ -435,11 +427,9 @@
435 427 This email was sent to: %3$s
436 428
437 429 Regards,
438 430 The %4$s Team
439 -%5$s',
440 - 'bbpress'
441 - );
431 +%5$s', 'bbpress' );
442 432
443 433 /**
444 434 * Filter the email text sent when a user changes emails.
445 435 *
@@ -459,9 +449,8 @@
459 449 // Build the email message
460 450 $message = sprintf( $content, $user_login, $confirm_url, $r['newemail'], get_site_option( 'site_name' ), network_home_url() );
461 451
462 452 // Build the email subject
463 - /* translators: %s: Site name */
464 453 $subject = sprintf( __( '[%s] New Email Address', 'bbpress' ), wp_specialchars_decode( get_option( 'blogname' ) ) );
465 454
466 455 // Send the email
467 456 wp_mail( $r['newemail'], $subject, $message );
@@ -468,9 +457,9 @@
468 457 }
469 458
470 459 /**
471 460 * Conditionally hook the core WordPress output actions to the end of the
472 - * default user's edit profile template.
461 + * default user's edit profile template
473 462 *
474 463 * This allows clever plugin authors to conditionally unhook the WordPress core
475 464 * output actions if they don't want any unexpected junk to appear there, and
476 465 * also avoids needing to pollute the templates with additional logic and actions.
@@ -485,16 +474,16 @@
485 474
486 475 /** User Queries **************************************************************/
487 476
488 477 /**
489 - * Get the topics that a user created.
478 + * Get the topics that a user created
490 479 *
491 480 * @since 2.0.0 bbPress (r2660)
492 481 * @since 2.6.0 bbPress (r6618) Signature changed to accept an array of arguments
493 482 *
494 - * @param array $args Optional. Arguments to pass into bbp_has_topics().
483 + * @param array $args Optional. Arguments to pass into bbp_has_topics()
495 484 *
496 - * @return bool True if user has started topics, otherwise false.
485 + * @return bool True if user has started topics, otherwise false
497 486 */
498 487 function bbp_get_user_topics_started( $args = array() ) {
499 488
500 489 // Backwards compat for pre-2.6.0
@@ -520,16 +509,16 @@
520 509 return apply_filters( 'bbp_get_user_topics_started', $query, $user_id, $r, $args );
521 510 }
522 511
523 512 /**
524 - * Get the replies that a user created.
513 + * Get the replies that a user created
525 514 *
526 515 * @since 2.2.0 bbPress (r4225)
527 516 * @since 2.6.0 bbPress (r6618) Signature changed to accept an array of arguments
528 517 *
529 - * @param array $args Optional. Arguments to pass into bbp_has_replies().
518 + * @param array $args Optional. Arguments to pass into bbp_has_replies()
530 519 *
531 - * @return bool True if user has created replies, otherwise false.
520 + * @return bool True if user has created replies, otherwise false
532 521 */
533 522 function bbp_get_user_replies_created( $args = array() ) {
534 523
535 524 // Backwards compat for pre-2.6.0
@@ -559,11 +548,11 @@
559 548 return apply_filters( 'bbp_get_user_replies_created', $query, $user_id, $r, $args );
560 549 }
561 550
562 551 /**
563 - * Get user IDs from nicenames.
552 + * Get user IDs from nicenames
564 553 *
565 - * This function is primarily used when saving object moderators.
554 + * This function is primarily used when saving object moderators
566 555 *
567 556 * @since 2.6.0 bbPress
568 557 *
569 558 * @param mixed $user_nicenames
@@ -585,13 +574,11 @@
585 574 // Sanitize each nicename in the array
586 575 $user_nicenames = array_map( 'sanitize_title', $user_nicenames );
587 576
588 577 // Get users
589 - $users = get_users(
590 - array(
591 - 'nicename__in' => $user_nicenames
592 - )
593 - );
578 + $users = get_users( array(
579 + 'nicename__in' => $user_nicenames
580 + ) );
594 581
595 582 // Pluck or empty
596 583 if ( ! empty( $users ) ) {
597 584 $retval = wp_list_pluck( $users, 'ID' );
@@ -602,15 +589,15 @@
602 589 return (array) apply_filters( 'bbp_get_user_ids_from_nicenames', $retval, $user_nicenames );
603 590 }
604 591
605 592 /**
606 - * Get user nicenames from IDs.
593 + * Get user nicenames from IDs
607 594 *
608 - * This function is primarily used when saving object moderators.
595 + * This function is primarily used when saving object moderators
609 596 *
610 597 * @since 2.6.0 bbPress
611 598 *
612 - * @param mixed $user_ids User ids.
599 + * @param mixed $user_ids
613 600 * @return array
614 601 */
615 602 function bbp_get_user_nicenames_from_ids( $user_ids = array() ) {
616 603
@@ -620,13 +607,11 @@
620 607 // Only query if nicenames
621 608 if ( ! empty( $user_ids ) ) {
622 609
623 610 // Get users
624 - $users = get_users(
625 - array(
626 - 'include' => $user_ids
627 - )
628 - );
611 + $users = get_users( array(
612 + 'include' => $user_ids
613 + ) );
629 614
630 615 // Pluck or empty
631 616 if ( ! empty( $users ) ) {
632 617 $retval = wp_list_pluck( $users, 'user_nicename' );
@@ -639,15 +624,15 @@
639 624
640 625 /** Post Counts ***************************************************************/
641 626
642 627 /**
643 - * Return the raw database count of topics by a user.
628 + * Return the raw database count of topics by a user
644 629 *
645 630 * @since 2.1.0 bbPress (r3633)
646 631 *
647 - * @param int $user_id User ID to get count for.
632 + * @param int $user_id User ID to get count for
648 633 *
649 - * @return int Raw DB count of topics.
634 + * @return int Raw DB count of topics
650 635 */
651 636 function bbp_get_user_topic_count_raw( $user_id = 0 ) {
652 637 $user_id = bbp_get_user_id( $user_id );
653 638 $bbp_db = bbp_db();
@@ -665,15 +650,15 @@
665 650 return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id );
666 651 }
667 652
668 653 /**
669 - * Return the raw database count of replies by a user.
654 + * Return the raw database count of replies by a user
670 655 *
671 656 * @since 2.1.0 bbPress (r3633)
672 657 *
673 - * @param int $user_id User ID to get count for.
658 + * @param int $user_id User ID to get count for
674 659 *
675 - * @return int Raw DB count of replies.
660 + * @return int Raw DB count of replies
676 661 */
677 662 function bbp_get_user_reply_count_raw( $user_id = 0 ) {
678 663 $user_id = bbp_get_user_id( $user_id );
679 664 $bbp_db = bbp_db();
@@ -695,10 +680,10 @@
695 680 * Bump the topic count for a user by a certain amount.
696 681 *
697 682 * @since 2.6.0 bbPress (r5309)
698 683 *
699 - * @param int $user_id User id.
700 - * @param int $difference Optional. Default 1. Number to bump.
684 + * @param int $user_id
685 + * @param int $difference
701 686 */
702 687 function bbp_bump_user_topic_count( $user_id = 0, $difference = 1 ) {
703 688
704 689 // Bail if no bump
@@ -731,10 +716,10 @@
731 716 * Bump the reply count for a user by a certain amount.
732 717 *
733 718 * @since 2.6.0 bbPress (r5309)
734 719 *
735 - * @param int $user_id User id.
736 - * @param int $difference Optional. Default 1. Number to bump.
720 + * @param int $user_id
721 + * @param int $difference
737 722 */
738 723 function bbp_bump_user_reply_count( $user_id = 0, $difference = 1 ) {
739 724
740 725 // Bail if no bump
@@ -783,9 +768,9 @@
783 768 /**
784 769 * Helper function used to increase (by one) the count of replies for a user when
785 770 * a reply is published.
786 771 *
787 - * This is a helper function, hooked to `bbp_new_reply`.
772 + * This is a helper function, hooked to `bbp_new_reply`
788 773 *
789 774 * @since 2.6.0 bbPress (r5309)
790 775 *
791 776 * @param $topic_id
@@ -826,9 +811,9 @@
826 811
827 812 /** Permissions ***************************************************************/
828 813
829 814 /**
830 - * Redirect if unauthorized user is attempting to edit another user.
815 + * Redirect if unauthorized user is attempting to edit another user
831 816 *
832 817 * This is hooked to 'bbp_template_redirect' and controls the conditions under
833 818 * which a user can edit another user (or themselves.) If these conditions are
834 819 * met, we assume a user cannot perform this task, and look for ways they can
@@ -968,60 +953,36 @@
968 953 /**
969 954 * Convert passwords from previous platform encryption to WordPress encryption.
970 955 *
971 956 * @since 2.1.0 bbPress (r3813)
972 - * @since 2.6.10 bbPress (r7244) Switched from direct query to get_user_by()
973 957 */
974 958 function bbp_user_maybe_convert_pass() {
975 959
976 - // Sanitize login
977 - $login = ! empty( $_POST['log'] )
978 - ? sanitize_user( wp_unslash( $_POST['log'] ) )
960 + // Sanitize username
961 + $username = ! empty( $_POST['log'] )
962 + ? sanitize_user( $_POST['log'] )
979 963 : '';
980 964
981 - // Sanitize password
982 - $pass = ! empty( $_POST['pwd'] )
983 - ? trim( $_POST['pwd'] )
984 - : '';
985 -
986 - // Bail if no username or password
987 - if ( empty( $login ) || empty( $pass ) ) {
965 + // Bail if no username
966 + if ( empty( $username ) ) {
988 967 return;
989 968 }
990 969
991 - // Get user by login...
992 - $user = get_user_by( 'login', $login );
993 -
994 - // ...or get user by email
995 - if ( empty( $user ) && strpos( $login, '@' ) ) {
996 - $user = get_user_by( 'email', $login );
997 - }
998 -
999 - // Bail if no user
1000 - if ( empty( $user ) ) {
970 + // Bail if no user password to convert
971 + $bbp_db = bbp_db();
972 + $query = $bbp_db->prepare( "SELECT * FROM {$bbp_db->users} INNER JOIN {$bbp_db->usermeta} ON user_id = ID WHERE meta_key = %s AND user_login = %s LIMIT 1", '_bbp_class', $username );
973 + $row = $bbp_db->get_row( $query );
974 + if ( empty( $row ) || is_wp_error( $row ) ) {
1001 975 return;
1002 976 }
1003 977
1004 - // Get converter class from usermeta
1005 - $class = get_user_meta( $user->ID, '_bbp_class', true );
1006 -
1007 - // Bail if no converter class in meta
1008 - if ( empty( $class ) || ! is_string( $class ) ) {
1009 - return;
1010 - }
1011 -
1012 978 // Setup the converter
1013 979 bbp_setup_converter();
1014 980
1015 - // Try to instantiate the converter class
1016 - $converter = bbp_new_converter( $class );
981 + // Try to convert the old password for this user
982 + $converter = bbp_new_converter( $row->meta_value );
1017 983
1018 - // Bail if no converter
1019 - if ( empty( $converter ) ) {
1020 - return;
1021 - }
1022 -
1023 - // Try to call the password conversion callback method
984 + // Try to call the conversion method
1024 985 if ( ( $converter instanceof BBP_Converter_Base ) && method_exists( $converter, 'callback_pass' ) ) {
1025 - $converter->callback_pass( $login, $pass );
986 + $converter->callback_pass( $username, $_POST['pwd'] );
1026 987 }
1027 988 }