List Non-WebP Image Files

This gives you a list of all non-WebP image files that are WordPress attachments, that is, they are in the WP Media Library, including all sizes.

The list includes all JPEG/JPG/PNG images that WordPress knows of. That is, all attachments, featured images, images inserted into post content, and all extra sizes including thumbnails and any custom sizes.

This will only list images of type JPEG, JPG, or PNG. It will not list WebP, nor GIF, nor other formats.

You can either use this as a quick one-time-use plugin which you can delete right after, or do it yourself with the code below.

To Use This as a Plugin

  1. Download the plugin ↓

  2. Upload, install and activate the plugin in your WordPress admin Plugins page.
  3. Click on the new menu item in your WordPress dashboard, “List Non-WebP Image Files.”
  4. Click DOWNLOAD LIST to download the text file called wp_images.txt that lists your images.
  5. You can then deactivate and delete the plugin.

To Do it Yourself

If you prefer to do it yourself instead of using the plugin above, here is the PHP code. Lines 1–21 add a page in your admin to let you run the download. Lines 23–70 do the actual work of putting the list together.

PHP

add_action('admin_menu', function() {
		add_menu_page('List Non-WebP Image Files', 'List Non-WebP Image Files', 'manage_options', 'listnonwebpimagefiles', 'listnonwebpimagefiles_admin_page', 'dashicons-hammer', 4);
});
function listnonwebpimagefiles_admin_page(){
	?>
	<div class="wrap">
	<h1>List Non-WebP Image Files</h1>
	<div class="card">
		<p class="notice-title">Download a text file that lists all JPEG/JPG/PNG images that WordPress knows of.</p>
		<p class="notice-title">That is, all attachments, featured images, images inserted into post content, and all extra sizes including thumbnails and any custom sizes.</p>
		<p class="notice-title">This will only list images of type JPEG, JPG, or PNG. It will not list WebP, nor GIF, nor other formats.</p>
		<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
			<p><input type="hidden" name="action" value="listnonwebpimagefiles_do">
				<?php wp_nonce_field('clicked_to_see', 'wc_convert_nonce');
				submit_button('DOWNLOAD LIST', 'primary', 'submit', false);?>
			</p>
		</form>
    </div>
	</div>
	<?php
}
add_action('admin_post_listnonwebpimagefiles_do', function () {
	if (!wp_verify_nonce($_POST['wc_convert_nonce'], 'clicked_to_see')) return;
	if (!current_user_can('manage_options')) return;
	$_attached_files = array();
	$_sized_files = array();
	$old_imagetypes = array('image/png','image/jpg','image/jpeg');
	$attachments = get_posts(array('post_type'=>'attachment','numberposts' => -1));

	foreach ($attachments as $attachment) {
		// skip if not a jpeg or png image
	    if(! in_array($attachment->post_mime_type, $old_imagetypes)) {
	    	continue;
	    }

		// 1. List all _wp_attached_file

		$original_file = get_post_meta($attachment->ID, '_wp_attached_file', true);
		if($original_file) {
	    	$_attached_files[] = $original_file;
	    }
			
		// 2. List sized files from _wp_attachment_metadata

		$metadata = wp_get_attachment_metadata($attachment->ID);
	    foreach($metadata['sizes'] as $arr) {
	    	if(! in_array($arr['mime-type'], $old_imagetypes)) continue;
	    	$_sized_files[] = $arr['file'];
	    }

	} // end foreach attachment

	$final_arr = array_unique(array_merge($_attached_files, $_sized_files));
	$text = implode("\n", $final_arr);
	$namefile = "wp_images.txt";

	//save file
	$file = fopen($namefile, "w") or die("Unable to open file!");
	fwrite($file, $text);
	fclose($file);

	//header download
	header("Content-Disposition: attachment; filename=\"" . $namefile . "\"");
	header("Content-Type: application/force-download");
	header('Expires: 0');
	header('Cache-Control: must-revalidate');
	header('Pragma: public');
	header("Content-Type: text/plain");
	echo $text;
	exit;	
});

See more:

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]