basename($url), 'tmp_name' => $tmp ); if (is_wp_error($tmp)) { @unlink($file_array['tmp_name']); return (array( 'status' => 'error', 'message' => $tmp->get_error_message() )); } $id = media_handle_sideload($file_array, $post_id); if (is_wp_error($id)) { @unlink($file_array['tmp_name']); return (array( 'status' => 'error', 'message' => $tmp->get_error_message() )); } remove_filter('https_ssl_verify', '__return_false'); remove_filter('https_local_ssl_verify', '__return_false'); $value = wp_get_attachment_url($id); return (array( 'status' => 'success', 'message' => $value )); } /** * Delete temporary files * * @return void * @since 8.5.21 */ public static function wpvr_delete_temp_file() { $filesToDelete = array(); $file_save_url = wp_upload_dir(); $rootPath = realpath($file_save_url['basedir'] . '/wpvr/temp/'); $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { if (!$file->isDir()) { $filePath = $file->getRealPath(); $filesToDelete[] = $filePath; } } foreach ($filesToDelete as $file) { unlink($file); } } }