bp_attachments_cover_image_ajax_delete()
Ajax delete a cover photo for a given object and item id.
Description
Return
(string|null) A json object containing success data if the cover photo was deleted error message otherwise.
Source
File: bp-core/bp-core-attachments.php
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 | function bp_attachments_cover_image_ajax_delete() { if ( ! bp_is_post_request() ) { wp_send_json_error(); } if ( empty ( $_POST [ 'object' ] ) || empty ( $_POST [ 'item_id' ] ) ) { wp_send_json_error(); } $args = array ( 'object' => sanitize_text_field( $_POST [ 'object' ] ), 'item_id' => (int) $_POST [ 'item_id' ], ); // Check permissions. check_admin_referer( 'bp_delete_cover_image' , 'nonce' ); if ( ! bp_attachments_current_user_can( 'edit_cover_image' , $args ) ) { wp_send_json_error(); } // Set object for the user's case. if ( 'user' === $args [ 'object' ] ) { $component = 'xprofile' ; $dir = 'members' ; // Set it for any other cases. } else { $component = $args [ 'object' ] . 's' ; $dir = $component ; } // Handle delete. if ( bp_attachments_delete_file( array ( 'item_id' => $args [ 'item_id' ], 'object_dir' => $dir , 'type' => 'cover-image' ) ) ) { /** * Fires if the cover photo was successfully deleted. * * The dynamic portion of the hook will be xprofile in case of a user's * cover photo, groups in case of a group's cover photo. For instance: * Use add_action( 'xprofile_cover_image_deleted' ) to run your specific * code once the user has deleted his cover photo. * * @since BuddyPress 2.8.0 * * @param int $item_id Inform about the item id the cover photo was deleted for. */ do_action( "{$component}_cover_image_deleted" , (int) $args [ 'item_id' ] ); $response = array ( 'reset_url' => '' , 'feedback_code' => 3, ); // Get cover photo settings in case there's a default header. $cover_params = bp_attachments_get_cover_image_settings( $component ); // Check if there's a default cover. if ( ! empty ( $cover_params [ 'default_cover' ] ) ) { $response [ 'reset_url' ] = $cover_params [ 'default_cover' ]; } wp_send_json_success( $response ); } else { wp_send_json_error( array ( 'feedback_code' => 2, ) ); } } |
Changelog
Version | Description |
---|---|
BuddyPress 2.4.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.