INVP::delete_attachment_orphans()

Deletes media that is managed by this plugin but not attached to a post.


Return Return

(void)


Top ↑

Source Source

File: includes/class-invp.php

	public static function delete_attachment_orphans() {
		$orphan_media = get_posts(
			array(
				'posts_per_page' => -1,
				'post_status'    => 'any',
				'post_type'      => 'attachment',
				'meta_query'     => array(
					array(
						'key'     => apply_filters( 'invp_prefix_meta_key', 'photo_number' ),
						'compare' => 'EXISTS',
					),
				),
			)
		);
		$settings     = self::settings();
		foreach ( $orphan_media as $post ) {
			wp_delete_attachment( $post->ID, $settings['skip_trash'] );
		}
	}