Skip to content

Prefer str_contains over strpos where applicable#2727

Merged
Crabcyborg merged 1 commit into
masterfrom
prefer_str_contains_to_strpos
Jan 6, 2026
Merged

Prefer str_contains over strpos where applicable#2727
Crabcyborg merged 1 commit into
masterfrom
prefer_str_contains_to_strpos

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

No description provided.

@Crabcyborg Crabcyborg added this to the 6.27 milestone Jan 6, 2026
@Crabcyborg Crabcyborg changed the title Prefer str_contains to strpos Prefer str_contains to strpos where applicable Jan 6, 2026
@Crabcyborg Crabcyborg changed the title Prefer str_contains to strpos where applicable Prefer str_contains to strpos where applicable Jan 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 6, 2026

Walkthrough

This pull request systematically replaces strpos() string containment checks with str_contains() across 18 files. Each replacement fixes potential bugs where substrings at position 0 would previously evaluate as falsy, ensuring consistent boolean results when checking for substring presence.

Changes

Cohort / File(s) Summary
Controllers
classes/controllers/FrmAddonsController.php, FrmDeactivationFeedbackController.php, FrmFieldsController.php, FrmFormsController.php
Replaced strpos() with str_contains() for hyphen detection, 'formidable.php' inclusion, equals sign detection, and captcha-api handle checking. Fixes edge cases where substrings appear at position 0.
Helper – String Utilities
classes/helpers/FrmAppHelper.php
Replaced strpos() with str_contains() in get_param() (bracket detection) and icon_by_class() (space detection).
Helper – Email Processing
classes/helpers/FrmEmailSummaryHelper.php
Replaced strpos() with str_contains() in process_inbox_cta_button() for inline style and button-class detection.
Helper – List & Fields
classes/helpers/FrmEntriesListHelper.php, FrmFieldsHelper.php
Replaced strpos() with str_contains() in column-name parsing (-_- detection) and field-type processing (pipe, bracket, and CSS-class detection).
Helper – Forms & XML
classes/helpers/FrmFormsHelper.php, FrmXMLHelper.php
Replaced strpos() with str_contains() for shortcode detection ([button_action], [button_label], conditional shortcodes) and email-field pipe-delimiter detection.
Models – File & Email
classes/models/FrmCreateFile.php, FrmEmail.php
Replaced strpos() with str_contains() in FTP hostname-colon detection and Yahoo email-address detection.
Models – Entry & Validation
classes/models/FrmEntryMeta.php, FrmEntryValidate.php
Replaced strpos() with str_contains() in GROUP BY clause detection and email-address at-sign detection.
Models – Field HTML & Migration
classes/models/FrmFieldFormHtml.php, FrmMigrate.php
Replaced strpos() with str_contains() for ID-attribute, collapse-shortcode, form-field-class detection, and version/size/submit-html string checks.
Models – Field Number
classes/models/fields/FrmFieldNumber.php
Replaced strpos() with str_contains() in comma-removal check within remove_commas_from_number().
Autoloader & Stripe
formidable.php, stripe/models/FrmStrpLiteAuth.php
Replaced strpos() with str_contains() in Field-class detection (autoloader) and form-ID hidden-input detection (Stripe module).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

run analysis, run tests

Suggested reviewers

  • truongwp
  • lauramekaj1

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess whether a description exists and relates to the changeset. Add a pull request description explaining the rationale for preferring str_contains and the bug fixes this change provides.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 96.43% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly and directly summarizes the main change: replacing strpos() calls with str_contains() across multiple files.
✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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

Caution

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

⚠️ Outside diff range comments (1)
classes/helpers/FrmAppHelper.php (1)

736-743: Critical: str_contains() requires PHP 8.0+ but plugin declares PHP 7.0 minimum

The use of str_contains() at lines 737 and 1393 creates a fatal compatibility issue. This function is native to PHP 8.0+ only and does not exist in PHP 7.x. The plugin's readme.txt declares "Requires PHP: 7.0", meaning installations on PHP 7.x will fail at runtime.

Either:

  • Update readme.txt to require PHP 8.0 or higher, or
  • Add a polyfill: if ( ! function_exists( 'str_contains' ) ) { function str_contains( $haystack, $needle ) { return strpos( $haystack, $needle ) !== false; } }
