Changeset 13092 for trunk/src/bp-friends/bp-friends-functions.php
- Timestamp:
- 08/24/2021 04:16:17 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/bp-friends-functions.php
r13086 r13092 34 34 35 35 // You cannot be friends with yourself! 36 if ( $initiator_userid == $friend_userid ) {36 if ( $initiator_userid === $friend_userid ) { 37 37 return false; 38 38 } … … 78 78 * @since 1.0.0 79 79 * 80 * @param int $id ID of the pending friendship connection.81 * @param int $initiator_user_id ID of the friendship initiator.82 * @param int $friend_user_id ID of the friend user.83 * @param object $friendship BuddyPress Friendship Object.80 * @param int $id ID of the pending friendship connection. 81 * @param int $initiator_user_id ID of the friendship initiator. 82 * @param int $friend_user_id ID of the friend user. 83 * @param BP_Friends_Friendship $friendship The friendship object. 84 84 */ 85 85 do_action( 'friends_friendship_' . $action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship ); … … 175 175 * @since 1.0.0 176 176 * 177 * @param int $id ID of the pending friendship object.178 * @param int $initiator_user_id ID of the friendship initiator.179 * @param int $friend_user_id ID of the user requested friendship with.180 * @param object $friendship BuddyPress Friendship Object.177 * @param int $id ID of the pending friendship object. 178 * @param int $initiator_user_id ID of the friendship initiator. 179 * @param int $friend_user_id ID of the user requested friendship with. 180 * @param BP_Friends_Friendship $friendship The friendship object. 181 181 */ 182 182 do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship ); … … 206 206 * @since 1.0.0 207 207 * 208 * @param int $friendship_id ID of the pendingfriendship.209 * @param BP_Friends_Friendship $friendship s Friendship object. Passed by reference.208 * @param int $friendship_id ID of the friendship. 209 * @param BP_Friends_Friendship $friendship The friendship object. Passed by reference. 210 210 */ 211 211 do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) ); 212 212 213 return true; 213 214 } … … 241 242 * 242 243 * @param int $friendship_id ID of the friendship. 243 * @param BP_Friends_Friendship $friendship Friendship object. Passed by reference.244 * @param BP_Friends_Friendship $friendship The friendship object. Passed by reference. 244 245 */ 245 do_action_ref_array( 'friends_friendship_withdrawn', 246 do_action_ref_array( 'friends_friendship_withdrawn', array( $friendship_id, &$friendship ) ); 246 247 247 248 return true; … … 261 262 */ 262 263 function friends_check_friendship( $user_id, $possible_friend_id ) { 263 264 if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) ) 265 return true; 266 267 return false; 264 return ( 'is_friend' === BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) ); 268 265 } 269 266 … … 274 271 * 275 272 * @since 1.2.0 273 * 274 * @global object $friends_template 276 275 * 277 276 * @param int $user_id ID of the first user. … … 302 301 */ 303 302 function friends_get_total_friend_count( $user_id = 0 ) { 304 if ( empty( $user_id ) ) 303 if ( empty( $user_id ) ) { 305 304 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 305 } 306 306 307 307 $count = bp_get_user_meta( $user_id, 'total_friend_count', true ); 308 if ( empty( $count ) ) 308 if ( empty( $count ) ) { 309 309 $count = 0; 310 } 310 311 311 312 /** … … 316 317 * @param int $count Total friend count for a given user. 317 318 */ 318 return apply_filters( 'friends_get_total_friend_count', $count );319 return apply_filters( 'friends_get_total_friend_count', (int) $count ); 319 320 } 320 321 … … 330 331 $friend_count = friends_get_total_friend_count( $user_id ); 331 332 332 if ( empty( $friend_count ) ) 333 if ( empty( $friend_count ) ) { 333 334 return false; 334 335 if ( !(int) $friend_count ) 335 } 336 337 if ( ! (int) $friend_count ) { 336 338 return false; 339 } 337 340 338 341 return true; … … 346 349 * @param int $initiator_user_id ID of the first user. 347 350 * @param int $friend_user_id ID of the second user. 348 * @return int|null ID of the friendship if found, otherwise false.351 * @return int|null ID of the friendship if found, otherwise null. 349 352 */ 350 353 function friends_get_friendship_id( $initiator_user_id, $friend_user_id ) { … … 407 410 * @since 1.0.0 408 411 * 409 * @see BP_Core_User::get_users() for a description of return value.412 * @see bp_core_get_users() for a description of return value. 410 413 * 411 414 * @param int $user_id ID of the user whose friends are being retrieved. … … 445 448 * @since 1.0.0 446 449 * 447 * @see BP_Core_User::get_users() for a description of return value.450 * @see bp_core_get_users() for a description of return value. 448 451 * 449 452 * @param int $user_id ID of the user whose friends are being retrieved. … … 483 486 * @since 1.0.0 484 487 * 485 * @see BP_Core_User::get_users() for a description of return value.488 * @see bp_core_get_users() for a description of return value. 486 489 * 487 490 * @param int $user_id ID of the user whose friends are being retrieved. … … 525 528 * 526 529 * @param array $friend_ids See BP_Friends_Friendship::get_bulk_last_active(). 527 * @return array $user_idsSee BP_Friends_Friendship::get_bulk_last_active().530 * @return array See BP_Friends_Friendship::get_bulk_last_active(). 528 531 */ 529 532 function friends_get_bulk_last_active( $friend_ids ) { … … 547 550 548 551 // Default to logged in user id. 549 if ( empty( $user_id ) ) 552 if ( empty( $user_id ) ) { 550 553 $user_id = bp_loggedin_user_id(); 554 } 551 555 552 556 // Only group admins can invited previously banned users. … … 561 565 * @since 1.5.4 562 566 * 563 * @param array $value Array of default parameters for invite list. 567 * @param array $value { 568 * @type int $user_id User ID whose friends too see can be invited. 569 * @type string $type Type of order to return a list of members. 570 * @type int $per_page Number of friends per page. 571 * } 564 572 */ 565 $args = apply_filters( 'bp_friends_pre_get_invite_list', array( 566 'user_id' => $user_id, 567 'type' => 'alphabetical', 568 'per_page' => 0 569 ) ); 573 $args = apply_filters( 574 'bp_friends_pre_get_invite_list', 575 array( 576 'user_id' => $user_id, 577 'type' => 'alphabetical', 578 'per_page' => 0, 579 ) 580 ); 570 581 571 582 // User has friends. … … 589 600 590 601 // Skip friend if already in the group. 591 if ( groups_is_user_member( $friend_user_id, $group_id ) ) 602 if ( groups_is_user_member( $friend_user_id, $group_id ) ) { 592 603 continue; 604 } 593 605 594 606 // Skip friend if not group admin and user banned from group. 595 if ( ( false === $user_is_admin ) && groups_is_user_banned( $friend_user_id, $group_id ) ) 607 if ( ( false === $user_is_admin ) && groups_is_user_banned( $friend_user_id, $group_id ) ) { 596 608 continue; 609 } 597 610 598 611 // Friend is safe, so add it to the array of possible friends. 599 612 $friends[] = array( 600 613 'id' => $friend_user_id, 601 'full_name' => bp_get_member_name() 614 'full_name' => bp_get_member_name(), 602 615 ); 603 616 … … 606 619 607 620 // If no friends, explicitly set to false. 608 if ( empty( $friends ) ) 621 if ( empty( $friends ) ) { 609 622 $friends = false; 623 } 610 624 611 625 /** … … 634 648 * @param int $user_id ID of the user whose friends are being counted. 635 649 * @param int $group_id ID of the group friends are being invited to. 636 * @return int $invitable_countEligible friend count.650 * @return int Eligible friend count. 637 651 */ 638 652 function friends_count_invitable_friends( $user_id, $group_id ) { … … 667 681 */ 668 682 function friends_search_users( $search_terms, $user_id, $pag_num = 0, $pag_page = 0 ) { 669 670 683 $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page ); 671 684 672 if ( empty( $user_ids ) ) 685 if ( empty( $user_ids ) ) { 673 686 return false; 687 } 674 688 675 689 $users = array(); 676 for ( $i = 0, $count = count( $user_ids ); $i < $count; ++$i ) 677 $users[] = new BP_Core_User( $user_ids[$i] ); 678 679 return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count( $search_terms ) ); 690 for ( $i = 0, $count = count( $user_ids ); $i < $count; ++$i ) { 691 $users[] = new BP_Core_User( $user_ids[ $i ] ); 692 } 693 694 return array( 695 'users' => $users, 696 'count' => BP_Friends_Friendship::search_users_count( $search_terms ), 697 ); 680 698 } 681 699 … … 690 708 function friends_is_friendship_confirmed( $friendship_id ) { 691 709 $friendship = new BP_Friends_Friendship( $friendship_id ); 692 return $friendship->is_confirmed;710 return (bool) $friendship->is_confirmed; 693 711 } 694 712 … … 709 727 */ 710 728 function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) { 711 712 if ( 'add' == $status ) { 713 bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int)bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 ); 714 bp_update_user_meta( $friend_user_id, 'total_friend_count', (int)bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) + 1 ); 729 if ( 'add' === $status ) { 730 bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int) bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 ); 731 bp_update_user_meta( $friend_user_id, 'total_friend_count', (int) bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) + 1 ); 715 732 } else { 716 bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int) bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) - 1 );717 bp_update_user_meta( $friend_user_id, 'total_friend_count', (int) bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) - 1 );733 bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int) bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) - 1 ); 734 bp_update_user_meta( $friend_user_id, 'total_friend_count', (int) bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) - 1 ); 718 735 } 719 736 } … … 757 774 do_action( 'friends_remove_data', $user_id ); 758 775 } 759 add_action( 'wpmu_delete_user', 776 add_action( 'wpmu_delete_user', 'friends_remove_data' ); 760 777 add_action( 'bp_make_spam_user', 'friends_remove_data' ); 761 778 … … 806 823 807 824 $friends_query = array( 808 'count_total' => '', 825 'count_total' => '', // Prevents total count. 809 826 'populate_extras' => false, 810 811 827 'type' => 'alphabetical', 812 828 'user_id' => get_current_user_id(), … … 851 867 */ 852 868 function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) { 853 if ( 'no' == bp_get_user_meta( (int) $friend_id, 'notification_friends_friendship_request', true ) ) {869 if ( 'no' === bp_get_user_meta( (int) $friend_id, 'notification_friends_friendship_request', true ) ) { 854 870 return; 855 871 } … … 888 904 */ 889 905 function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) { 890 if ( 'no' == bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) {906 if ( 'no' === bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) { 891 907 return; 892 908 } … … 904 920 'friendship.id' => $friendship_id, 905 921 'initiator.id' => $initiator_id, 906 'unsubscribe' 922 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ), 907 923 ), 908 924 ); … … 921 937 */ 922 938 function bp_friends_personal_data_exporter( $email_address, $page ) { 923 $number = 50; 924 925 $email_address = trim( $email_address ); 926 939 $number = 50; 940 $email_address = trim( $email_address ); 927 941 $data_to_export = array(); 928 929 $user = get_user_by( 'email', $email_address ); 942 $user = get_user_by( 'email', $email_address ); 930 943 931 944 if ( ! $user ) { … … 941 954 'per_page' => $number, 942 955 ) ); 943 944 $user_data_to_export = array();945 956 946 957 foreach ( $friendships as $friendship ) { … … 995 1006 */ 996 1007 function bp_friends_pending_sent_requests_personal_data_exporter( $email_address, $page ) { 997 $number = 50; 998 999 $email_address = trim( $email_address ); 1000 1008 $number = 50; 1009 $email_address = trim( $email_address ); 1001 1010 $data_to_export = array(); 1002 1003 $user = get_user_by( 'email', $email_address ); 1011 $user = get_user_by( 'email', $email_address ); 1004 1012 1005 1013 if ( ! $user ) { … … 1016 1024 'per_page' => $number, 1017 1025 ) ); 1018 1019 $user_data_to_export = array();1020 1026 1021 1027 foreach ( $friendships as $friendship ) { … … 1058 1064 */ 1059 1065 function bp_friends_pending_received_requests_personal_data_exporter( $email_address, $page ) { 1060 $number = 50; 1061 1062 $email_address = trim( $email_address ); 1063 1066 $number = 50; 1067 $email_address = trim( $email_address ); 1064 1068 $data_to_export = array(); 1065 1066 $user = get_user_by( 'email', $email_address ); 1069 $user = get_user_by( 'email', $email_address ); 1067 1070 1068 1071 if ( ! $user ) { … … 1079 1082 'per_page' => $number, 1080 1083 ) ); 1081 1082 $user_data_to_export = array();1083 1084 1084 1085 foreach ( $friendships as $friendship ) {
Note: See TracChangeset
for help on using the changeset viewer.