Skip to content

Conversation

@arifulhoque7
Copy link
Contributor

@arifulhoque7 arifulhoque7 commented Aug 28, 2025

Related PR in PRO
Close issue

Summary by CodeRabbit

  • New Features

    • Added support for displaying multiselect values inside repeatable fields.
  • Bug Fixes

    • Toggle settings now behave consistently across different truthy values.
    • Improved consistency when rendering textarea and repeated field values.
  • Chores

    • Hardened internal database operations using prepared statements.
    • Updated translation template (POT) to reflect latest source references.

@arifulhoque7 arifulhoque7 self-assigned this Aug 28, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 28, 2025

Walkthrough

Introduces toggle value normalization in post form settings, adjusts textarea field data handling by removing a type guard, updates repeat field rendering to support multiselect and removes prior preprocessing, switches WooCommerce review updates to a prepared statement, and refreshes POT metadata/source references.

Changes

Cohort / File(s) Summary of Changes
Form builder settings normalization
admin/form-builder/views/post-form-settings.php
Normalizes toggle values to literal 'on' using wpuf_is_checkbox_or_toggle_on() before checked-state evaluation.
Textarea field data handling
includes/Fields/Form_Field_Textarea.php
Removes early non-string guard; now unconditionally applies implode(',', $data). Alters behavior for non-array/non-string inputs.
Repeat/custom fields rendering
wpuf-functions.php
Removes legacy preprocessing of repeat values; adds explicit multiselect handling inside repeats; keeps checkbox/radio/select handling; minor indentation change for UL.
WooCommerce reviews update path
includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php
Replaces direct SQL assignment with $wpdb->prepare inside a query call to update comment_status; prior raw SQL line commented out.
Localization references update
languages/wp-user-frontend.pot
Updates POT creation date and source reference mappings; no msgid/msgstr content changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

needs: developer feedback

Suggested reviewers

  • Rubaiyat-E-Mohammad
  • sapayth

Poem

I twitch my whiskers at toggles now “on,”
Arrays hop together, comma-trails long.
Repeats learn to juggle multiselect cheer,
Woo reviews prepared—safe burrows, no fear.
POTs are stirred, timestamps align—
Thump-thump! says the rabbit: ship time is fine. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
wpuf-functions.php (1)

1203-1212: Guard non-scalar repeat inner values to avoid “Array to string conversion”.

If a repeat inner field (e.g., select with multiple, or unexpected array) slips through, make_clickable( $inner_field_value ) will emit notices. Coerce arrays to strings before rendering.

Apply:

-                                    } elseif ( 'radio' === $inner_field['input_type'] || 'select' === $inner_field['input_type'] ) {
-                                        // For radio and select fields, display single value
-                                        $repeat_html .= '<span>' . make_clickable( $inner_field_value ) . '</span>';
+                                    } elseif ( 'radio' === $inner_field['input_type'] || 'select' === $inner_field['input_type'] ) {
+                                        // For radio and select fields, coerce arrays defensively
+                                        $val = is_array( $inner_field_value ) ? implode( ', ', $inner_field_value ) : $inner_field_value;
+                                        $repeat_html .= '<span>' . make_clickable( $val ) . '</span>';
                                     } else {
-                                        // For text and other fields
-                                        $repeat_html .= '<span>' . make_clickable( $inner_field_value ) . '</span>';
+                                        // For text and other fields
+                                        $val = is_array( $inner_field_value ) ? implode( ', ', $inner_field_value ) : $inner_field_value;
+                                        $repeat_html .= '<span>' . make_clickable( $val ) . '</span>';
                                     }
🧹 Nitpick comments (2)
admin/form-builder/views/post-form-settings.php (2)

387-390: Good: normalize toggle truthy states before rendering.

Ensures '1'/'yes'/'true' display as checked consistently.

You can make the state explicit:

- if ( wpuf_is_checkbox_or_toggle_on( $toggle_value ) ) {
-     $toggle_value = 'on';
- }
+ $toggle_value = wpuf_is_checkbox_or_toggle_on( $toggle_value ) ? 'on' : 'off';

301-337: Avoid double-fetching $value from $form_settings.

$value is reassigned from $form_settings twice (Lines 325–329 and 333–336). This can be simplified to one lookup to reduce branching and confusion.

