[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-friends/actions/ -> add-friend.php (source)

   1  <?php
   2  /**
   3   * Friends: Add action.
   4   *
   5   * @package BuddyPress
   6   * @subpackage FriendsActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Catch and process friendship requests.
  12   *
  13   * @since 1.0.1
  14   */
  15  function friends_action_add_friend() {
  16      if ( ! bp_is_friends_component() || ! bp_is_current_action( 'add-friend' ) ) {
  17          return false;
  18      }
  19  
  20      $potential_friend_id = (int) bp_action_variable( 0 );
  21      if ( ! $potential_friend_id ) {
  22          return false;
  23      }
  24  
  25      if ( bp_loggedin_user_id() === $potential_friend_id ) {
  26          return false;
  27      }
  28  
  29      $friendship_status = BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $potential_friend_id );
  30  
  31      if ( 'not_friends' === $friendship_status ) {
  32  
  33          if ( ! check_admin_referer( 'friends_add_friend' ) ) {
  34              return false;
  35          }
  36  
  37          if ( ! friends_add_friend( bp_loggedin_user_id(), $potential_friend_id ) ) {
  38              bp_core_add_message( __( 'Friendship could not be requested.', 'buddypress' ), 'error' );
  39          } else {
  40              bp_core_add_message( __( 'Friendship requested', 'buddypress' ) );
  41          }
  42      } elseif ( 'is_friend' === $friendship_status ) {
  43          bp_core_add_message( __( 'You are already friends with this user', 'buddypress' ), 'error' );
  44      } else {
  45          bp_core_add_message( __( 'You already have a pending friendship request with this user', 'buddypress' ), 'error' );
  46      }
  47  
  48      bp_core_redirect( wp_get_referer() );
  49  
  50      return false;
  51  }
  52  add_action( 'bp_actions', 'friends_action_add_friend' );


Generated: Tue Apr 23 01:01:07 2024 Cross-referenced by PHPXref 0.7.1