bp_nouveau_ajax_document_delete()

Ajax delete the document.

Description

Source

File: bp-templates/bp-nouveau/includes/document/ajax.php

function bp_nouveau_ajax_document_delete() {

	$response = array(
		'feedback' => sprintf(
			'<div class="bp-feedback error bp-ajax-message"><span class="bp-icon" aria-hidden="true"></span><p>%s</p></div>',
			esc_html__( 'There was a problem performing this action. Please try again.', 'buddyboss' )
		),
	);

	// Bail if not a POST action.
	if ( ! bp_is_post_request() ) {
		wp_send_json_error( $response );
	}

	$id            = ! empty( $_POST['id'] ) ? (int) filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT ) : 0;
	$attachment_id = ! empty( $_POST['attachment_id'] ) ? (int) filter_input( INPUT_POST, 'attachment_id', FILTER_VALIDATE_INT ) : 0;
	$type          = ! empty( $_POST['type'] ) ? filter_input( INPUT_POST, 'type', FILTER_SANITIZE_STRING ) : '';
	$scope         = ! empty( $_POST['scope'] ) ? filter_input( INPUT_POST, 'scope', FILTER_SANITIZE_STRING ) : '';

	if ( '' === $type ) {
		wp_send_json_error( $response );
	}

	if ( 'folder' === $type ) {
		if ( bp_folder_user_can_delete( $id ) ) {
			bp_folder_delete( array( 'id' => $id ) );
		}
	} else {
		if ( bp_document_user_can_delete( $id ) ) {
			$args = array(
				'id'            => $id,
				'attachment_id' => $attachment_id,
			);
			bp_document_delete( $args );
		}
	}

	$content = '';
	ob_start();

	$string = '';
	if ( '' !== $scope && 'personal' === $scope ) {
		$string = '&scope=' . $scope;
	}

	if ( bp_has_document( bp_ajax_querystring( 'document' ) . $string ) ) :

		if ( empty( $_POST['page'] ) || 1 === (int) filter_input( INPUT_POST, 'page', FILTER_SANITIZE_STRING ) ) :
			?>

			<div class="document-data-table-head">
				<span class="data-head-sort-label"><?php esc_html_e( 'Sort By:', 'buddyboss' ); ?></span>
				<div class="data-head data-head-name">
				<span>
					<?php esc_html_e( 'Name', 'buddyboss' ); ?>
					<i class="bb-icon-triangle-fill"></i>
				</span>

				</div>
				<div class="data-head data-head-modified">
				<span>
					<?php esc_html_e( 'Modified', 'buddyboss' ); ?>
					<i class="bb-icon-triangle-fill"></i>
				</span>

				</div>
				<div class="data-head data-head-visibility">
				<span>
					<?php esc_html_e( 'Visibility', 'buddyboss' ); ?>
					<i class="bb-icon-triangle-fill"></i>
				</span>
				</div>
			</div><!-- .document-data-table-head -->

			<div id="media-folder-document-data-table">
			<?php
			bp_get_template_part( 'document/activity-document-move' );
			bp_get_template_part( 'document/activity-document-folder-move' );

		endif;

		while ( bp_document() ) :
			bp_the_document();

			bp_get_template_part( 'document/document-entry' );

		endwhile;

		if ( bp_document_has_more_items() ) :
			?>
			<div class="pager">
				<div class="dt-more-container load-more">
					<a class="button outline full" href="<?php bp_document_load_more_link(); ?>"><?php esc_html_e( 'Load More', 'buddyboss' ); ?></a>
				</div>
			</div>
			<?php
		endif;

		if ( empty( $_POST['page'] ) || 1 === (int) filter_input( INPUT_POST, 'page', FILTER_SANITIZE_STRING ) ) :
			?>
			</div> <!-- #media-folder-document-data-table -->
			<?php
		endif;

	else :

		bp_nouveau_user_feedback( 'media-loop-document-none' );

	endif;

	$content .= ob_get_clean();

	wp_send_json_success(
		array(
			'message' => 'success',
			'html'    => $content,
		)
	);

}

Changelog

Changelog
Version Description
BuddyBoss 1.4.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.