bp_activity_user_can_delete( false|BP_Activity_Activity $activity = false )
Determine if the current user can delete an activity item.
Description
Parameters
- $activity
-
(Optional) Falls back on the current item in the loop.
Default value: false
Return
(bool) True if can delete, false otherwise.
Source
File: bp-activity/bp-activity-template.php
function bp_activity_user_can_delete( $activity = false ) { global $activities_template; // Try to use current activity if none was passed. if ( empty( $activity ) && ! empty( $activities_template->activity ) ) { $activity = $activities_template->activity; } // If current_comment is set, we'll use that in place of the main activity. if ( isset( $activity->current_comment ) ) { $activity = $activity->current_comment; } // Assume the user cannot delete the activity item. $can_delete = false; // Only logged in users can delete activity. if ( is_user_logged_in() ) { // Community moderators can always delete activity (at least for now). if ( bp_current_user_can( 'bp_moderate' ) ) { $can_delete = true; } // Users are allowed to delete their own activity. This is actually // quite powerful, because doing so also deletes all comments to that // activity item. We should revisit this eventually. if ( isset( $activity->user_id ) && ( $activity->user_id === bp_loggedin_user_id() ) ) { $can_delete = true; } // Viewing a single item, and this user is an admin of that item. if ( bp_is_single_item() && bp_is_item_admin() ) { $can_delete = true; } } /** * Filters whether the current user can delete an activity item. * * @since BuddyPress 1.5.0 * * @param bool $can_delete Whether the user can delete the item. * @param object $activity Current activity item object. */ return (bool) apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.2.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.