bp_nouveau_ajax_document_save_privacy()

Description

Source

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

function bp_nouveau_ajax_document_save_privacy() {
	global $wpdb, $bp;

	if ( ! is_user_logged_in() ) {
		$response['feedback'] = esc_html__( 'Please login to edit a privacy.', 'buddyboss' );
		wp_send_json_error( $response );
	}

	$id      = filter_input( INPUT_POST, 'itemId', FILTER_VALIDATE_INT );
	$type    = filter_input( INPUT_POST, 'type', FILTER_SANITIZE_STRING );
	$privacy = filter_input( INPUT_POST, 'value', FILTER_SANITIZE_STRING );

	if ( 'folder' === $type ) {
		if ( (int) $id > 0 ) {
			$has_access = bp_folder_user_can_edit( $id );
			if ( ! $has_access ) {
				$response['feedback'] = esc_html__( 'You don\'t have permission to update this folder privacy.', 'buddyboss' );
				wp_send_json_error( $response );
			}
		}
	} else {
		if ( (int) $id > 0 ) {
			$has_access = bp_document_user_can_edit( $id );
			if ( ! $has_access ) {
				$response['feedback'] = esc_html__( 'You don\'t have permission to update this document privacy.', 'buddyboss' );
				wp_send_json_error( $response );
			}
		}
	}

	if ( ! array_key_exists( $privacy, bp_document_get_visibility_levels() ) ) {
		$response['feedback'] = esc_html__( 'Invalid privacy status.', 'buddyboss' );
		wp_send_json_error( $response );
	}

	// Update document privacy with nested level.
	bp_document_update_privacy( $id, $privacy, $type );

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

}

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.