Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mail body replace text bug #1460

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions includes/Ajax/Frontend_Form_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,30 @@ public function prepare_mail_body( $content, $user_id, $post_id ) {
preg_match_all( '/%custom_([\w-]*)\b%/', $content, $matches );
[ $search, $replace ] = $matches;

$args = array(
'post_type' => 'wpuf_input',
'posts_per_page' => -1
);
$wpuf_posts = get_posts($args);

if ( $replace ) {
foreach ( $replace as $index => $meta_key ) {
$input_type = '';
foreach ($wpuf_posts as $post) {
$post_content = $post->post_content;
$data = unserialize($post_content);
if ($data['name'] == $meta_key){
$input_type = $data['input_type'];
break;
}
}

$use_attachment_url = false;
if ($input_type == "image_upload" || $input_type == "file_upload"){
$use_attachment_url = true;
}


$value = get_post_meta( $post_id, $meta_key, false );

if ( isset( $value[0] ) && is_array( $value[0] ) ) {
Expand All @@ -687,21 +709,21 @@ public function prepare_mail_body( $content, $user_id, $post_id ) {

foreach ( $value as $val ) {
if ( $is_first ) {
if ( get_post_mime_type( (int) $val ) ) {
if ( $use_attachment_url ) {
$meta_val = wp_get_attachment_url( $val );
} else {
$meta_val = $val;
}
$is_first = false;
} else {
if ( get_post_mime_type( (int) $val ) ) {
if ( $use_attachment_url ) {
$meta_val = $meta_val . ', ' . wp_get_attachment_url( $val );
} else {
$meta_val = $meta_val . ', ' . $val;
}
}

if ( get_post_mime_type( (int) $val ) ) {
if ( $use_attachment_url ) {
Comment on lines +712 to +726
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistent handling of attachment URLs.

The logic for appending attachment URLs seems inconsistent. In some cases, you use a comma for separation, and in others, you do not. This could lead to malformed strings when multiple values are present. Ensure consistency in how values are concatenated.

// Corrected logic for consistent comma usage
if ($use_attachment_url) {
    $meta_val = $meta_val . (empty($meta_val) ? '' : ', ') . wp_get_attachment_url($val);
} else {
    $meta_val = $meta_val . (empty($meta_val) ? '' : ', ') . $val;
}

$meta_val = $meta_val . ',' . wp_get_attachment_url( $val );
} else {
$meta_val = $meta_val . ',' . $val;
Expand All @@ -714,7 +736,7 @@ public function prepare_mail_body( $content, $user_id, $post_id ) {
$new_value = implode( ', ', $value );
}

if ( get_post_mime_type( (int) $new_value ) ) {
if ( $use_attachment_url ) {
$original_value = wp_get_attachment_url( $new_value );
} else {
$original_value = $new_value;
Expand Down