Skip to content

Instantly share code, notes, and snippets.

@KittenCodes
Last active March 20, 2019 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KittenCodes/dd4882c92f2c8b0421bd5849cad629ac to your computer and use it in GitHub Desktop.
Save KittenCodes/dd4882c92f2c8b0421bd5849cad629ac to your computer and use it in GitHub Desktop.
Delete empty export files created by WP All Import
<?php
/*
################### READ ME #################################
Hooks into pmxe_after_export and deletes the export files if no posts were found.
This is provided in the hopes it is useful, but without any support.
###############################################################
Instructions:
The code needs to be added to your theme functions.php or by using a plugin like Code Snippets:
https://wordpress.org/plugins/code-snippets/
###############################################################
*/
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 );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment