Advertisement
adczk

Forminator - upload link in thank you message

Feb 15th, 2024
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2.  
  3. add_filter( 'forminator_replace_form_data', 'wpmudev_send_uploaded_image_behavior', 10, 3 );
  4. function wpmudev_send_uploaded_image_behavior( $content, $data, $original_content ){
  5.     $submitted_data = Forminator_CForm_Front_Action::$info['field_data_array'];
  6.     $prepped_data = wp_list_pluck( $submitted_data, 'value', 'name' );
  7.     if ( $data['form_id'] != 18122 ) { // Please change the form ID.
  8.         return $content;
  9.     }
  10.    
  11.     if ( strpos( $content, '{uploaded_image}' ) !== false ) {
  12.         $field_name = 'upload-1';
  13.         if ( is_array( $prepped_data[ $field_name ] ) && ! empty( $prepped_data[ $field_name ]['file'] ) ) {
  14.             if ( is_array( $prepped_data[ $field_name ]['file']['file_url'] ) ) {
  15.                 foreach ( $prepped_data[ $field_name ]['file']['file_url'] as $k => $v ) {
  16.                     $replace_html = '<a href="'.$v.'">'.substr( $v, 0, 30 ).'...</a>';
  17.                    
  18.                     $content = str_replace( '{uploaded_image}', $replace_html, $content );
  19.                 }
  20.             } else {
  21.                 $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'">'.substr( $prepped_data[ $field_name ]['file']['file_url'], 0, 30 ).'...</a>';
  22.                        
  23.                 $content = str_replace( '{uploaded_image}', $replace_html, $content );
  24.             }
  25.         }
  26.     }
  27.     return $content;
  28. }
  29.  
  30.  
  31. ----
  32.  
  33. /*Here are also two modifications that you can apply to this code if you prefer:
  34.  
  35. 1. Show only the filename (so e.g. "image.jpg" or "something.pdf")
  36.  
  37. To do this
  38.  
  39. a) replace  this line of above code
  40.  
  41. $replace_html = '<a href="'.$v.'">'.substr( $v, 0, 30 ).'...</a>';
  42.  
  43. with this one
  44.  
  45. $replace_html = '<a href="'.$v.'">'.basename( parse_url( $v, PHP_URL_PATH ) ).'</a>';
  46.  
  47. b) and replace this line of the code
  48.  
  49. $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'">'.substr( $prepped_data[ $field_name ]['file']['file_url'], 0, 30 ).'...</a>';
  50.  
  51. with this one
  52.  
  53. $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'">'.basename( parse_url( $prepped_data[$field_name]['file']['file_url'], PHP_URL_PATH ) ).'</a>';
  54.  
  55.  
  56. 2. Show just a text link (like "CLICK HERE TO DOWNLOAD" or similar):
  57.  
  58. To do this
  59.  
  60. a) replace this line of the code
  61.  
  62. $replace_html = '<a href="'.$v.'">'.substr( $v, 0, 30 ).'...</a>';
  63.  
  64. with this one
  65.  
  66. $replace_html = '<a href="'.$v.'"> CLICK TO DOWNLOAD </a>';
  67.  
  68.  
  69. b) and replace this line of the code
  70.  
  71. $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'">'.substr( $prepped_data[ $field_name ]['file']['file_url'], 0, 30 ).'...</a>';
  72.  
  73. with this one
  74.  
  75. $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'"> CLICK TO DOWNLOAD </a>';
  76.  
  77. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement