Skip to content
Merged
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
4 changes: 2 additions & 2 deletions views/checkout/fields/field-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class="form-control wu-w-full wu-my-1 <?php echo esc_attr(trim($field->classes))

<?php if ($field->placeholder) : ?>

<option <?php checked(! $field->value); ?> class="wu-opacity-75"><?php echo esc_html($field->placeholder); ?></option>
<option <?php selected(! $field->value); ?> class="wu-opacity-75"><?php echo esc_html($field->placeholder); ?></option>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether this pattern appears elsewhere and should be corrected consistently.
rg -nP --type=php -C2 'selected\(\s*!\s*\$[A-Za-z_][A-Za-z0-9_>\-\[\]\'"]*\s*\)'

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 149


🏁 Script executed:

cat -n views/checkout/fields/field-select.php | head -70

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 2037


🏁 Script executed:

# Search for selected() calls with boolean operators, using simpler pattern
rg -n --type=php 'selected\(' views/checkout/fields/ -A1 -B1

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 544


Add explicit value attribute to placeholder option and fix falsy comparison

Line 45 uses selected(! $field->value) which incorrectly selects the placeholder when $field->value is a falsy but valid value like the string '0'. Additionally, the placeholder option lacks a value attribute. Use proper two-argument comparison instead:

Suggested fix
-	<option <?php selected(! $field->value); ?> class="wu-opacity-75"><?php echo esc_html($field->placeholder); ?></option>
+	<option value="" <?php selected('', (string) $field->value); ?> class="wu-opacity-75"><?php echo esc_html($field->placeholder); ?></option>
📝 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
<option <?php selected(! $field->value); ?> class="wu-opacity-75"><?php echo esc_html($field->placeholder); ?></option>
<option value="" <?php selected('', (string) $field->value); ?> class="wu-opacity-75"><?php echo esc_html($field->placeholder); ?></option>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@views/checkout/fields/field-select.php` at line 45, The placeholder <option>
currently lacks a value attribute and uses selected(! $field->value) which
mis-selects when $field->value is a falsy but valid value (e.g., "0"); update
the option to include an explicit value (e.g., value="") and replace the
boolean-negation selected call with the two-argument comparison
selected($field->value, '') so selection only occurs when the actual field value
equals the empty placeholder; target the <option> line that echoes
esc_html($field->placeholder) and the selected(...) invocation to make this
change.


<?php endif; ?>

<?php foreach ($field->options as $key => $label) : ?>

<option
value="<?php echo esc_attr($key); ?>"
<?php checked($key, $field->value); ?>
<?php selected($key, $field->value); ?>
>
<?php echo esc_html($label); ?>
</option>
Expand Down
Loading