• Resolved DougMelvin

    (@dougmelvin)


    Hello. I would like to suggest that pdf thumbnails are deleted when a pdf is deleted.
    I’ve added the following code in my custom theme to this end:

    add_action( 'admin_init', 'codex_init' );
    function codex_init() {
        if ( current_user_can( 'delete_posts' ) )
            add_action( 'delete_post', 'delete_child_attachments', 10 );
    }
    
    function delete_child_attachments( $pid ) {
    	if( 'attachment' == get_post_type($pid) ){
    		global $wpdb;
    		//get any child attachments - pdf thumbnails are saved as an attachment of the pdf file
    		$child_ids = $wpdb->get_results("
    		  SELECT ID
    		  FROM $wpdb->posts
    		  WHERE
    			post_parent = $pid
    			AND
    			post_type = 'attachment'
    		");
    		if( !empty( $child_ids ) ){
    			foreach( $child_ids as $child_id ){
    				wp_delete_attachment( $child_id->ID , true );
    			}
    		}
    	}
    	return true;
    }

    https://www.ads-software.com/plugins/pdf-thumbnails/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Delete thumbnails when deleting the PDF file’ is closed to new replies.