🤖 Fix all issues with AI Agents
In @classes/helpers/FrmXMLHelper.php:
- Line 2270: The code uses PHP 8's str_contains() on $email_field which breaks
PHP 7 compatibility; replace occurrences of str_contains( $email_field, '|' )
with the PHP 7-compatible check strpos( $email_field, '|' ) !== false (also
update the other instance noted around the code location referenced as 2358).
Ensure you change both usages of str_contains to the strpos !== false pattern so
behavior remains identical.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de67430 and 8b6f2d9.

📒 Files selected for processing (19)
  • classes/controllers/FrmAddonsController.php
  • classes/controllers/FrmDeactivationFeedbackController.php
  • classes/controllers/FrmFieldsController.php
  • classes/controllers/FrmFormsController.php
  • classes/helpers/FrmAppHelper.php
  • classes/helpers/FrmEmailSummaryHelper.php
  • classes/helpers/FrmEntriesListHelper.php
  • classes/helpers/FrmFieldsHelper.php
  • classes/helpers/FrmFormsHelper.php
  • classes/helpers/FrmXMLHelper.php
  • classes/models/FrmCreateFile.php
  • classes/models/FrmEmail.php
  • classes/models/FrmEntryMeta.php
  • classes/models/FrmEntryValidate.php
  • classes/models/FrmFieldFormHtml.php
  • classes/models/FrmMigrate.php
  • classes/models/fields/FrmFieldNumber.php
  • formidable.php
  • stripe/models/FrmStrpLiteAuth.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Cypress
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: Cypress
🔇 Additional comments (25)
classes/controllers/FrmDeactivationFeedbackController.php (1)

61-64: LGTM!

The migration to str_contains() correctly handles plugin path detection, fixing the edge case where the plugin filename could appear at position 0.

classes/models/FrmCreateFile.php (1)

265-265: LGTM!

The migration to str_contains() correctly handles colon detection for hostname:port parsing, fixing the edge case where a malformed hostname starting with ':' would be treated as not containing a colon.

stripe/models/FrmStrpLiteAuth.php (1)

120-120: LGTM!

The migration to str_contains() correctly handles form ID detection in HTML, fixing the edge case where the hidden input appears at the start of the HTML string.

classes/controllers/FrmAddonsController.php (1)

454-458: LGTM!

The migration to str_contains() correctly handles hyphen detection in license keys for normalization, fixing the edge case where a hyphen at position 0 would be falsy. The added blank line improves readability.

classes/controllers/FrmFormsController.php (1)

3528-3533: str_contains-based defer check is correct and safer

The updated condition using str_contains( $tag, 'defer' ) preserves the original intent (only inject attributes once) and avoids the classic strpos() === 0 pitfall. No behavioral or compatibility concerns within this method.

classes/helpers/FrmEntriesListHelper.php (1)

519-557: Embedded field parsing with str_contains is correct

Using str_contains( $col_name, '-_-' ) before the explode() keeps the previous behavior, handles delimiters at any position (including index 0), and keeps $embedded_field_id guarded by the existing isset() check. No issues here.

classes/models/fields/FrmFieldNumber.php (1)

165-170: Comma detection for numeric fields now uses str_contains correctly

str_contains( $args['value'], ',' ) is an appropriate replacement for the old comma check and works as expected given $args['value'] is treated as a string throughout validation. No behavioral regressions introduced.

classes/models/FrmEmail.php (1)

716-741: Yahoo sender detection via str_contains is correct

The updated Yahoo-domain check using str_contains( $from_email, '@yahoo.com' ) keeps the same intent—rewriting problematic Yahoo From addresses to the WordPress default—while simplifying the conditional. No functional issues introduced.

formidable.php (1)

101-101: LGTM: Correctly handles edge case for class names starting with "Field".

The change from strpos() to str_contains() ensures correct behavior when a class name starts with "Field" (e.g., FieldCustomType). The previous implementation would return 0 (falsy) for such cases, potentially skipping the fields directory check.

classes/models/FrmMigrate.php (3)

379-379: LGTM: Improved dash detection in version strings.

