[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Mon Sep 28 01:01:32 2020 Cross-referenced by PHPXref 0.7.1