bp_activity_user_can_edit( false|BP_Activity_Activity $activity = false, bool $privacy_edit = false )
Determine if the current user can edit an activity item.
Description
Parameters
- $activity
-
(Optional) Falls back on the current item in the loop.
Default value: false
- $privacy_edit
-
(Optional) True if editing privacy.
Default value: false
Return
(bool) True if can edit, false otherwise.
Source
File: bp-activity/bp-activity-template.php
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 | function bp_activity_user_can_edit( $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 edit the activity item. $can_edit = false; // Only logged in users can edit activity and Activity must be of type 'activity_update', 'activity_comment' if ( is_user_logged_in() && in_array( $activity ->type, array ( 'activity_update' , 'activity_comment' ) ) ) { // Users are allowed to edit their own activity. if ( isset( $activity ->user_id ) && ( bp_loggedin_user_id() === $activity ->user_id ) ) { $can_edit = true; } // Viewing a single item, and this user is an admin of that item. if ( bp_is_single_item() && bp_is_item_admin() ) { $can_edit = true; } } /** * Filters whether the current user can edit an activity item. * * @since BuddyBoss 1.2.0 * * @param bool $can_edit Whether the user can edit the item. * @param object $activity Current activity item object. */ return (bool) apply_filters( 'bp_activity_user_can_edit' , $can_edit , $activity ); } |
Changelog
Version | Description |
---|---|
BuddyBoss 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.