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
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 | 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.