-    // replace default value if already saved in DB
-    if ( ! empty( $field['name'] ) ) {
-        preg_match('/wpuf_settings\[(.*?)\]\[(.*?)\]/', $field['name'], $matches);
-        if (isset($matches[1]) && isset($matches[2])) {
-            $dynamic_key = $matches[1];
-            $temp_key    = $matches[2];
-            $value       = isset( $form_settings[ $dynamic_key ][ $temp_key ] ) ? $form_settings[ $dynamic_key ][ $temp_key ] : $value;
-        }
-    } else {
-        $value = isset( $form_settings[ $field_key ] ) ? $form_settings[ $field_key ] : $value;   // checking with isset because saved value can be empty string
-    }
-
-    // if the field is a pro fields preview, no need to load fields from db
-    if ( $is_pro_preview ) {
-        $value = ! empty( $field['value'] ) ? $field['value'] : $value;
-    } else {
-        $value = isset( $form_settings[ $field_key ] ) ? $form_settings[ $field_key ] : $value;   // checking with isset because saved value can be empty string
-    }
+    // Resolve saved value once
+    if ( ! empty( $field['name'] ) && preg_match( '/wpuf_settings\[(.*?)\]\[(.*?)\]/', $field['name'], $m ) === 1 ) {
+        $value = isset( $form_settings[ $m[1] ][ $m[2] ] ) ? $form_settings[ $m[1] ][ $m[2] ] : $value;
+    } else {
+        $value = isset( $form_settings[ $field_key ] ) ? $form_settings[ $field_key ] : $value;
+    }
+    // For pro previews, prefer provided demo value
+    if ( $is_pro_preview && isset( $field['value'] ) ) {
+        $value = $field['value'];
+    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 80de1df and 1ba6e96.

📒 Files selected for processing (3)
  • admin/form-builder/views/post-form-settings.php (1 hunks)
  • includes/Fields/Form_Field_Textarea.php (0 hunks)
  • wpuf-functions.php (1 hunks)
💤 Files with no reviewable changes (1)
  • includes/Fields/Form_Field_Textarea.php
🧰 Additional context used
🧬 Code graph analysis (1)
admin/form-builder/views/post-form-settings.php (1)
wpuf-functions.php (1)
  • wpuf_is_checkbox_or_toggle_on (5592-5594)
🪛 GitHub Actions: Inspections
admin/form-builder/views/post-form-settings.php

[error] 1-1: PHP_CodeSniffer (phpcs) error: There must be one blank line after the namespace declaration. Command: vendor/bin/phpcs admin/form-builder/views/post-form-settings.php includes/Fields/Form_Field_Textarea.php wpuf-functions.php -q --report=checkstyle | cs2pr --graceful-warnings

🔇 Additional comments (2)
wpuf-functions.php (1)

1183-1183: Repeat field UL re-indent: OK

No functional change here; markup remains the same.

admin/form-builder/views/post-form-settings.php (1)

1-1: Namespace blank-line sniff not applicable
No namespace declarations exist in admin/form-builder/views/post-form-settings.php, includes/Fields/Form_Field_Textarea.php, or wpuf-functions.php; the “blank line after namespace” error must originate from a different file.

Likely an incorrect or invalid review comment.

@arifulhoque7 arifulhoque7 force-pushed the fix/profile-form-multistep-toggle branch from ab88de9 to e34634e Compare August 28, 2025 09:40
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php (2)

29-36: Silence unused parameter warnings by convention.

Prefix unused args to satisfy analyzers without changing the hook signature.

-    public function sync_product_gallery( $post_id, $form_id, $form_settings, $meta_vars = [] ) {
+    public function sync_product_gallery( $post_id, $_form_id, $_form_settings, $_meta_vars = [] ) {

7-7: Fix PHPCS: trailing whitespace.

Trim trailing spaces on these lines to satisfy the PHPCS inspection.

Also applies to: 11-11, 16-16, 20-20, 34-34, 37-37, 46-46, 48-48, 52-52, 60-60

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ab88de9 and e34634e.

📒 Files selected for processing (3)
  • includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php (0 hunks)
  • includes/Integrations.php (1 hunks)
  • includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php (1 hunks)
💤 Files with no reviewable changes (1)
  • includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php
🧰 Additional context used
🧬 Code graph analysis (1)
includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php (3)
includes/Integrations.php (2)
  • Integrations (10-58)
  • __construct (29-40)
includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php (1)
  • __construct (12-253)
includes/Traits/FieldableTrait.php (1)
  • update_post_meta (337-447)
🪛 PHPMD (2.15.0)
includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php

29-29: Avoid unused parameters such as '$form_id'. (Unused Code Rules)

(UnusedFormalParameter)


29-29: Avoid unused parameters such as '$form_settings'. (Unused Code Rules)

(UnusedFormalParameter)


29-29: Avoid unused parameters such as '$meta_vars'. (Unused Code Rules)

(UnusedFormalParameter)

🪛 GitHub Check: Run PHPCS inspection
includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php

[failure] 60-60:
Whitespace found at end of line


[failure] 52-52:
Whitespace found at end of line


[failure] 48-48:
Whitespace found at end of line


[failure] 46-46:
Whitespace found at end of line


[failure] 37-37:
Whitespace found at end of line


[failure] 34-34:
Whitespace found at end of line


[warning] 29-29:
The method parameter $meta_vars is never used


[warning] 29-29:
The method parameter $form_settings is never used


[warning] 29-29:
The method parameter $form_id is never used


[failure] 20-20:
Whitespace found at end of line


[failure] 16-16:
Whitespace found at end of line


[failure] 11-11:
Whitespace found at end of line


[failure] 7-7:
Whitespace found at end of line

🔇 Additional comments (3)
includes/Integrations.php (2)

26-26: WooCommerce integration wiring looks correct; confirm load order.

If Integrations is constructed before WooCommerce loads, class_exists('WooCommerce') will be false and the integration won’t initialize. Verify construction happens after plugins_loaded (or re-scan then).


26-26: Scope drift vs PR title.

Title mentions “Profile Form Multistep Toggle,” but this adds a WooCommerce gallery sync integration. Confirm scope or split PR for clarity.

includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php (1)

12-19: Hooks look appropriate for when meta is available.

Good choice of WPUF post insert/update and product save hooks.

Comment on lines 43 to 51
public function sync_gallery_on_save( $post_id ) {
// Avoid infinite loops
remove_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );

$this->sync_gallery_images( $post_id );

// Re-add the action
add_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Guard autosaves/revisions and ensure hook is always restored.

Prevents unnecessary work and guarantees the hook is re-added even if something fails.

-    public function sync_gallery_on_save( $post_id ) {
-        // Avoid infinite loops
-        remove_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
-        
-        $this->sync_gallery_images( $post_id );
-        
-        // Re-add the action
-        add_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
-    }
+    public function sync_gallery_on_save( $post_id ) {
+        if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
+            return;
+        }
+        // Avoid infinite loops
+        remove_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
+        try {
+            $this->sync_gallery_images( $post_id );
+        } finally {
+            // Re-add the action
+            add_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
+        }
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function sync_gallery_on_save( $post_id ) {
// Avoid infinite loops
remove_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
$this->sync_gallery_images( $post_id );
// Re-add the action
add_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
}
public function sync_gallery_on_save( $post_id ) {
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
return;
}
// Avoid infinite loops
remove_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
try {
$this->sync_gallery_images( $post_id );
} finally {
// Re-add the action
add_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
}
}
🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[failure] 48-48:
Whitespace found at end of line


[failure] 46-46:
Whitespace found at end of line

🤖 Prompt for AI Agents
In includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php around lines 43 to
51, the save_post handler does not guard against autosaves/revisions and can
fail to re-add the hook if an exception occurs; update sync_gallery_on_save to
early-return for autosaves and revisions (use wp_is_post_autosave and
wp_is_post_revision or check DOING_AUTOSAVE), optionally validate the post type
is 'product' and post ID is valid, then wrap the call to sync_gallery_images in
a try/finally so add_action is always executed to re-register the handler even
on error.

Comment on lines 58 to 81
private function sync_gallery_images( $post_id ) {
$images = get_post_meta( $post_id, '_product_image', true );

if ( ! empty( $images ) ) {
// Handle serialized data
if ( is_string( $images ) && is_serialized( $images ) ) {
$images = maybe_unserialize( $images );
}

// Ensure we have an array
if ( ! is_array( $images ) ) {
$images = [ $images ];
}

// Filter out empty values
$images = array_filter( $images, function( $img ) {
return ! empty( $img ) && ( is_numeric( $img ) || is_string( $img ) );
});

// Update WooCommerce gallery meta
if ( ! empty( $images ) ) {
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $images ) );
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Sanitize to numeric IDs only, dedupe, and clear gallery when empty.

Current filter permits arbitrary strings and never clears stale galleries.

-    private function sync_gallery_images( $post_id ) {
-        $images = get_post_meta( $post_id, '_product_image', true );
-        
-        if ( ! empty( $images ) ) {
-            // Handle serialized data
-            if ( is_string( $images ) && is_serialized( $images ) ) {
-                $images = maybe_unserialize( $images );
-            }
-            
-            // Ensure we have an array
-            if ( ! is_array( $images ) ) {
-                $images = [ $images ];
-            }
-            
-            // Filter out empty values
-            $images = array_filter( $images, function( $img ) {
-                return ! empty( $img ) && ( is_numeric( $img ) || is_string( $img ) );
-            });
-            
-            // Update WooCommerce gallery meta
-            if ( ! empty( $images ) ) {
-                update_post_meta( $post_id, '_product_image_gallery', implode( ',', $images ) );
-            }
-        }
-    }
+    private function sync_gallery_images( $post_id ) {
+        $images = get_post_meta( $post_id, '_product_image', true );
+
+        // Normalize into a flat list of numeric IDs
+        if ( is_string( $images ) ) {
+            $images = wp_parse_id_list( $images );
+        } elseif ( is_array( $images ) ) {
+            $images = array_map(
+                static function ( $img ) {
+                    if ( is_array( $img ) ) {
+                        $img = $img['id'] ?? $img['attachment_id'] ?? null;
+                    }
+                    return absint( $img );
+                },
+                $images
+            );
+        } else {
+            $images = [];
+        }
+
+        // Dedupe and drop empties/invalids
+        $images = array_values( array_filter( array_unique( array_map( 'absint', $images ) ) ) );
+
+        if ( $images ) {
+            update_post_meta( $post_id, '_product_image_gallery', implode( ',', $images ) );
+        } else {
+            delete_post_meta( $post_id, '_product_image_gallery' );
+        }
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private function sync_gallery_images( $post_id ) {
$images = get_post_meta( $post_id, '_product_image', true );
if ( ! empty( $images ) ) {
// Handle serialized data
if ( is_string( $images ) && is_serialized( $images ) ) {
$images = maybe_unserialize( $images );
}
// Ensure we have an array
if ( ! is_array( $images ) ) {
$images = [ $images ];
}
// Filter out empty values
$images = array_filter( $images, function( $img ) {
return ! empty( $img ) && ( is_numeric( $img ) || is_string( $img ) );
});
// Update WooCommerce gallery meta
if ( ! empty( $images ) ) {
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $images ) );
}
}
private function sync_gallery_images( $post_id ) {
$images = get_post_meta( $post_id, '_product_image', true );
// Normalize into a flat list of numeric IDs
if ( is_string( $images ) ) {
$images = wp_parse_id_list( $images );
} elseif ( is_array( $images ) ) {
$images = array_map(
static function ( $img ) {
if ( is_array( $img ) ) {
$img = $img['id'] ?? $img['attachment_id'] ?? null;
}
return absint( $img );
},
$images
);
} else {
$images = [];
}
// Dedupe and drop empties/invalids
$images = array_values( array_filter( array_unique( array_map( 'absint', $images ) ) ) );
if ( $images ) {
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $images ) );
} else {
delete_post_meta( $post_id, '_product_image_gallery' );
}
}
🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[failure] 60-60:
Whitespace found at end of line

🤖 Prompt for AI Agents
In includes/Integrations/WPUF_WooCommerce_Gallery_Sync.php around lines 58 to
81, the gallery sync accepts arbitrary strings and never clears stale galleries;
change the filter to accept only numeric attachment IDs (cast values to int),
remove non-positive IDs, deduplicate the list (preserve order), and then update
the _product_image_gallery meta with a comma-separated string of unique numeric
IDs; if the resulting array is empty, explicitly update_post_meta with an empty
string to clear the gallery.

Copy link

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php (1)

304-311: Prefer WC CRUD or wp_update_post to keep caches and hooks consistent.

Direct SQL bypasses WP/WC hooks and object cache. Use WooCommerce’s product API (preferred) or wp_update_post(); both ensure proper invalidation and side effects.

-    public function update_reviews( $post_id ) {
-        global $wpdb;
-        $reviews = get_post_meta( $post_id, 'product_reviews', true );
-        $status  = ! empty( $reviews ) ? 'open' : 'closed';
-        //$comment_sql = "UPDATE {$wpdb->prefix}posts SET comment_status='{$status}' WHERE ID={$post_id} AND post_status='publish' AND post_type='product'";
-        $wpdb->get_results( $wpdb->prepare( "UPDATE {$wpdb->prefix}posts SET comment_status=%s WHERE ID=%d AND post_status='publish' AND post_type='product'", $status, $post_id ) );
-    }
+    public function update_reviews( $post_id ) {
+        $reviews = get_post_meta( $post_id, 'product_reviews', true );
+        $status  = ! empty( $reviews ) ? 'open' : 'closed';
+
+        // Prefer WC CRUD to update reviews (maintains hooks/cache).
+        if ( function_exists( 'wc_get_product' ) ) {
+            $product = wc_get_product( $post_id );
+            if ( $product ) {
+                $product->set_reviews_allowed( 'open' === $status );
+                $product->save();
+                return;
+            }
+        }
+
+        // Fallback to core API.
+        wp_update_post( array( 'ID' => $post_id, 'comment_status' => $status ) );
+    }
🧹 Nitpick comments (1)
includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php (1)

309-309: Remove dead commented SQL.

The commented $comment_sql line adds noise; drop it.

-        //$comment_sql = "UPDATE {$wpdb->prefix}posts SET comment_status='{$status}' WHERE ID={$post_id} AND post_status='publish' AND post_type='product'";
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d60efc1 and 3543b44.

📒 Files selected for processing (1)
  • includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php (1 hunks)
🔇 Additional comments (1)
includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php (1)

310-311: Confirm WHERE constraints won’t block valid updates.

Requiring post_status='publish' and post_type='product' is redundant with ID=%d and may prevent toggling reviews for drafts/pending products. Verify intended behavior and drop extra predicates if unnecessary.

Comment on lines 310 to 311
$wpdb->get_results( $wpdb->prepare( "UPDATE {$wpdb->prefix}posts SET comment_status=%s WHERE ID=%d AND post_status='publish' AND post_type='product'", $status, $post_id ) );
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use $wpdb->query (or $wpdb->update) for UPDATE; get_results is the wrong API, and prefer $wpdb->posts over string interpolation.

get_results() is intended for SELECT-like queries; here it still executes but discards the affected-rows result and is semantically misleading. Also, reference the posts table via $wpdb->posts.

-        $wpdb->get_results( $wpdb->prepare( "UPDATE {$wpdb->prefix}posts SET comment_status=%s WHERE ID=%d AND post_status='publish' AND post_type='product'", $status, $post_id ) );
+        $wpdb->query(
+            $wpdb->prepare(
+                "UPDATE {$wpdb->posts} SET comment_status = %s WHERE ID = %d AND post_status = 'publish' AND post_type = 'product'",
+                $status,
+                $post_id
+            )
+        );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$wpdb->get_results( $wpdb->prepare( "UPDATE {$wpdb->prefix}posts SET comment_status=%s WHERE ID=%d AND post_status='publish' AND post_type='product'", $status, $post_id ) );
}
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->posts} SET comment_status = %s WHERE ID = %d AND post_status = 'publish' AND post_type = 'product'",
$status,
$post_id
)
);
}
🤖 Prompt for AI Agents
In includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php around
lines 310-311, the code uses $wpdb->get_results for an UPDATE and interpolates
the table name; replace this with the proper $wpdb API and table constant: call
$wpdb->update against $wpdb->posts (or use $wpdb->query with a prepared UPDATE)
so the function semantics match (returning affected rows) and avoid
string-interpolating {$wpdb->prefix}; pass the data array and where conditions
(ID => $post_id plus the post_status and post_type constraints) to $wpdb->update
or, if using $wpdb->query, use $wpdb->prepare with $wpdb->posts in the query
string.

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added QA Approved This PR is approved by the QA team and removed bug labels Sep 1, 2025
@sapayth sapayth merged commit 4853246 into weDevsOfficial:develop Sep 1, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants