bp_avatar_ajax_delete

Ajax delete an avatar for a given object and item id.

Description

(string|null) bp_avatar_ajax_delete(); 

Returns (string|null)

A JSON object containing success data if the avatar was deleted, error message otherwise.


Usage

  1. if ( !function_exists( 'bp_avatar_ajax_delete' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-avatars.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_avatar_ajax_delete(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-avatars.php  
  1. function bp_avatar_ajax_delete() { 
  2. // Bail if not a POST action. 
  3. if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 
  4. wp_send_json_error(); 
  5.  
  6. $avatar_data = $_POST; 
  7.  
  8. if ( empty( $avatar_data['object'] ) || empty( $avatar_data['item_id'] ) ) { 
  9. wp_send_json_error(); 
  10.  
  11. $nonce = 'bp_delete_avatar_link'; 
  12. if ( 'group' === $avatar_data['object'] ) { 
  13. $nonce = 'bp_group_avatar_delete'; 
  14.  
  15. // Check the nonce. 
  16. check_admin_referer( $nonce, 'nonce' ); 
  17.  
  18. // Capability check. 
  19. if ( ! bp_attachments_current_user_can( 'edit_avatar', $avatar_data ) ) { 
  20. wp_send_json_error(); 
  21.  
  22. // Handle delete. 
  23. if ( bp_core_delete_existing_avatar( array( 'item_id' => $avatar_data['item_id'], 'object' => $avatar_data['object'] ) ) ) { 
  24. $return = array( 
  25. 'avatar' => html_entity_decode( bp_core_fetch_avatar( array( 
  26. 'object' => $avatar_data['object'],  
  27. 'item_id' => $avatar_data['item_id'],  
  28. 'html' => false,  
  29. 'type' => 'full',  
  30. ) ) ),  
  31. 'feedback_code' => 4,  
  32. 'item_id' => $avatar_data['item_id'],  
  33. ); 
  34.  
  35. wp_send_json_success( $return ); 
  36. } else { 
  37. wp_send_json_error( array( 
  38. 'feedback_code' => 3,  
  39. ) );