CodeDropz

Base64 Encode - For CF7

Aug 14th, 2020 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. // paste this code inside your wp-content/themes/{themename}/functions.php
  2. add_action('wpcf7_posted_data', function( $posted_data ){
  3.  
  4.     // Subbmisson instance from CF7
  5.     $submission = WPCF7_Submission::get_instance();
  6.  
  7.     // Make sure we have the data
  8.     if ( ! $posted_data ) {
  9.         $posted_data = $submission->get_posted_data();
  10.     }
  11.  
  12.     // @note : change the name of your upload field.
  13.     $file_upload_name = 'uploader-249';
  14.  
  15.     if( isset( $posted_data[ $file_upload_name ] ) ) {
  16.         foreach( $posted_data[ $file_upload_name ] as $index => $file ) {
  17.             if( wpcf7_is_url( $file ) ) {
  18.                 $posted_data["$file_upload_name"][$index] = base64_encode( file_get_contents( $file ) );
  19.             }
  20.         }
  21.     }
  22.    
  23.     return $posted_data;
  24.  
  25. },100, 1 );
Add Comment
Please, Sign In to add comment