Skip to:
Content

BuddyPress.org

Changeset 8697


Ignore:
Timestamp:
07/27/2014 03:01:26 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Updates to bp_activity_user_can_delete():

  • Wrap $can_delete checks is is_user_logged_in() to avoid superfluous processing on activity items when no user is logged in.
  • Cast return value to boolean.
  • Add some inline documentation.
  • Add an empty() check on $activities_template->activity to avoid using it if the global is not setup yet.
  • Add some brackets.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-template.php

    r8685 r8697  
    16361636        global $activities_template;
    16371637
    1638         if ( !$activity )
     1638        // Try to use current activity if none was passed
     1639        if ( empty( $activity ) && ! empty( $activities_template->activity ) ) {
    16391640                $activity = $activities_template->activity;
    1640 
    1641         if ( isset( $activity->current_comment ) )
     1641        }
     1642
     1643        // If current_comment is set, we'll use that in place of the main activity
     1644        if ( isset( $activity->current_comment ) ) {
    16421645                $activity = $activity->current_comment;
    1643 
     1646        }
     1647
     1648        // Assume the user cannot delete the activity item
    16441649        $can_delete = false;
    16451650
    1646         if ( bp_current_user_can( 'bp_moderate' ) )
    1647                 $can_delete = true;
    1648 
    1649         if ( is_user_logged_in() && $activity->user_id == bp_loggedin_user_id() )
    1650                 $can_delete = true;
    1651 
    1652         if ( bp_is_item_admin() && bp_is_single_item() )
    1653                 $can_delete = true;
    1654 
    1655         return apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity );
     1651        // Only logged in users can delete activity
     1652        if ( is_user_logged_in() ) {
     1653
     1654                // Community moderators can always delete activity (at least for now)
     1655                if ( bp_current_user_can( 'bp_moderate' ) ) {
     1656                        $can_delete = true;
     1657                }
     1658
     1659                // Users are allowed to delete their own activity. This is actually
     1660                // quite powerful, because doing so also deletes all comments to that
     1661                // activity item. We should revisit this eventually.
     1662                if ( $activity->user_id === bp_loggedin_user_id() ) {
     1663                        $can_delete = true;
     1664                }
     1665
     1666                // Viewing a single item, and this user is an admin of that item
     1667                if ( bp_is_single_item() && bp_is_item_admin() ) {
     1668                        $can_delete = true;
     1669                }
     1670        }
     1671
     1672        return (bool) apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity );
    16561673}
    16571674
Note: See TracChangeset for help on using the changeset viewer.