bp_media_user_can_delete( int|BP_Media $media = false )

Determine if the current user can delete an media item.

Description

Parameters

$media

(Optional) BP_Media object or ID of the media

Default value: false

Return

(bool) True if can delete, false otherwise.

Source

File: bp-media/bp-media-template.php

function bp_media_user_can_delete( $media = false ) {

	// Assume the user cannot delete the media item.
	$can_delete = false;

	if ( empty( $media ) ) {
		return $can_delete;
	}

	if ( ! is_object( $media ) ) {
		$media = new BP_Media( $media );
	}

	if ( empty( $media ) ) {
		return $can_delete;
	}

	// Only logged in users can delete media.
	if ( is_user_logged_in() ) {

		// Community moderators can always delete media (at least for now).
		if ( bp_current_user_can( 'bp_moderate' ) ) {
			$can_delete = true;
		}

		// Users are allowed to delete their own media.
		if ( isset( $media->user_id ) && ( $media->user_id === bp_loggedin_user_id() ) ) {
			$can_delete = true;
		}

		if ( bp_is_active( 'groups' ) && $media->group_id > 0 ) {
			$manage   = groups_can_user_manage_document( bp_loggedin_user_id(), $media->group_id );
			$status   = bp_group_get_media_status( $media->group_id );
			$is_admin = groups_is_user_admin( bp_loggedin_user_id(), $media->group_id );
			$is_mod   = groups_is_user_mod( bp_loggedin_user_id(), $media->group_id );
			if ( $manage ) {
				if ( $media->user_id === bp_loggedin_user_id() ) {
					$can_delete = true;
				} elseif ( 'members' === $status && ( $is_mod || $is_admin ) ) {
					$can_delete = true;
				} elseif ( 'mods' == $status && ( $is_mod || $is_admin ) ) {
					$can_delete = true;
				} elseif ( 'admins' == $status && $is_admin ) {
					$can_delete = true;
				}
			}
		}
	}

	/**
	 * Filters whether the current user can delete an media item.
	 *
	 * @since BuddyBoss 1.2.0
	 *
	 * @param bool   $can_delete Whether the user can delete the item.
	 * @param object $media   Current media item object.
	 */
	return (bool) apply_filters( 'bp_media_user_can_delete', $can_delete, $media );
}

Changelog

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.