ap_clear_unattached_media( integer $user_id = false )

Description #

Delete all un-attached media of user.

Parameters #

  • $user_id
    integer (Optional) User ID. Default value: false

Source #

File: includes/upload.php

function ap_clear_unattached_media( $user_id = false ) {
	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

	global $wpdb;
	$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_title='_ap_temp_media' AND post_author = %d", $user_id ) ); // phpcs:ignore WordPress.DB

	foreach ( (array) $post_ids as $id ) {
		wp_delete_attachment( $id, true );
	}
}

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