Skip to content

Instantly share code, notes, and snippets.

@cliffordp cliffordp/functions.php
Last active Apr 14, 2019

Embed
What would you like to do?
WP All Import - set uploads folder to the Import ID
<?php
/**
* WP All Import: Upload media to a directory named after the Import ID.
*
* @link https://gist.github.com/cliffordp/fc0fa5686d6a127246224f1565b60128 This snippet.
* @link https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/wp_all_import_images_uploads_dir.php
*
* @see PMXI_Import_Record::process()
* @see wp_upload_dir()
*
* @param array $uploads
* @param array $articleData
* @param array $current_xml_node
* @param $import_id
*
* @return array
*/
function cliff_wpai_set_upload_folder_to_import_id( $uploads, $articleData, $current_xml_node, $import_id ) {
// Ensure not empty or unexpected value, with fallback to zero.
$import_id = absint( $import_id );
$uploads['path'] = $uploads['basedir'] . '/' . $import_id;
$uploads['url'] = $uploads['baseurl'] . '/' . $import_id;
if ( ! file_exists( $uploads['path'] ) ) {
mkdir( $uploads['path'], 0755, true );
}
return $uploads;
}
add_filter( 'wp_all_import_images_uploads_dir', 'cliff_wpai_set_upload_folder_to_import_id', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.