Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'forminator_replace_form_data', 'wpmudev_send_uploaded_image_behavior', 10, 3 );
- function wpmudev_send_uploaded_image_behavior( $content, $data, $original_content ){
- $submitted_data = Forminator_CForm_Front_Action::$info['field_data_array'];
- $prepped_data = wp_list_pluck( $submitted_data, 'value', 'name' );
- if ( $data['form_id'] != 18122 ) { // Please change the form ID.
- return $content;
- }
- if ( strpos( $content, '{uploaded_image}' ) !== false ) {
- $field_name = 'upload-1';
- if ( is_array( $prepped_data[ $field_name ] ) && ! empty( $prepped_data[ $field_name ]['file'] ) ) {
- if ( is_array( $prepped_data[ $field_name ]['file']['file_url'] ) ) {
- foreach ( $prepped_data[ $field_name ]['file']['file_url'] as $k => $v ) {
- $replace_html = '<a href="'.$v.'">'.substr( $v, 0, 30 ).'...</a>';
- $content = str_replace( '{uploaded_image}', $replace_html, $content );
- }
- } else {
- $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'">'.substr( $prepped_data[ $field_name ]['file']['file_url'], 0, 30 ).'...</a>';
- $content = str_replace( '{uploaded_image}', $replace_html, $content );
- }
- }
- }
- return $content;
- }
- ----
- /*Here are also two modifications that you can apply to this code if you prefer:
- 1. Show only the filename (so e.g. "image.jpg" or "something.pdf")
- To do this
- a) replace this line of above code
- $replace_html = '<a href="'.$v.'">'.substr( $v, 0, 30 ).'...</a>';
- with this one
- $replace_html = '<a href="'.$v.'">'.basename( parse_url( $v, PHP_URL_PATH ) ).'</a>';
- b) and replace this line of the code
- $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'">'.substr( $prepped_data[ $field_name ]['file']['file_url'], 0, 30 ).'...</a>';
- with this one
- $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>';
- 2. Show just a text link (like "CLICK HERE TO DOWNLOAD" or similar):
- To do this
- a) replace this line of the code
- $replace_html = '<a href="'.$v.'">'.substr( $v, 0, 30 ).'...</a>';
- with this one
- $replace_html = '<a href="'.$v.'"> CLICK TO DOWNLOAD </a>';
- b) and replace this line of the code
- $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'">'.substr( $prepped_data[ $field_name ]['file']['file_url'], 0, 30 ).'...</a>';
- with this one
- $replace_html = '<a href="'.$prepped_data[ $field_name ]['file']['file_url'].'"> CLICK TO DOWNLOAD </a>';
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement