bp_avatar_ajax_delete()
Ajax delete an avatar for a given object and item id.
Description
Return
(string|null) A JSON object containing success data if the avatar was deleted, error message otherwise.
Source
File: bp-core/bp-core-avatars.php
function bp_avatar_ajax_delete() {
if ( ! bp_is_post_request() ) {
wp_send_json_error();
}
$avatar_data = $_POST;
if ( empty( $avatar_data['object'] ) || empty( $avatar_data['item_id'] ) ) {
wp_send_json_error();
}
$nonce = 'bp_delete_avatar_link';
if ( 'group' === $avatar_data['object'] ) {
$nonce = 'bp_group_avatar_delete';
}
// Check the nonce.
check_admin_referer( $nonce, 'nonce' );
// Capability check.
if ( ! bp_attachments_current_user_can( 'edit_avatar', $avatar_data ) ) {
wp_send_json_error();
}
// Handle delete.
if ( bp_core_delete_existing_avatar( array( 'item_id' => $avatar_data['item_id'], 'object' => $avatar_data['object'] ) ) ) {
$return = array(
'avatar' => esc_url( bp_core_fetch_avatar( array(
'object' => $avatar_data['object'],
'item_id' => $avatar_data['item_id'],
'html' => false,
'type' => 'full',
) ) ),
'feedback_code' => 4,
'item_id' => $avatar_data['item_id'],
);
wp_send_json_success( $return );
} else {
wp_send_json_error( array(
'feedback_code' => 3,
) );
}
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.3.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.