Last active
September 21, 2024 21:01
-
-
Save getneerajk/3ff3b0c874c21b0be6af5ab576b6aa46 to your computer and use it in GitHub Desktop.
WP All Import Pro upload image to its original path #wp #WP_All_Import_Pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wp_all_import_single_image_uploads_dir', 'wpai_wp_all_import_single_image_uploads_dir', 10, 6 ); | |
function wpai_wp_all_import_single_image_uploads_dir( $uploads, $image_url, $articleData, $current_xml_node, $import_id, $post_id ) { | |
$position = strpos($image_url, 'uploads'); | |
$result = substr($image_url, $position + 7,8); //eg: `/2021/05` | |
$uploads['path'] = $uploads['basedir'].$result; | |
$uploads['url'] = $uploads['baseurl'].$result; | |
$uploads['subdir']=$result; | |
if (!file_exists($uploads['path'])) { | |
mkdir($uploads['path'], 0755, true); | |
} | |
return $uploads; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment