Changeset 13092
- Timestamp:
- 08/24/2021 04:16:17 AM (3 years ago)
- Location:
- trunk/src/bp-friends
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/actions/add-friend.php
r11931 r13092 1 1 <?php 2 2 /** 3 * Friends: Add action 3 * Friends: Add action. 4 4 * 5 5 * @package BuddyPress … … 14 14 */ 15 15 function friends_action_add_friend() { 16 if ( ! bp_is_friends_component() || !bp_is_current_action( 'add-friend' ) )16 if ( ! bp_is_friends_component() || ! bp_is_current_action( 'add-friend' ) ) { 17 17 return false; 18 } 18 19 19 if ( !$potential_friend_id = (int)bp_action_variable( 0 ) ) 20 $potential_friend_id = (int) bp_action_variable( 0 ); 21 if ( ! $potential_friend_id ) { 20 22 return false; 23 } 21 24 22 if ( $potential_friend_id == bp_loggedin_user_id() )25 if ( bp_loggedin_user_id() === $potential_friend_id ) { 23 26 return false; 27 } 24 28 25 29 $friendship_status = BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $potential_friend_id ); 26 30 27 if ( 'not_friends' == $friendship_status ) {31 if ( 'not_friends' === $friendship_status ) { 28 32 29 if ( ! check_admin_referer( 'friends_add_friend' ) )33 if ( ! check_admin_referer( 'friends_add_friend' ) ) { 30 34 return false; 35 } 31 36 32 if ( ! friends_add_friend( bp_loggedin_user_id(), $potential_friend_id ) ) {37 if ( ! friends_add_friend( bp_loggedin_user_id(), $potential_friend_id ) ) { 33 38 bp_core_add_message( __( 'Friendship could not be requested.', 'buddypress' ), 'error' ); 34 39 } else { 35 40 bp_core_add_message( __( 'Friendship requested', 'buddypress' ) ); 36 41 } 37 38 } elseif ( 'is_friend' == $friendship_status ) { 42 } elseif ( 'is_friend' === $friendship_status ) { 39 43 bp_core_add_message( __( 'You are already friends with this user', 'buddypress' ), 'error' ); 40 44 } else { -
trunk/src/bp-friends/actions/remove-friend.php
r11931 r13092 1 1 <?php 2 2 /** 3 * Friends: Remove action 3 * Friends: Remove action. 4 4 * 5 5 * @package BuddyPress … … 14 14 */ 15 15 function friends_action_remove_friend() { 16 if ( ! bp_is_friends_component() || !bp_is_current_action( 'remove-friend' ) )16 if ( ! bp_is_friends_component() || ! bp_is_current_action( 'remove-friend' ) ) { 17 17 return false; 18 } 18 19 19 if ( !$potential_friend_id = (int)bp_action_variable( 0 ) ) 20 $potential_friend_id = (int) bp_action_variable( 0 ); 21 if ( ! $potential_friend_id ) { 20 22 return false; 23 } 21 24 22 if ( $potential_friend_id == bp_loggedin_user_id() )25 if ( bp_loggedin_user_id() === $potential_friend_id ) { 23 26 return false; 27 } 24 28 25 29 $friendship_status = BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $potential_friend_id ); 26 30 27 if ( 'is_friend' == $friendship_status ) {31 if ( 'is_friend' === $friendship_status ) { 28 32 29 if ( ! check_admin_referer( 'friends_remove_friend' ) )33 if ( ! check_admin_referer( 'friends_remove_friend' ) ) { 30 34 return false; 35 } 31 36 32 if ( ! friends_remove_friend( bp_loggedin_user_id(), $potential_friend_id ) ) {37 if ( ! friends_remove_friend( bp_loggedin_user_id(), $potential_friend_id ) ) { 33 38 bp_core_add_message( __( 'Friendship could not be canceled.', 'buddypress' ), 'error' ); 34 39 } else { 35 40 bp_core_add_message( __( 'Friendship canceled', 'buddypress' ) ); 36 41 } 37 38 } elseif ( 'not_friends' == $friendship_status ) { 42 } elseif ( 'not_friends' === $friendship_status ) { 39 43 bp_core_add_message( __( 'You are not yet friends with this user', 'buddypress' ), 'error' ); 40 44 } else { -
trunk/src/bp-friends/bp-friends-activity.php
r12602 r13092 50 50 'secondary_item_id' => false, 51 51 'recorded_time' => bp_core_current_time(), 52 'hide_sitewide' => false 52 'hide_sitewide' => false, 53 53 ) ); 54 54 … … 70 70 * @type int $user_id ID of the user associated with the activity item. 71 71 * } 72 * @return bool True on success, false on failure.73 72 */ 74 73 function friends_delete_activity( $args ) { … … 81 80 'item_id' => $args['item_id'], 82 81 'type' => $args['type'], 83 'user_id' => $args['user_id'] 82 'user_id' => $args['user_id'], 84 83 ) ); 85 84 } … … 89 88 * 90 89 * @since 1.1.0 90 * 91 * @return bool False if activity component is not active. 91 92 */ 92 93 function friends_register_activity_actions() { 93 94 94 if ( ! bp_is_active( 'activity' ) ) {95 if ( ! bp_is_active( 'activity' ) ) { 95 96 return false; 96 97 } … … 136 137 * @param string $action Activity action string. 137 138 * @param object $activity Activity data. 138 * @return string $actionFormatted activity action.139 * @return string Formatted activity action. 139 140 */ 140 141 function bp_friends_format_activity_action_friendship_accepted( $action, $activity ) { … … 171 172 * @param string $action Static activity action. 172 173 * @param object $activity Activity data. 173 * @return string $actionFormatted activity action.174 * @return string Formatted activity action. 174 175 */ 175 176 function bp_friends_format_activity_action_friendship_created( $action, $activity ) { … … 270 271 'column' => 'user_id', 271 272 'compare' => 'IN', 272 'value' => (array) $friends 273 'value' => (array) $friends, 273 274 ), 274 275 … … 276 277 array( 277 278 'column' => 'hide_sitewide', 278 'value' => 0 279 'value' => 0, 279 280 ), 280 281 … … 282 283 'override' => array( 283 284 'filter' => array( 'user_id' => 0 ), 284 'show_hidden' => true 285 'show_hidden' => true, 285 286 ), 286 287 ); … … 355 356 'value' => $user_id, 356 357 ), 357 ) 358 ), 358 359 ); 359 360 … … 373 374 * @since 1.9.0 374 375 * 375 * @param int $friendship_id ID of the friendship. 376 * @param int $initiator_user_id ID of friendship initiator. 377 * @param int $friend_user_id ID of user whose friendship is requested. 378 * @param object|bool $friendship Optional Friendship object. 379 */ 380 function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id, $friendship = false ) { 376 * @param int $friendship_id ID of the friendship. 377 * @param int $initiator_user_id ID of friendship initiator. 378 * @param int $friend_user_id ID of user whose friendship is requested. 379 */ 380 function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id ) { 381 381 if ( ! bp_is_active( 'activity' ) ) { 382 382 return; … … 388 388 'type' => 'friendship_created', 389 389 'item_id' => $friendship_id, 390 'secondary_item_id' => $friend_user_id 390 'secondary_item_id' => $friend_user_id, 391 391 ) ); 392 392 } 393 add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4);393 add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 3 ); 394 394 395 395 /** … … 405 405 } 406 406 407 bp_activity_delete( array( 408 'component' => buddypress()->friends->id, 409 'type' => 'friendship_created', 410 'secondary_item_id' => $user_id 411 ) ); 407 bp_activity_delete( 408 array( 409 'component' => buddypress()->friends->id, 410 'type' => 'friendship_created', 411 'secondary_item_id' => $user_id, 412 ) 413 ); 412 414 } 413 415 add_action( 'friends_remove_data', 'bp_friends_delete_activity_on_user_delete' ); … … 421 423 */ 422 424 function bp_friends_delete_activity_on_friendship_delete( $friendship_id ) { 423 friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_created', 'user_id' => 0 ) ); 425 friends_delete_activity( 426 array( 427 'item_id' => $friendship_id, 428 'type' => 'friendship_created', 429 'user_id' => 0, 430 ) 431 ); 424 432 } 425 433 add_action( 'friends_friendship_deleted', 'bp_friends_delete_activity_on_friendship_delete' ); -
trunk/src/bp-friends/bp-friends-blocks.php
r13004 r13092 9 9 10 10 // Exit if accessed directly. 11 if ( ! defined( 'ABSPATH' ) ) { 12 exit; 13 } 11 defined( 'ABSPATH' ) || exit; 14 12 15 13 /** -
trunk/src/bp-friends/bp-friends-cache.php
r11949 r13092 24 24 */ 25 25 function friends_clear_friend_object_cache( $friendship_id ) { 26 if ( !$friendship = new BP_Friends_Friendship( $friendship_id ) ) 26 $friendship = new BP_Friends_Friendship( $friendship_id ); 27 if ( ! $friendship ) { 27 28 return false; 29 } 28 30 29 wp_cache_delete( 'friends_friend_ids_' . 30 wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id,'bp' );31 wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' ); 32 wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' ); 31 33 } 32 34 33 35 // List actions to clear object caches on. 34 36 add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' ); 35 add_action( 'friends_friendship_deleted', 37 add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' ); 36 38 37 39 /** … … 43 45 * @param int $initiator_user_id ID of the first user. 44 46 * @param int $friend_user_id ID of the second user. 45 * @return bool46 47 */ 47 48 function bp_friends_clear_bp_friends_friendships_cache( $friendship_id, $initiator_user_id, $friend_user_id ) { 48 49 // Clear friendship ID cache for each user. 49 50 wp_cache_delete( $initiator_user_id, 'bp_friends_friendships_for_user' ); 50 wp_cache_delete( $friend_user_id, 51 wp_cache_delete( $friend_user_id, 'bp_friends_friendships_for_user' ); 51 52 52 53 // Clear the friendship object cache. … … 60 61 } 61 62 add_action( 'friends_friendship_requested', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 ); 62 add_action( 'friends_friendship_accepted', 63 add_action( 'friends_friendship_deleted', 63 add_action( 'friends_friendship_accepted', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 ); 64 add_action( 'friends_friendship_deleted', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 ); 64 65 65 66 /** … … 69 70 * 70 71 * @param int $friendship_id The friendship ID. 71 * @param BP_Friends_Friendship $friendship Friendship object.72 * @param BP_Friends_Friendship $friendship The friendship object. 72 73 */ 73 function bp_friends_clear_bp_friends_friendships_cache_remove( $friendship_id, BP_Friends_Friendship$friendship ) {74 function bp_friends_clear_bp_friends_friendships_cache_remove( $friendship_id, $friendship ) { 74 75 // Clear friendship ID cache for each user. 75 76 wp_cache_delete( $friendship->initiator_user_id, 'bp_friends_friendships_for_user' ); 76 wp_cache_delete( $friendship->friend_user_id, 77 wp_cache_delete( $friendship->friend_user_id, 'bp_friends_friendships_for_user' ); 77 78 78 79 // Clear the friendship object cache. … … 83 84 } 84 85 add_action( 'friends_friendship_withdrawn', 'bp_friends_clear_bp_friends_friendships_cache_remove', 10, 2 ); 85 add_action( 'friends_friendship_rejected', 86 add_action( 'friends_friendship_rejected', 'bp_friends_clear_bp_friends_friendships_cache_remove', 10, 2 ); 86 87 87 88 /** … … 111 112 } 112 113 add_action( 'friends_friendship_requested', 'bp_friends_clear_request_cache_on_save', 10, 3 ); 113 add_action( 'friends_friendship_accepted', 114 add_action( 'friends_friendship_accepted', 'bp_friends_clear_request_cache_on_save', 10, 3 ); 114 115 115 116 /** … … 121 122 * 122 123 * @param int $friendship_id The friendship ID. 123 * @param BP_Friends_Friendship $friendship Friendship object.124 * @param BP_Friends_Friendship $friendship The friendship object. 124 125 */ 125 function bp_friends_clear_request_cache_on_remove( $friendship_id, BP_Friends_Friendship$friendship ) {126 function bp_friends_clear_request_cache_on_remove( $friendship_id, $friendship ) { 126 127 bp_friends_clear_request_cache( $friendship->friend_user_id ); 127 128 } 128 129 add_action( 'friends_friendship_withdrawn', 'bp_friends_clear_request_cache_on_remove', 10, 2 ); 129 add_action( 'friends_friendship_rejected', 130 add_action( 'friends_friendship_rejected', 'bp_friends_clear_request_cache_on_remove', 10, 2 ); 130 131 131 132 /** … … 134 135 * @since 3.0.0 135 136 * 136 * @param BP_Friends_Friendship $friendship Friendship object.137 * @param BP_Friends_Friendship $friendship The friendship object. 137 138 */ 138 139 function bp_friends_delete_cached_friendships_on_friendship_save( $friendship ) { -
trunk/src/bp-friends/bp-friends-cssjs.php
r13002 r13092 9 9 10 10 // Exit if accessed directly. 11 if ( ! defined( 'ABSPATH' ) ) { 12 exit; 13 } 11 defined( 'ABSPATH' ) || exit; 14 12 15 13 /** -
trunk/src/bp-friends/bp-friends-filters.php
r12670 r13092 13 13 // Format numerical output. 14 14 add_filter( 'friends_get_total_friend_count', 'bp_core_number_format' ); 15 add_filter( 'bp_get_total_friend_count', 15 add_filter( 'bp_get_total_friend_count', 'bp_core_number_format' ); 16 16 17 17 /** … … 23 23 * @since 1.7.0 24 24 * 25 * @global WPDB $wpdb WordPress database access object.26 *27 25 * @param BP_User_Query $user_query The BP_User_Query object. 28 26 * @param string $user_ids_sql Comma-separated list of user IDs to fetch extra 29 27 * data for, as determined by BP_User_Query. 30 28 */ 31 function bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) { 32 global $wpdb; 29 function bp_friends_filter_user_query_populate_extras( $user_query, $user_ids_sql ) { 33 30 34 31 // Stop if user isn't logged in. 35 if ( ! $user_id = bp_loggedin_user_id() ) { 32 $user_id = bp_loggedin_user_id(); 33 if ( ! $user_id ) { 36 34 return; 37 35 } … … 45 43 $status = BP_Friends_Friendship::check_is_friend( $user_id, $friend_id ); 46 44 $user_query->results[ $friend_id ]->friendship_status = $status; 47 if ( 'is_friend' == $status ) {45 if ( 'is_friend' === $status ) { 48 46 $user_query->results[ $friend_id ]->is_friend = 1; 49 47 } 50 48 } 51 52 49 } 53 50 add_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 ); -
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 ) { -
trunk/src/bp-friends/bp-friends-loader.php
r11360 r13092 6 6 * 7 7 * @package BuddyPress 8 * @subpackage Friends 8 * @subpackage FriendsLoader 9 9 * @since 1.5.0 10 10 */ -
trunk/src/bp-friends/bp-friends-notifications.php
r12597 r13092 44 44 } else { 45 45 /* translators: %s: friend name */ 46 $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), 46 $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 47 47 $amount = 'single'; 48 48 } … … 62 62 } else { 63 63 /* translators: %s: friend name */ 64 $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), 64 $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 65 65 $amount = 'single'; 66 66 } … … 70 70 71 71 // Return either an HTML link or an array, depending on the requested format. 72 if ( 'string' == $format ) {72 if ( 'string' === $format ) { 73 73 74 74 /** … … 177 177 * @since 1.9.0 178 178 * 179 * @param int $friendship_id Friendship ID (not used).180 * @param object $friendship Friendship object.179 * @param int $friendship_id Friendship ID (not used). 180 * @param BP_Friends_Friendship $friendship The friendship object. 181 181 */ 182 182 function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) { … … 216 216 * @since 1.9.0 217 217 * 218 * @param int $friendship_id Friendship ID (not used).219 * @param object $friendship Friendship Object.218 * @param int $friendship_id Friendship ID (not used). 219 * @param BP_Friends_Friendship $friendship The friendship object. 220 220 */ 221 221 function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) { … … 243 243 function friends_screen_notification_settings() { 244 244 245 if ( !$send_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_request', true ) ) 246 $send_requests = 'yes'; 247 248 if ( !$accept_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_accepted', true ) ) 245 if ( ! $send_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_request', true ) ) { 246 $send_requests = 'yes'; 247 } 248 249 if ( ! $accept_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_accepted', true ) ) 249 250 $accept_requests = 'yes'; ?> 250 251 … … 253 254 <tr> 254 255 <th class="icon"></th> 255 <th class="title"><?php _ex( 'Friends', 'Friend settings on notification settings page', 'buddypress' ) ?></th>256 <th class="yes"><?php _e( 'Yes', 'buddypress' )?></th>257 <th class="no"><?php _e( 'No', 'buddypress' )?></th>256 <th class="title"><?php _ex( 'Friends', 'Friend settings on notification settings page', 'buddypress' ); ?></th> 257 <th class="yes"><?php esc_html_e( 'Yes', 'buddypress' ); ?></th> 258 <th class="no"><?php esc_html_e( 'No', 'buddypress' ); ?></th> 258 259 </tr> 259 260 </thead> … … 262 263 <tr id="friends-notification-settings-request"> 263 264 <td></td> 264 <td><?php _ex( 'A member sends you a friendship request', 'Friend settings on notification settings page', 'buddypress' ) ?></td>265 <td><?php _ex( 'A member sends you a friendship request', 'Friend settings on notification settings page', 'buddypress' ); ?></td> 265 266 <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_request]" id="notification-friends-friendship-request-yes" value="yes" <?php checked( $send_requests, 'yes', true ) ?>/><label for="notification-friends-friendship-request-yes" class="bp-screen-reader-text"><?php 266 267 /* translators: accessibility text */ 267 _e( 'Yes, send email', 'buddypress' );268 esc_html_e( 'Yes, send email', 'buddypress' ); 268 269 ?></label></td> 269 270 <td class="no"><input type="radio" name="notifications[notification_friends_friendship_request]" id="notification-friends-friendship-request-no" value="no" <?php checked( $send_requests, 'no', true ) ?>/><label for="notification-friends-friendship-request-no" class="bp-screen-reader-text"><?php 270 271 /* translators: accessibility text */ 271 _e( 'No, do not send email', 'buddypress' );272 esc_html_e( 'No, do not send email', 'buddypress' ); 272 273 ?></label></td> 273 274 </tr> … … 277 278 <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_accepted]" id="notification-friends-friendship-accepted-yes" value="yes" <?php checked( $accept_requests, 'yes', true ) ?>/><label for="notification-friends-friendship-accepted-yes" class="bp-screen-reader-text"><?php 278 279 /* translators: accessibility text */ 279 _e( 'Yes, send email', 'buddypress' );280 esc_html_e( 'Yes, send email', 'buddypress' ); 280 281 ?></label></td> 281 282 <td class="no"><input type="radio" name="notifications[notification_friends_friendship_accepted]" id="notification-friends-friendship-accepted-no" value="no" <?php checked( $accept_requests, 'no', true ) ?>/><label for="notification-friends-friendship-accepted-no" class="bp-screen-reader-text"><?php 282 283 /* translators: accessibility text */ 283 _e( 'No, do not send email', 'buddypress' );284 esc_html_e( 'No, do not send email', 'buddypress' ); 284 285 ?></label></td> 285 286 </tr> -
trunk/src/bp-friends/bp-friends-template.php
r12670 r13092 15 15 * 16 16 * @since 1.5.0 17 *18 17 */ 19 18 function bp_friends_slug() { … … 43 42 * 44 43 * @since 1.5.0 45 *46 44 */ 47 45 function bp_friends_root_slug() { … … 246 244 * Return value is a string of the form "x friends". 247 245 * 246 * @global object $members_template 247 * 248 248 * @since 1.2.0 249 249 * … … 296 296 global $friends_template; 297 297 298 if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) ) 298 if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) ) { 299 299 $user_id = $friends_template->friendship->friend->id; 300 elseif ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) )300 } elseif ( empty( $user_id ) && ! isset( $friends_template->friendship->friend ) ) { 301 301 $user_id = bp_displayed_user_id(); 302 } 302 303 303 304 /** … … 320 321 * @param int $user_id ID of the potential friend. Default: the value of 321 322 * {@link bp_get_potential_friend_id()}. 322 * @return string 'is_friend', 'not_friends', or 'pending'.323 * @return bool|string 'is_friend', 'not_friends', or 'pending'. 323 324 */ 324 325 function bp_is_friend( $user_id = 0 ) { 325 326 326 if ( ! is_user_logged_in() )327 if ( ! is_user_logged_in() ) { 327 328 return false; 328 329 if ( empty( $user_id ) ) 329 } 330 331 if ( empty( $user_id ) ) { 330 332 $user_id = bp_get_potential_friend_id( $user_id ); 331 332 if ( bp_loggedin_user_id() == $user_id ) 333 } 334 335 if ( bp_loggedin_user_id() === $user_id ) { 333 336 return false; 337 } 334 338 335 339 /** … … 338 342 * @since 1.2.10 339 343 * 340 * @param string $value String status of friendship. Possible values are 'is_friend', 'not_friends', 'pending'. 344 * @param string $value String status of friendship. Possible values are 'is_friend', 'not_friends', 'pending'. 345 * @param int $user_id ID of the potential friend. 341 346 */ 342 347 return apply_filters( 'bp_is_friend', friends_check_friendship_status( bp_loggedin_user_id(), $user_id ), $user_id ); … … 364 369 * applies. Default: value of {@link bp_get_potential_friend_id()}. 365 370 * @param bool $friend_status Not currently used. 366 * @return false|string HTML for the Add Friend button.371 * @return bool|string HTML for the Add Friend button. False if already friends. 367 372 */ 368 373 function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) { 369 374 370 if ( empty( $potential_friend_id ) ) 375 if ( empty( $potential_friend_id ) ) { 371 376 $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id ); 377 } 372 378 373 379 $is_friend = bp_is_friend( $potential_friend_id ); 374 380 375 if ( empty( $is_friend ) ) 381 if ( empty( $is_friend ) ) { 376 382 return false; 383 } 377 384 378 385 switch ( $is_friend ) { 379 case 'pending' 386 case 'pending': 380 387 $button = array( 381 388 'id' => 'pending', … … 389 396 'link_id' => 'friend-' . $potential_friend_id, 390 397 'link_rel' => 'remove', 391 'link_class' => 'friendship-button pending_friend requested' 398 'link_class' => 'friendship-button pending_friend requested', 392 399 ); 393 400 break; 394 401 395 case 'awaiting_response' 402 case 'awaiting_response': 396 403 $button = array( 397 404 'id' => 'awaiting_response', … … 405 412 'link_id' => 'friend-' . $potential_friend_id, 406 413 'link_rel' => 'remove', 407 'link_class' => 'friendship-button awaiting_response_friend requested' 414 'link_class' => 'friendship-button awaiting_response_friend requested', 408 415 ); 409 416 break; 410 417 411 case 'is_friend' 418 case 'is_friend': 412 419 $button = array( 413 420 'id' => 'is_friend', … … 421 428 'link_id' => 'friend-' . $potential_friend_id, 422 429 'link_rel' => 'remove', 423 'link_class' => 'friendship-button is_friend remove' 430 'link_class' => 'friendship-button is_friend remove', 424 431 ); 425 432 break; … … 437 444 'link_id' => 'friend-' . $potential_friend_id, 438 445 'link_rel' => 'add', 439 'link_class' => 'friendship-button not_friends add' 446 'link_class' => 'friendship-button not_friends add', 440 447 ); 441 448 break; … … 459 466 * @param int $user_id Optional. Default: the displayed user's ID, or the 460 467 * logged-in user's ID. 461 * @return false|string A comma-separated list of friend IDs if any are found,468 * @return bool|string A comma-separated list of friend IDs if any are found, 462 469 * otherwise false. 463 470 */ 464 471 function bp_get_friend_ids( $user_id = 0 ) { 465 472 466 if ( empty( $user_id ) ) 473 if ( empty( $user_id ) ) { 467 474 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 475 } 468 476 469 477 $friend_ids = friends_get_friend_user_ids( $user_id ); 470 478 471 if ( empty( $friend_ids ) ) 479 if ( empty( $friend_ids ) ) { 472 480 return false; 481 } 473 482 474 483 return implode( ',', friends_get_friend_user_ids( $user_id ) ); … … 488 497 */ 489 498 function bp_get_friendship_requests( $user_id = 0 ) { 490 if ( ! $user_id ) {499 if ( ! $user_id ) { 491 500 $user_id = bp_displayed_user_id(); 492 501 } 493 502 494 if ( ! $user_id ) {503 if ( ! $user_id ) { 495 504 return 0; 496 505 } … … 498 507 $requests = friends_get_friendship_request_user_ids( $user_id ); 499 508 500 if ( ! empty( $requests ) ) {509 if ( ! empty( $requests ) ) { 501 510 $requests = implode( ',', (array) $requests ); 502 511 } else { … … 529 538 * @since 1.2.0 530 539 * 540 * @global object $members_template 541 * 531 542 * @return int ID of the friendship. 532 543 */ … … 562 573 * @since 1.0.0 563 574 * 575 * @global object $members_template 576 * 564 577 * @return string accept-friendship URL. 565 578 */ … … 597 610 * @since 1.0.0 598 611 * 612 * @global object $members_template 613 * 599 614 * @return string reject-friendship URL. 600 615 */ … … 656 671 * @since 1.2.0 657 672 * 658 * @see bp_friend_get_total_requests_count() for description of arguments. 659 * 660 * @param int $user_id See {@link bp_friend_get_total_requests_count(). 673 * @param int $user_id ID of the user whose requests are being counted. 674 * Default: ID of the logged-in user. 661 675 */ 662 676 function bp_friend_total_requests_count( $user_id = 0 ) { … … 673 687 */ 674 688 function bp_friend_get_total_requests_count( $user_id = 0 ) { 675 if ( empty( $user_id ) ) 689 if ( empty( $user_id ) ) { 676 690 $user_id = bp_loggedin_user_id(); 691 } 677 692 678 693 /** -
trunk/src/bp-friends/bp-friends-widgets.php
r11381 r13092 4 4 * 5 5 * @package BuddyPress 6 * @subpackage Friends 6 * @subpackage FriendsWidgets 7 7 * @since 1.9.0 8 8 */ … … 28 28 } 29 29 30 add_action( 'widgets_init', function() { register_widget( 'BP_Core_Friends_Widget' ); } ); 30 add_action( 31 'widgets_init', 32 function() { 33 register_widget( 'BP_Core_Friends_Widget' ); 34 } 35 ); 31 36 } 32 37 add_action( 'bp_register_widgets', 'bp_friends_register_widgets' ); … … 87 92 <?php else: ?> 88 93 <?php echo "-1[[SPLIT]]<li>"; ?> 89 <?php _e( 'There were no members found, please try another filter.', 'buddypress' ); ?>94 <?php esc_html_e( 'There were no members found, please try another filter.', 'buddypress' ); ?> 90 95 <?php echo "</li>"; ?> 91 96 <?php endif; -
trunk/src/bp-friends/classes/class-bp-core-friends-widget.php
r12997 r13092 4 4 * 5 5 * @package BuddyPress 6 * @subpackage Friends 6 * @subpackage FriendsWidget 7 7 * @since 1.9.0 8 8 */ … … 24 24 * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options. 25 25 */ 26 function __construct() {26 public function __construct() { 27 27 $widget_ops = array( 28 28 'description' => __( 'A dynamic list of recently active, popular, and newest Friends of the displayed member. Widget is only shown when viewing a member profile.', 'buddypress' ), … … 53 53 * @since 1.9.0 54 54 * 55 * @global object $members_template 56 * 55 57 * @param array $args Widget arguments. 56 58 * @param array $instance The widget settings, as saved by the user. 57 59 */ 58 function widget( $args, $instance ) {60 public function widget( $args, $instance ) { 59 61 global $members_template; 60 62 … … 65 67 } 66 68 67 $user_id = bp_displayed_user_id();68 $link = trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() );69 $user_id = bp_displayed_user_id(); 70 $link = trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() ); 69 71 $instance['title'] = sprintf( __( "%s's Friends", 'buddypress' ), bp_get_displayed_user_fullname() ); 70 72 … … 159 161 * @return array $instance The processed settings to save. 160 162 */ 161 function update( $new_instance, $old_instance ) {163 public function update( $new_instance, $old_instance ) { 162 164 $instance = $old_instance; 163 165 … … 175 177 * 176 178 * @param array $instance The saved widget settings. 177 * @return void 178 */ 179 function form( $instance ) { 179 */ 180 public function form( $instance ) { 180 181 $defaults = array( 181 'max_friends' 182 'max_friends' => 5, 182 183 'friend_default' => 'active', 183 'link_title' => false184 'link_title' => false, 184 185 ); 185 $instance = wp_parse_args( (array) $instance, $defaults ); 186 187 $max_friends 186 187 $instance = wp_parse_args( (array) $instance, $defaults ); 188 $max_friends = $instance['max_friends']; 188 189 $friend_default = $instance['friend_default']; 189 $link_title 190 $link_title = (bool) $instance['link_title']; 190 191 ?> 191 192 192 193 <p><label for="<?php echo $this->get_field_id( 'link_title' ); ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title'); ?>" id="<?php echo $this->get_field_id( 'link_title' ); ?>" value="1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Members directory', 'buddypress' ); ?></label></p> 193 194 194 <p><label for="<?php echo $this->get_field_id( 'max_friends' ); ?>"><?php _e( 'Max friends to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_friends' ); ?>" name="<?php echo $this->get_field_name( 'max_friends' ); ?>" type="text" value="<?php echo absint( $max_friends ); ?>" style="width: 30%" /></label></p>195 <p><label for="<?php echo $this->get_field_id( 'max_friends' ); ?>"><?php esc_html_e( 'Max friends to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_friends' ); ?>" name="<?php echo $this->get_field_name( 'max_friends' ); ?>" type="text" value="<?php echo absint( $max_friends ); ?>" style="width: 30%" /></label></p> 195 196 196 197 <p> 197 <label for="<?php echo $this->get_field_id( 'friend_default' ) ?>"><?php _e( 'Default friends to show:', 'buddypress' ); ?></label>198 <label for="<?php echo $this->get_field_id( 'friend_default' ) ?>"><?php esc_html_e( 'Default friends to show:', 'buddypress' ); ?></label> 198 199 <select name="<?php echo $this->get_field_name( 'friend_default' ); ?>" id="<?php echo $this->get_field_id( 'friend_default' ); ?>"> 199 <option value="newest" <?php selected( $friend_default, 'newest' ); ?>><?php _e( 'Newest', 'buddypress' ); ?></option>200 <option value="active" <?php selected( $friend_default, 'active' ); ?>><?php_e( 'Active', 'buddypress' ); ?></option>201 <option value="popular" <?php selected( $friend_default, 'popular' ); ?>><?php _e( 'Popular', 'buddypress' ); ?></option>200 <option value="newest" <?php selected( $friend_default, 'newest' ); ?>><?php esc_html_e( 'Newest', 'buddypress' ); ?></option> 201 <option value="active" <?php selected( $friend_default, 'active' ); ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></option> 202 <option value="popular" <?php selected( $friend_default, 'popular' ); ?>><?php esc_html_e( 'Popular', 'buddypress' ); ?></option> 202 203 </select> 203 204 </p> 204 205 205 <?php 206 206 } -
trunk/src/bp-friends/classes/class-bp-friends-component.php
r13002 r13092 6 6 * 7 7 * @package BuddyPress 8 * @subpackage Friends 8 * @subpackage FriendsComponent 9 9 * @since 1.5.0 10 10 */ … … 31 31 buddypress()->plugin_dir, 32 32 array( 33 'adminbar_myaccount_order' => 60 33 'adminbar_myaccount_order' => 60, 34 34 ) 35 35 ); … … 104 104 * 105 105 * @since 1.5.0 106 * 107 * @global BuddyPress $bp The one true BuddyPress instance. 106 108 * 107 109 * @see BP_Component::setup_globals() for description of parameters. … … 194 196 'screen_function' => 'friends_screen_my_friends', 195 197 'default_subnav_slug' => 'my-friends', 196 'item_css_id' => $this->id 198 'item_css_id' => $this->id, 197 199 ); 198 200 … … 205 207 'screen_function' => 'friends_screen_my_friends', 206 208 'position' => 10, 207 'item_css_id' => 'friends-my-friends' 209 'item_css_id' => 'friends-my-friends', 208 210 ); 209 211 … … 215 217 'screen_function' => 'friends_screen_requests', 216 218 'position' => 20, 217 'user_has_access' => $access 219 'user_has_access' => $access, 218 220 ); 219 221 … … 241 243 // Pending friend requests. 242 244 $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) ); 243 if ( ! empty( $count ) ) {245 if ( ! empty( $count ) ) { 244 246 $title = sprintf( 245 247 /* translators: %s: Pending friend request count for the current user */ … … 253 255 ); 254 256 } else { 255 $title = _x( 'Friends', 'My Account Friends menu','buddypress' );256 $pending = _x( 'No Pending Requests', 'My Account Friends menu sub nav', 'buddypress' );257 $title = _x( 'Friends', 'My Account Friends menu', 'buddypress' ); 258 $pending = _x( 'No Pending Requests', 'My Account Friends menu sub nav', 'buddypress' ); 257 259 } 258 260 … … 262 264 'id' => 'my-account-' . $this->id, 263 265 'title' => $title, 264 'href' => $friends_link 266 'href' => $friends_link, 265 267 ); 266 268 … … 271 273 'title' => _x( 'Friendships', 'My Account Friends menu sub nav', 'buddypress' ), 272 274 'href' => $friends_link, 273 'position' => 10 275 'position' => 10, 274 276 ); 275 277 … … 280 282 'title' => $pending, 281 283 'href' => trailingslashit( $friends_link . 'requests' ), 282 'position' => 20 284 'position' => 20, 283 285 ); 284 286 } … … 291 293 * 292 294 * @since 1.5.0 295 * 296 * @global BuddyPress $bp The one true BuddyPress instance. 293 297 */ 294 298 public function setup_title() { -
trunk/src/bp-friends/classes/class-bp-friends-friendship.php
r13086 r13092 4 4 * 5 5 * @package BuddyPress 6 * @subpackage Friends Classes6 * @subpackage FriendsFriendship 7 7 * @since 1.0.0 8 8 */ … … 132 132 * 133 133 * @since 1.0.0 134 * 135 * @global BuddyPress $bp The one true BuddyPress instance. 136 * @global wpdb $wpdb WordPress database object. 134 137 */ 135 138 public function populate() { … … 161 164 162 165 if ( ! empty( $this->populate_friend_details ) ) { 163 if ( $this->friend_user_id == bp_displayed_user_id()) {166 if ( bp_displayed_user_id() === $this->friend_user_id ) { 164 167 $this->friend = new BP_Core_User( $this->initiator_user_id ); 165 168 } else { … … 174 177 * @since 1.0.0 175 178 * 179 * @global BuddyPress $bp The one true BuddyPress instance. 180 * @global wpdb $wpdb WordPress database object. 181 * 176 182 * @return bool True on success, false on failure. 177 183 */ … … 182 188 183 189 $this->initiator_user_id = apply_filters( 'friends_friendship_initiator_user_id_before_save', $this->initiator_user_id, $this->id ); 184 $this->friend_user_id = apply_filters( 'friends_friendship_friend_user_id_before_save', $this->friend_user_id,$this->id );185 $this->is_confirmed = apply_filters( 'friends_friendship_is_confirmed_before_save', $this->is_confirmed,$this->id );186 $this->is_limited = apply_filters( 'friends_friendship_is_limited_before_save', $this->is_limited,$this->id );187 $this->date_created = apply_filters( 'friends_friendship_date_created_before_save', $this->date_created,$this->id );190 $this->friend_user_id = apply_filters( 'friends_friendship_friend_user_id_before_save', $this->friend_user_id, $this->id ); 191 $this->is_confirmed = apply_filters( 'friends_friendship_is_confirmed_before_save', $this->is_confirmed, $this->id ); 192 $this->is_limited = apply_filters( 'friends_friendship_is_limited_before_save', $this->is_limited, $this->id ); 193 $this->date_created = apply_filters( 'friends_friendship_date_created_before_save', $this->date_created, $this->id ); 188 194 189 195 /** … … 192 198 * @since 1.0.0 193 199 * 194 * @param BP_Friends_Friendship $value Current friendship request object.200 * @param BP_Friends_Friendship $value Current friendship object. Passed by reference. 195 201 */ 196 202 do_action_ref_array( 'friends_friendship_before_save', array( &$this ) ); 197 203 198 204 // Update. 199 if ( !empty( $this->id ) ) {205 if ( ! empty( $this->id ) ) { 200 206 $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) ); 201 207 … … 211 217 * @since 1.0.0 212 218 * 213 * @param BP_Friends_Friendship $value Current friendship request object.219 * @param BP_Friends_Friendship $value Current friendship object. Passed by reference. 214 220 */ 215 221 do_action_ref_array( 'friends_friendship_after_save', array( &$this ) ); … … 223 229 * @since 1.0.0 224 230 * 231 * @global BuddyPress $bp The one true BuddyPress instance. 232 * @global wpdb $wpdb WordPress database object. 233 * 225 234 * @return bool|int 226 235 */ … … 240 249 * @since 2.6.0 241 250 * 242 * @param int $user_idID of the user whose friends are being retrieved.243 * @param array $args{251 * @param int $user_id ID of the user whose friends are being retrieved. 252 * @param array $args { 244 253 * Optional. Filter parameters. 245 254 * @type int $id ID of specific friendship to retrieve. … … 251 260 * @type string $sort_order ASC or DESC. Default DESC. 252 261 * } 253 * @param string $operator 262 * @param string $operator Optional. Operator to use in `wp_list_filter()`. 254 263 * 255 264 * @return array $friendships Array of friendship objects. … … 376 385 * @since 2.7.0 377 386 * 387 * @global BuddyPress $bp The one true BuddyPress instance. 388 * @global wpdb $wpdb WordPress database object. 389 * 378 390 * @param int $user_id ID of the user. 379 391 * @return array … … 403 415 */ 404 416 public static function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) { 405 global $wpdb;406 417 407 418 if ( ! empty( $friend_requests_only ) ) { 408 419 $args = array( 409 'is_confirmed' => 0,410 'friend_user_id' => $user_id 420 'is_confirmed' => 0, 421 'friend_user_id' => $user_id, 411 422 ); 412 423 } else { … … 443 454 444 455 // Can't friend yourself. 445 if ( $user_id == $friend_id ) {456 if ( $user_id === $friend_id ) { 446 457 return $friendship_id; 447 458 } … … 453 464 $args = array( 454 465 'initiator_user_id' => $friend_id, 455 'friend_user_id' => $friend_id 466 'friend_user_id' => $friend_id, 456 467 ); 468 457 469 $result = self::get_friendships( $user_id, $args, 'OR' ); 458 470 if ( $result ) { … … 469 481 * @param int $user_id The ID of the user who has received the 470 482 * friendship requests. 471 * @return array|bool An array of user IDs ,or false if none are found.483 * @return array|bool An array of user IDs or false if none are found. 472 484 */ 473 485 public static function get_friendship_request_user_ids( $user_id ) { … … 499 511 */ 500 512 public static function total_friend_count( $user_id = 0 ) { 501 global $wpdb;502 513 503 514 if ( empty( $user_id ) ) { … … 510 521 */ 511 522 512 $args = array( 513 'is_confirmed' => 1, 514 ); 523 $args = array( 'is_confirmed' => 1 ); 515 524 $friendships = self::get_friendships( $user_id, $args ); 516 525 $count = count( $friendships ); … … 529 538 * Search the friends of a user by a search string. 530 539 * 531 * @since 1.0.0 540 * @todo Optimize this function. 541 * 542 * @since 1.0.0 543 * 544 * @global BuddyPress $bp The one true BuddyPress instance. 545 * @global wpdb $wpdb WordPress database object. 532 546 * 533 547 * @param string $filter The search string, matched against xprofile … … 546 560 global $wpdb; 547 561 548 /* 549 * TODO: Optimize this function. 550 */ 551 552 if ( empty( $user_id ) ) 562 $bp = buddypress(); 563 564 if ( empty( $user_id ) ) { 553 565 $user_id = bp_loggedin_user_id(); 566 } 554 567 555 568 // Only search for matching strings at the beginning of the … … 558 571 559 572 $pag_sql = ''; 560 if ( ! empty( $limit ) && !empty( $page ) )573 if ( ! empty( $limit ) && ! empty( $page ) ) { 561 574 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 562 563 if ( !$friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ) ) 575 } 576 577 $friend_ids = self::get_friend_user_ids( $user_id ); 578 if ( ! $friend_ids ) { 564 579 return false; 580 } 565 581 566 582 // Get all the user ids for the current user's friends. 567 583 $fids = implode( ',', wp_parse_id_list( $friend_ids ) ); 568 584 569 if ( empty( $fids ) ) 585 if ( empty( $fids ) ) { 570 586 return false; 571 572 $bp = buddypress(); 587 } 573 588 574 589 // Filter the user_ids based on the search criteria. … … 584 599 $total_friend_ids = $wpdb->get_var( $total_sql ); 585 600 586 if ( empty( $filtered_friend_ids ) ) 601 if ( empty( $filtered_friend_ids ) ) { 587 602 return false; 588 589 return array( 'friends' => array_map( 'intval', $filtered_friend_ids ), 'total' => (int) $total_friend_ids ); 603 } 604 605 return array( 606 'friends' => array_map( 'intval', $filtered_friend_ids ), 607 'total' => (int) $total_friend_ids, 608 ); 590 609 } 591 610 … … 608 627 */ 609 628 public static function check_is_friend( $initiator_userid, $possible_friend_userid ) { 610 global $wpdb;611 629 612 630 if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) { … … 615 633 616 634 // Can't friend yourself. 617 if ( $initiator_userid == $possible_friend_userid ) {635 if ( $initiator_userid === $possible_friend_userid ) { 618 636 return 'not_friends'; 619 637 } 620 638 621 BP_Friends_Friendship::update_bp_friends_cache( $initiator_userid, $possible_friend_userid );639 self::update_bp_friends_cache( $initiator_userid, $possible_friend_userid ); 622 640 623 641 return bp_core_get_incremented_cache( $initiator_userid . ':' . $possible_friend_userid, 'bp_friends' ); 624 642 } 625 643 626 627 644 /** 628 645 * Find uncached friendships between a user and one or more other users and cache them. … … 630 647 * @since 3.0.0 631 648 * 632 * @param int $user_id The ID of the primary user for whom we want 649 * @global BuddyPress $bp The one true BuddyPress instance. 650 * @global wpdb $wpdb WordPress database object. 651 * 652 * @param int $user_id The ID of the primary user for whom we want 633 653 * to check friendships statuses. 634 654 * @param int|array|string $possible_friend_ids The IDs of the one or more users 635 655 * to check friendship status with primary user. 636 * @return null637 656 */ 638 657 public static function update_bp_friends_cache( $user_id, $possible_friend_ids ) { 639 658 global $wpdb; 640 $bp = buddypress(); 659 660 $bp = buddypress(); 641 661 $possible_friend_ids = wp_parse_id_list( $possible_friend_ids ); 642 662 … … 649 669 } 650 670 } 671 651 672 if ( empty( $fetch ) ) { 652 673 return; … … 695 716 */ 696 717 public static function get_bulk_last_active( $user_ids ) { 697 global $wpdb;698 699 718 $last_activities = BP_Core_User::get_last_activity( $user_ids ); 700 719 701 720 // Sort and structure as expected in legacy function. 702 721 usort( $last_activities, function( $a, $b ) { 703 if ( $a['date_recorded'] == $b['date_recorded'] ) {722 if ( $a['date_recorded'] === $b['date_recorded'] ) { 704 723 return 0; 705 724 } … … 710 729 $retval = array(); 711 730 foreach ( $last_activities as $last_activity ) { 712 $u = new stdClass;731 $u = new stdClass(); 713 732 $u->last_activity = $last_activity['date_recorded']; 714 733 $u->user_id = $last_activity['user_id']; … … 725 744 * @since 1.0.0 726 745 * 746 * @global BuddyPress $bp The one true BuddyPress instance. 747 * @global wpdb $wpdb WordPress database object. 748 * 727 749 * @param int $friendship_id ID of the friendship to be accepted. 728 750 * @return int Number of database rows updated. 729 751 */ 730 public static function accept( $friendship_id) {752 public static function accept( $friendship_id ) { 731 753 global $wpdb; 732 754 … … 740 762 * 741 763 * @since 1.6.0 764 * 765 * @global BuddyPress $bp The one true BuddyPress instance. 766 * @global wpdb $wpdb WordPress database object. 742 767 * 743 768 * @param int $friendship_id ID of the friendship to be withdrawn. 744 769 * @return int Number of database rows deleted. 745 770 */ 746 public static function withdraw( $friendship_id) {771 public static function withdraw( $friendship_id ) { 747 772 global $wpdb; 748 773 … … 756 781 * 757 782 * @since 1.0.0 783 * 784 * @global BuddyPress $bp The one true BuddyPress instance. 785 * @global wpdb $wpdb WordPress database object. 758 786 * 759 787 * @param int $friendship_id ID of the friendship to be rejected. 760 788 * @return int Number of database rows deleted. 761 789 */ 762 public static function reject( $friendship_id) {790 public static function reject( $friendship_id ) { 763 791 global $wpdb; 764 792 … … 774 802 * 775 803 * @since 1.0.0 804 * 805 * @global BuddyPress $bp The one true BuddyPress instance. 806 * @global wpdb $wpdb WordPress database object. 776 807 * 777 808 * @param string $filter String to search by. … … 793 824 794 825 $pag_sql = ''; 795 if ( ! empty( $limit ) && !empty( $page ) )826 if ( ! empty( $limit ) && ! empty( $page ) ) { 796 827 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) ); 828 } 797 829 798 830 $bp = buddypress(); … … 805 837 } 806 838 807 $filtered_fids = $wpdb->get_col( $sql);808 809 if ( empty( $filtered_fids ) ) 839 $filtered_fids = $wpdb->get_col( $sql ); 840 841 if ( empty( $filtered_fids ) ) { 810 842 return false; 843 } 811 844 812 845 return $filtered_fids; … … 819 852 * 820 853 * @since 1.0.0 854 * 855 * @global BuddyPress $bp The one true BuddyPress instance. 856 * @global wpdb $wpdb WordPress database object. 821 857 * 822 858 * @param string $filter Search term. … … 842 878 } 843 879 844 $user_count = $wpdb->get_col( $sql);845 846 if ( empty( $user_count ) ) 880 $user_count = $wpdb->get_col( $sql ); 881 882 if ( empty( $user_count ) ) { 847 883 return false; 884 } 848 885 849 886 return $user_count[0]; … … 857 894 * @since 1.0.0 858 895 * 896 * @global BuddyPress $bp The one true BuddyPress instance. 897 * @global wpdb $wpdb WordPress database object. 898 * 859 899 * @param array $user_ids Array of user IDs. 860 * @return array User IDs, sorted by the associated display names. 900 * @return array|bool User IDs, sorted by the associated display names. 901 * False if XProfile component is not active. 861 902 */ 862 903 public static function sort_by_name( $user_ids ) { 863 904 global $wpdb; 864 905 865 if ( ! bp_is_active( 'xprofile' ) )906 if ( ! bp_is_active( 'xprofile' ) ) { 866 907 return false; 908 } 867 909 868 910 $bp = buddypress(); … … 877 919 * 878 920 * @since 1.0.0 921 * 922 * @global BuddyPress $bp The one true BuddyPress instance. 923 * @global wpdb $wpdb WordPress database object. 879 924 * 880 925 * @param int $user_id ID of the user whose friends are being retrieved. … … 893 938 894 939 for ( $i = 0, $count = count( $results ); $i < $count; ++$i ) { 895 $fids[] = ( $results[ $i]->friend_user_id == $user_id ) ? $results[$i]->initiator_user_id : $results[$i]->friend_user_id;940 $fids[] = ( $results[ $i ]->friend_user_id === $user_id ) ? $results[ $i ]->initiator_user_id : $results[ $i ]->friend_user_id; 896 941 } 897 942 898 943 // Remove duplicates. 899 if ( count( $fids ) > 0 ) 944 if ( count( $fids ) > 0 ) { 900 945 return array_flip( array_flip( $fids ) ); 901 else 902 return false; 946 } 947 948 return false; 903 949 } 904 950 … … 912 958 * - users who have been banned from the group 913 959 * 914 * @since 1.0.0915 960 * @todo Need to do a group component check before using group functions. 961 * 962 * @since 1.0.0 916 963 * 917 964 * @param int $user_id ID of the user whose friends are being counted. 918 965 * @param int $group_id ID of the group friends are being invited to. 919 * @return int $invitable_count Eligiblefriend count.966 * @return bool|int False if group component is not active, and friend count. 920 967 */ 921 968 public static function get_invitable_friend_count( $user_id, $group_id ) { 969 970 if ( ! bp_is_active( 'group' ) ) { 971 return false; 972 } 922 973 923 974 // Setup some data we'll use below. 924 975 $is_group_admin = groups_is_user_admin( $user_id, $group_id ); 925 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );976 $friend_ids = self::get_friend_user_ids( $user_id ); 926 977 $invitable_count = 0; 927 978 … … 929 980 930 981 // If already a member, they cannot be invited again. 931 if ( groups_is_user_member( (int) $friend_ids[ $i], $group_id ) ) {982 if ( groups_is_user_member( (int) $friend_ids[ $i ], $group_id ) ) { 932 983 continue; 933 984 } 934 985 935 986 // If user already has invite, they cannot be added. 936 if ( groups_check_user_has_invite( (int) $friend_ids[ $i], $group_id ) ) {987 if ( groups_check_user_has_invite( (int) $friend_ids[ $i ], $group_id ) ) { 937 988 continue; 938 989 } 939 990 940 991 // If user is not group admin and friend is banned, they cannot be invited. 941 if ( ( false === $is_group_admin ) && groups_is_user_banned( (int) $friend_ids[ $i], $group_id ) ) {992 if ( ( false === $is_group_admin ) && groups_is_user_banned( (int) $friend_ids[ $i ], $group_id ) ) { 942 993 continue; 943 994 } … … 953 1004 * 954 1005 * @since 2.7.0 1006 * 1007 * @global BuddyPress $bp The one true BuddyPress instance. 1008 * @global wpdb $wpdb WordPress database object. 955 1009 * 956 1010 * @param int|string|array $friendship_ids Single friendship ID or comma-separated/array list of friendship IDs. … … 972 1026 * 973 1027 * @param int $friendship_id ID of the friendship. 974 * @return null|stdClass friend_user_id and initiator_user_id.1028 * @return null|stdClass 975 1029 */ 976 1030 public static function get_user_ids_for_friendship( $friendship_id ) { 977 978 1031 $friendship = new BP_Friends_Friendship( $friendship_id, false, false ); 979 1032 … … 982 1035 } 983 1036 984 $retval = new StdClass;985 $retval->friend_user_id = $friendship->friend_user_id;1037 $retval = new StdClass(); 1038 $retval->friend_user_id = $friendship->friend_user_id; 986 1039 $retval->initiator_user_id = $friendship->initiator_user_id; 987 1040 … … 993 1046 * 994 1047 * @since 1.0.0 1048 * 1049 * @global BuddyPress $bp The one true BuddyPress instance. 1050 * @global wpdb $wpdb WordPress database object. 995 1051 * 996 1052 * @param int $user_id ID of the user being expunged. … … 1033 1089 // Delete cached friendships. 1034 1090 wp_cache_delete( $friend_id, 'bp_friends_friendships_for_user' ); 1035 BP_Friends_Friendship::total_friend_count( $friend_id ); 1091 1092 self::total_friend_count( $friend_id ); 1036 1093 } 1037 1094
Note: See TracChangeset
for help on using the changeset viewer.