modemlooper avatar
About Blog

Allow BuddyPress Group Admin to delete all Activity and Replies

1 min read
buddypress wordpress php
/**
 * Allow group admins to delete all activity items inlcuging replies
 *
 * @param  boolean $retval
 * @param  string $capability
 * @param  integer $site_id
 * @param  integer $args
 * @return boolean
 */
function modemlooper_allow_group_admin_delete( $retval, $capability, $site_id, $args ) {

	if ( ! is_user_logged_in() ) {
		return $retval;
	}

	$action = isset( $_POST['action'] ) ? $_POST['action'] : '';

	if ( 'delete_activity_comment' === $action
		&& bp_is_group()
		&& groups_is_user_admin( bp_loggedin_user_id(), buddypress()->groups->current_group->id ) ) {
		return true;
	}

	return $retval;

}
add_filter( 'bp_current_user_can', 'modemlooper_allow_group_admin_delete', 10, 4 );