Fire_Kitteh of Soflyy WP All Import Export
6/21/2018 - 2:56 PM

Delete empty export files

Add to functions.php or Code Snippets

<?php

add_action('pmxe_after_export', 'wpae_get_file_after_export', 10, 2);

function wpae_get_file_after_export($export_id, $exportObj){
        $is_secure_export = PMXE_Plugin::getInstance()->getOption('secure');
        
        if (!$is_secure_export) {
                $filepath = get_attached_file($exportObj->attch_id);                    
        } else {
                $filepath = wp_all_export_get_absolute_path($exportObj->options['filepath']);
        }
        
        $filename = basename( $filepath );
        $path = str_replace( $filename, '', $filepath );
        if ( $exportObj->exported == 0 ) {
                $filename = explode( ".", $filename );
                $full_glob_search = $path . "*" . $filename[0] . "*";;
                if ( $files = glob( $full_glob_search ) ) {
                        foreach ( $files as $file ) {
                                unlink( $file );
                        }
                }
        }
}