-
Notifications
You must be signed in to change notification settings - Fork 27
/
wp_all_import_attachments_uploads_dir.php
42 lines (34 loc) · 1.59 KB
/
wp_all_import_attachments_uploads_dir.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* =========================================
* Filter: wp_all_import_attachments_uploads_dir
* =========================================
*
* Can be used to set a custom path in which attachments (uploaded by the "Download & Import Attachments" field) are uploaded. Only applies to attachments uploaded via WP All Import.
*
* @since 4.4.9
*
* @param $uploads array - Contains information related to the WordPress uploads path & URL
* @param $articleData array - Contains a list of data related to the post/user/taxonomy being imported
* @param $current_xml_node array - Contains a list of nodes within the current import record
* @param $import_id int - Contains the ID of the import
*
* @return string
*/
add_filter('wp_all_import_attachments_uploads_dir', 'wpai_wp_all_import_attachments_uploads_dir', 10, 4);
function wpai_wp_all_import_attachments_uploads_dir($uploads, $articleData, $current_xml_node, $import_id){
return $uploads;
}
/**
* Upload attachments to /woocommerce_uploads folder
*
*/
function wpai_attachments_uploaded_to_woocommerce_uploads($uploads, $articleData, $current_xml_node, $import_id) {
$uploads['path'] = $uploads['basedir'] . '/woocommerce_uploads/' . date("Y/m", strtotime($articleData['post_date']));
$uploads['url'] = $uploads['baseurl'] . '/woocommerce_uploads/' . date("Y/m", strtotime($articleData['post_date']));
if (!file_exists($uploads['path'])) {
mkdir($uploads['path'], 0755, true);
}
return $uploads;
}
add_filter('wp_all_import_attachments_uploads_dir', 'wpai_attachments_uploaded_to_woocommerce_uploads', 10, 4);