gdwpm_custom_upload_filter

The Google Drive WP Media gdwpm custom upload filter function.

Description

gdwpm_custom_upload_filter( $file ); 

Parameters (1)

0. $file
The file.

Usage

  1. if ( !function_exists( 'gdwpm_custom_upload_filter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-drive-wp-media/google-drive-wp-media.php'; 
  3.  
  4. // The file. 
  5. $file = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = gdwpm_custom_upload_filter($file); 
  9.  

Defined (1)

The function is defined in the following location(s).

/google-drive-wp-media.php  
  1. function gdwpm_custom_upload_filter( $file ) { 
  2. $gdwpm_opt_akun = get_option('gdwpm_akun_opt'); // imel, client id, service akun, private key 
  3. if(!empty($gdwpm_opt_akun[1]) && !empty($gdwpm_opt_akun[2]) && !empty($gdwpm_opt_akun[3])) { 
  4.  
  5. global $gdwpm_override_optional; 
  6.  
  7. require_once 'gdwpm-api/Google_Client.php'; 
  8. require_once 'gdwpm-api/contrib/Google_DriveService.php'; 
  9.  
  10. $gdwpm_service_ride = new GDWPMBantuan( $gdwpm_opt_akun[1], $gdwpm_opt_akun[2], $gdwpm_opt_akun[3] ); 
  11.  
  12. $filename = $file['name']; 
  13. $path = $file['tmp_name']; 
  14. $mime_berkas = $file['type']; 
  15. //$mime_berkas = sanitize_mime_type($mime_berkas); 
  16. $folder_ortu = preg_replace("/[^a-zA-Z0-9]+/", " ", $gdwpm_override_optional[1]); 
  17. $folder_ortu = sanitize_text_field($folder_ortu); 
  18.  
  19. if($folder_ortu != '') { 
  20. $folderId = $gdwpm_service_ride->getFolderIdByName( $folder_ortu ); 
  21.  
  22. $content = ''; 
  23.  
  24. if( ! $folderId ) { 
  25. $folderId = $gdwpm_service_ride->createFolder( $folder_ortu ); 
  26. $gdwpm_service_ride->setPermissions( $folderId, $gdwpm_opt_akun[0] ); 
  27.  
  28. $fileParent = new Google_ParentReference(); 
  29. $fileParent->setId( $folderId ); 
  30. $fileId = $gdwpm_service_ride->createFileFromPath( $path, $filename, $content, $fileParent ); 
  31.  
  32. $sukinfo = ''; 
  33. if($fileId) { 
  34. $gdwpm_service_ride->setPermissions( $fileId, 'me', 'reader', 'anyone' ); 
  35. if(!empty($mime_berkas) && $gdwpm_override_optional[2] == 'checked') { 
  36. gdwpm_ijin_masuk_perpus($mime_berkas, $filename, $fileId, $content, $folder_ortu); 
  37. $sukinfo = ' and added into your Media Library'; 
  38. echo '<div class="updated"><p>Done! <strong>'.$filename.' ('.$fileId.')</strong> successfully uploaded into <strong>'.$folder_ortu.'</strong>'.$sukinfo.'.</p></div>'; 
  39. $fileku[error] = 'Google Drive WP Media: Thiserrormessage appear because your file has been deleted before uploading to the internal uploads folder. If you want to remove this error, just navigate to Media >> Google Drive WP Media >> Options and then uncheck the "Google Drive as Default Media Upload Storage." and save it.'; 
  40. $fileku['name'] = $filename; 
  41. if(file_exists($path)) {@unlink($path);} 
  42. return $fileku; 
  43. }else{ 
  44. echo '<div class="error"><p>Failed to upload <strong>'.$filename.'</strong> to Google Drive.</p></div>'; 
  45. return $file; 
  46. }else{ 
  47. return $file;