The str_contains() replacement correctly handles the edge case where a dash might appear at the beginning of $old_db_version.


670-670: LGTM: Improved 'px' detection in size values.

The str_contains() replacement correctly handles the edge case where 'px' might appear at position 0 in the $size string.


869-869: LGTM: Improved 'save_draft' detection in submit HTML.

The str_contains() replacement correctly handles the edge case where 'save_draft' might appear at the beginning of the submit HTML string.

classes/controllers/FrmFieldsController.php (1)

1005-1005: LGTM: Correctly handles shortcode values starting with '='.

The change from strpos() to str_contains() ensures correct detection of the equals sign in shortcode values, including the edge case where '=' appears at position 0.

classes/helpers/FrmFieldsHelper.php (3)

23-23: LGTM: Improved pipe detection in field types.

The str_contains() replacement correctly handles the edge case where '|' might appear at the beginning of the $type string.


1336-1336: LGTM: Improved encoded bracket detection.

The str_contains() replacement correctly handles the edge case where '[' (HTML entity for '[') might appear at position 0 in the parameter.


2381-2381: LGTM: Improved class detection in icon strings.

The str_contains() replacement correctly handles the edge case where ' frm_show_upgrade' might appear at the beginning of the icon class string.

classes/models/FrmEntryValidate.php (1)

853-853: LGTM: Improved '@' detection in email validation.

The str_contains() replacement correctly handles the edge case where '@' might appear at position 0 in the value string. While is_email() would catch invalid cases like '@example.com', using str_contains() is semantically clearer and more consistent with the rest of this PR.

classes/helpers/FrmXMLHelper.php (2)

2270-2270: LGTM! Edge case fix for delimiter detection.

The change from strpos() to str_contains() correctly handles the edge case where the delimiter | appears at position 0. The previous implementation would have incorrectly skipped delimiter parsing in that scenario.


2358-2358: LGTM! Consistent edge case fix.

This change mirrors the fix at line 2270, ensuring delimiter detection works correctly when | appears at the start of the string.

classes/helpers/FrmEmailSummaryHelper.php (1)

534-542: LGTM! Correct HTML attribute detection.

Both changes properly handle edge cases in button HTML processing:

  • Line 534: Detects existing inline styles to avoid duplication
  • Line 540: Detects button class to conditionally add styling

The str_contains() implementation ensures correct detection regardless of substring position.

classes/models/FrmFieldFormHtml.php (3)

271-271: LGTM! Prevents duplicate ID attributes.

The change correctly detects existing ID attributes to avoid duplication. The str_contains() implementation ensures detection works even if the attribute appears at the beginning of the HTML segment.


410-411: LGTM! Shortcode detection fix.

The change ensures the collapse shortcode is removed regardless of its position in the HTML string.


546-548: LGTM! Prevents duplicate CSS class.

The change correctly detects the existing frm_form_field class to prevent duplication. The implementation properly handles cases where the class appears at the start of the HTML.

classes/helpers/FrmFormsHelper.php (2)

554-557: LGTM! Correct shortcode detection.

The change ensures the [button_action] shortcode is properly detected and processed regardless of its position in the button HTML. The previous implementation would have incorrectly skipped processing if the shortcode appeared at the beginning.


934-953: LGTM! Comprehensive shortcode detection fixes.

All four changes correctly handle shortcode detection:

  • Line 934: Enables button label processing when shortcode is present
  • Lines 943, 947, 951: Conditionally remove button-related shortcodes

The str_contains() implementation ensures proper detection when shortcodes appear at the start of the HTML string, fixing potential edge cases where button labels or conditional buttons would malfunction.

Comment thread classes/helpers/FrmXMLHelper.php
Comment thread classes/models/FrmEntryMeta.php
@Crabcyborg Crabcyborg changed the title Prefer str_contains to strpos where applicable Prefer str_contains over strpos where applicable Jan 6, 2026
@Crabcyborg Crabcyborg merged commit c5d0daa into master Jan 6, 2026
35 of 36 checks passed
@Crabcyborg Crabcyborg deleted the prefer_str_contains_to_strpos branch January 6, 2026 22:46
stephywells pushed a commit that referenced this pull request Apr 4, 2026
Prefer `str_contains` over `strpos` where applicable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant