-
Notifications
You must be signed in to change notification settings - Fork 146
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
base: develop
Are you sure you want to change the base?
Conversation
# Bug detail When sending emails for creating or updating posts, the function prepare_mail_body() in the Frontend_Form_Ajax class sometimes causes the email body to display the output of wp_get_attachment_url() for related posts instead of showing the meta_value.
WalkthroughThe Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range and nitpick comments (1)
includes/Ajax/Frontend_Form_Ajax.php (1)
739-739
: Validate the handling of theaddress_field
meta key.It appears there is special handling for an
address_field
meta key, but this is done outside the main loop and might not apply correctly if$use_attachment_url
is true. Ensure this special case is integrated properly into the main logic flow to avoid unexpected behavior.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- includes/Ajax/Frontend_Form_Ajax.php (3 hunks)
Additional comments not posted (1)
includes/Ajax/Frontend_Form_Ajax.php (1)
672-694
: Refactor the retrieval and processing of custom fields to improve performance.
[REFACTOR_SUGGESTion]
The current implementation retrieves all posts of typewpuf_input
and then iterates through them to find a match for each custom field. This can be inefficient, especially with a large number of posts or custom fields. Consider refactoring this to use a more direct query or caching mechanism to reduce database load.// Suggested refactor to use a direct query with caching $meta_key = 'your_meta_key_here'; // This should be dynamically set based on context $cached_input_types = wp_cache_get($meta_key, 'wpuf_input_types'); if (false === $cached_input_types) { $input_types = new WP_Query([ 'post_type' => 'wpuf_input', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => [ [ 'key' => 'name', 'value' => $meta_key, 'compare' => '=' ] ] ]); $cached_input_types = $input_types->posts; wp_cache_set($meta_key, $cached_input_types, 'wpuf_input_types'); } // Use $cached_input_types for further processing
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 ) { |
There was a problem hiding this comment.
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;
}
there could be an optimised approach. can you share the bug details in a video please @egushinnosuke ? |
@sapayth please check below |
Bug detail
When sending emails for creating or updating posts, the function prepare_mail_body() in the Frontend_Form_Ajax class sometimes causes the email body to display the output of wp_get_attachment_url() for related posts instead of showing the meta_value.
Summary by CodeRabbit