Skip to:
Content

BuddyPress.org

Ticket #8728: 8728.04.patch

File 8728.04.patch, 5.0 KB (added by emaralive, 13 months ago)

Replacement for 8728.03.patch

  • src/bp-core/admin/bp-core-admin-settings.php

    diff --git src/bp-core/admin/bp-core-admin-settings.php src/bp-core/admin/bp-core-admin-settings.php
    index 0dc6b02c9..cd8ab22b9 100644
    function bp_admin_setting_callback_group_cover_image_uploads() { 
    349349<?php
    350350}
    351351
     352/**
     353 * 'Enable group activity deletions.
     354 *
     355 * @since 14.0.0
     356 */
     357function bp_admin_setting_callback_group_activity_deletions() {
     358?>
     359        <input id="bp-enable-group-activity-deletions" name="bp-enable-group-activity-deletions" type="checkbox" value="1" <?php checked( bp_enable_group_activity_deletions() ); ?> />
     360        <label for="bp-enable-group-activity-deletions"><?php esc_html_e( "Allow group administrators and moderators to delete activity items from their group's activity stream", 'buddypress' ); ?></label>
     361<?php
     362}
     363
    352364/** Account settings Section ************************************************************/
    353365
    354366/**
  • src/bp-core/bp-core-options.php

    diff --git src/bp-core/bp-core-options.php src/bp-core/bp-core-options.php
    index c0ec714dd..614ccd64e 100644
    function bp_get_default_options() { 
    6262                // Group Cover image uploads.
    6363                'bp-disable-group-cover-image-uploads' => false,
    6464
     65                // Allow Group Activity Deletions.
     66                'bp-enable-group-activity-deletions'   => false,
     67
    6568                // Allow users to delete their own accounts.
    6669                'bp-disable-account-deletion'          => false,
    6770
    function bp_disable_group_cover_image_uploads( $default = false ) { 
    585588        return (bool) apply_filters( 'bp_disable_group_cover_image_uploads', (bool) bp_get_option( 'bp-disable-group-cover-image-uploads', $default ) );
    586589}
    587590
     591/**
     592 * Are group activity deletions enabled?
     593 *
     594 * @since 14.0.0
     595 *
     596 * @param bool $default Optional. Fallback value if not found in the database.
     597 *                      Default: false.
     598 * @return bool True if group activity deletions are enabled, otherwise false.
     599 */
     600function bp_enable_group_activity_deletions( $default = false ) {
     601
     602        /**
     603         * Filters whether or not group creator, group admin or group mod are able to delete group activity posts.
     604         *
     605         * @since 14.0.0
     606         *
     607         * @param bool $value Whether or not group creator, group admin or group mod are able to delete group activity post.
     608         */
     609        return (bool) apply_filters( 'bp_enable_group_activity_deletions', (bool) bp_get_option( 'bp-enable-group-activity-deletions', $default ) );
     610}
     611
    588612/**
    589613 * Are members able to delete their own accounts?
    590614 *
  • src/bp-core/classes/class-bp-admin.php

    diff --git src/bp-core/classes/class-bp-admin.php src/bp-core/classes/class-bp-admin.php
    index 7b263e133..680cf6cbc 100644
    class BP_Admin { 
    567567                                add_settings_field( 'bp-disable-group-cover-image-uploads', __( 'Group Cover Image Uploads', 'buddypress' ), 'bp_admin_setting_callback_group_cover_image_uploads', 'buddypress', 'bp_groups' );
    568568                                register_setting( 'buddypress', 'bp-disable-group-cover-image-uploads', 'intval' );
    569569                        }
     570
     571                        // Allow group activity deletions.
     572                        add_settings_field( 'bp-enable-group-activity-deletions', esc_html__( 'Group Activity Deletions', 'buddypress' ), 'bp_admin_setting_callback_group_activity_deletions', 'buddypress', 'bp_groups' );
     573                        register_setting( 'buddypress', 'bp-enable-group-activity-deletions', 'intval' );
    570574                }
    571575
    572576                /* Activity Section **************************************************/
  • src/bp-groups/bp-groups-activity.php

    diff --git src/bp-groups/bp-groups-activity.php src/bp-groups/bp-groups-activity.php
    index 1cafacd66..143d1e177 100644
    function groups_post_update( $args = '' ) { 
    650650 * @return bool
    651651 */
    652652function bp_groups_filter_activity_user_can_delete( $retval, $activity ) {
    653         // Bail if no current user.
    654         if ( ! is_user_logged_in() ) {
     653        // Bail if no current user or group activity deletions are disabled.
     654        if ( ! is_user_logged_in() || ! bp_enable_group_activity_deletions() ) {
    655655                return $retval;
    656656        }
    657657
    658         if ( isset( $activity->component ) || 'groups' !== $activity->component ) {
     658        if ( isset( $activity->component ) && 'groups' !== $activity->component ) {
    659659                return $retval;
    660660        }
    661661
    662         // Trust the passed value for administrators.
    663         if ( bp_current_user_can( 'bp_moderate' ) ) {
     662        // The first conditional statement will trust the passed value for administrators.
     663        // The second conditional statement does not allow "site admin" activity posts to be deleted by "non site admins".
     664        if ( bp_current_user_can( 'bp_moderate' ) || bp_user_can( $activity->user_id, 'bp_moderate' ) ) {
    664665                return $retval;
    665666        }
    666667
    667         // Group administrators or moderators can delete content in that group that doesn't belong to them.
    668668        $group_id = $activity->item_id;
     669
     670        // Group administrators or moderators can delete content in which deletions are allowed for that group.
    669671        if ( groups_is_user_admin( bp_loggedin_user_id(), $group_id ) || groups_is_user_mod( bp_loggedin_user_id(), $group_id ) ) {
    670672                $retval = true;
    671673        }