Skip to content

fix: use sanitized value in unique field check - #7628

Open
faisalahammad wants to merge 1 commit into
pods-framework:release/3.4.0from
faisalahammad:fix/7623-unique-check-value-init
Open

fix: use sanitized value in unique field check#7628
faisalahammad wants to merge 1 commit into
pods-framework:release/3.4.0from
faisalahammad:fix/7623-unique-check-value-init

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

AI disclosure: this PR was written with GLM 5.3 flash assistance, reviewed and tested by me.

Description

Unique field validation in PodsAPI::handle_field_validation() built its query prepare array with $check_value before that variable was assigned. The $check_value = pods_sanitize( $value ) call sat a few lines below the $prepare construction, so the query always received an undefined variable. This raised a PHP "Undefined variable $check_value" warning and silently disabled unique enforcement on table storage pods, including Advanced Content Types.

The fix moves the pods_sanitize() call above the $prepare array so the uniqueness query receives the sanitized value. Pick and other tableless field types are unaffected because they take the separate tableless branch and never reach this code path.

Backward compatible: yes, no breaking changes.

Related GitHub issue(s)

Fixes #7623

Testing instructions

  1. Create an Advanced Content Type pod (for example person) with table storage.
  2. Add a text field (for example social_security_number) and enable "Unique" under its Advanced settings.
  3. Save one item with a value such as 123-45-6789.
  4. Submit a second item with the same value with WP_DEBUG_DISPLAY enabled.
  5. Before this PR: the item saves anyway and a PHP Warning: Undefined variable $check_value appears in the logs.
  6. After this PR: saving fails with the field label followed by "needs to be unique", and no warning appears.

Tested manually: confirmed this resolves the reported issue.

Screenshots / screencast

Not applicable, no UI changes.

Changelog text for these changes

Bug: Fixed Unique field validation so the sanitized value is used in the uniqueness query. Unique fields on table storage pods now correctly block duplicate values and no longer trigger a PHP warning. #7623 (@faisalahammad)

PR checklist

The unique field check built its query prepare array with $check_value
before that variable was assigned, which raised an undefined variable
warning and silently disabled unique enforcement on table storage pods.
Move the pods_sanitize() call above the prepare array so the query gets
the sanitized value.

Fixes pods-framework#7623
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant