Created
July 13, 2014 23:36
-
-
Save sombrafam/426dad85eb390c9b6082 to your computer and use it in GitHub Desktop.
Code
This file contains 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
add_filter( 'fu_is_debug', '__return_true' ); | |
add_action( 'fu_after_upload', 'my_fu_after_upload', 10, 3 ); | |
function my_fu_after_upload( $attachment_ids, $success, $post_id ) { | |
// do something with freshly uploaded files | |
// This happens on POST request, so $_POST will also be available for you | |
$dest_folder = "/exports/data/".$post_id; | |
echo "FUNCTION AFTER UPLOAD: " . "<br>attachment_ids="; | |
print_r($attachment_ids); | |
echo "<br>result=". $success . "<br>post_id=". $post_id ; | |
print_r($_POST); | |
$post_name = get_post_field( 'post_title', $post_id, ""); | |
echo "Post name = " . $post_name . "<br>"; | |
if (!is_dir($dest_folder)) | |
mkdir($dest_folder); | |
$upload_dir = wp_upload_dir(); | |
echo "Upload dir<br>"; | |
print_r($upload_dir); | |
foreach ($attachment_ids as $attachment_id) { | |
printf("Getting attacments to atta %d <br>", $attachment_id); | |
$file = wp_get_attachment_metadata( $attachment_id, false); | |
print_r($file); | |
echo "<br>"; | |
$file = $file['file']; | |
$source_file = $upload_dir['basedir'] .'/'. $file; | |
// Get the last name of the file, ie for /2013/07/file.img returns file.img | |
$file = explode('/', $file); | |
$file = $file[count($file) - 1]; | |
// Get the file extension | |
$f_extension = explode('.', $file); | |
if (count($f_extension) < 2 ) { | |
$f_extension = ""; | |
} else { | |
$f_extension = $f_extension[count($f_extension) - 1]; | |
} | |
$dest_file = $dest_folder . '/' . $_POST['ra'] . '.' . $f_extension; | |
printf("Copying '%s' to '%s'<br>", $source_file, $dest_file); | |
// TODO: Verificar se não existe o arquivo antes | |
copy($source_file, $dest_file); | |
} | |
flush(); | |
} | |
add_action('fu_upload_result', 'my_fu_upload_result', 10, 2 ); | |
function my_fu_upload_result( $layout, $result ) { | |
// do something | |
echo "FUNCTION UPLOAD RESULT: " . "<br>layout=" . $layout . | |
"<br>result=". $result; | |
print_r($_POST); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment