I need to send a user id to a remote server to download an XML file. I accomplish this with the snippet below:
function custom_file_download($url, $type = 'xml'){
$ch = curl_init();
$userData = array( 'user_id' => 'MY_USER_ID' );
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $userData);
$result = curl_exec($ch);
if (curl_errno($ch)) {
exit('Error:' . curl_error($ch));
}
curl_close ($ch);
$uploads = wp_upload_dir();
$filename = $uploads['basedir'] . '/' . strtok(basename($url), "?") . '.' . $type;
if (file_exists($filename)){
@unlink($filename);
}
file_put_contents($filename, $result);
return str_replace($uploads['basedir'], $uploads['baseurl'], $filename);
}
I then use the 'Download from URL' option with the address
[custom_file_download("MY_REMOTE_URL", "xml")]
This successfully downloads the file to /wp-content/uploads. However, WP-Import returns the result "There's a problem with your import file. Please verify that the URL returns a valid import file."
I can import the file manually using the 'upload a file' option with no issues, which suggests there is nothing wrong with the file itself. But I can't create a cron job to complete a daily update until WP All Import can recognise that the file has been created successfully when using 'Download from URL'.
It's been suggested that the file location is not being returned to WP All Import correctly. Please, can someone assist with debugging and/or identifying errors in the snippet above?
Perhaps the download location should be amended to the WP All Import default (/wp-content/uploads/wpallimport/uploads)?
Thanks in advance
[custom_file_download("MY_REMOTE_URL", "xml")]
is not going to return a URL, and even if it did, the plugin needs an actual URL not a shortcode of function that returns one.