AnsPress_Uploader::delete_attachment()

Description #

Delete question or answer attachment.

Source #

File: includes/upload.php

	public static function delete_attachment() {
		$attachment_id = ap_sanitize_unslash( 'attachment_id', 'r' );

		if ( ! anspress_verify_nonce( 'delete-attachment-' . $attachment_id ) ) {
			ap_ajax_json( 'no_permission' );
		}

		// If user cannot delete then die.
		if ( ! ap_user_can_delete_attachment( $attachment_id ) ) {
			ap_ajax_json( 'no_permission' );
		}

		$attach = get_post( $attachment_id );
		$row    = wp_delete_attachment( $attachment_id, true );

		if ( false !== $row ) {
			ap_update_post_attach_ids( $attach->post_parent );
			ap_ajax_json( array( 'success' => true ) );
		}

		ap_ajax_json(
			array(
				'success'  => false,
				'snackbar' => array( 'message' => __( 'Unable to delete attachment', 'anspress-question-answer' ) ),
			)
		);
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment