Make WordPress Core

Opened 5 months ago

Closed 5 months ago

Last modified 4 months ago

#65408 closed enhancement (fixed)

Code Modernization: Use str_contains() instead of strpos()

Reported by: Soean Owned by: audrasjb
Priority: normal Milestone: 7.1
Component: General Version:
Severity: normal Keywords: has-patch commit
Cc: Focuses: coding-standards

Description

str_contains() was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).

WordPress core includes a polyfill for str_contains() on PHP < 8.0 as of WordPress 5.9.

This change replaces new introduced false !== strpos( ... ) and false === strpos( ... ) with str_contains() in core files, making the code more readable and consistent, as well as better aligned with modern development practices.

Introduced in r60269 and 60939

Follow-up to [52039], [55988], [56245], [60269], [60939]

Change History (5)

This ticket was mentioned in ​PR #12085 on ​WordPress/wordpress-develop by ​@Soean.


5 months ago
#1

str_contains() was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).

WordPress core includes a polyfill for str_contains() on PHP < 8.0 as of WordPress 5.9.

This PR replaces false !== strpos( ... ) and false === strpos( ... ) with str_contains() in core files, making the code more readable and consistent, as well as better aligned with modern development practices.

Introduced in r60269 and r60939

Trac ticket: https://core.trac.wordpress.org/ticket/65408

#2 @mukesh27
5 months ago

  • Keywords commit added
  • Milestone Awaiting Review → 7.1

#3 @audrasjb
5 months ago

  • Owner set to audrasjb
  • Status new → accepted

Self assigning for commit.

#4 @audrasjb
5 months ago

  • Resolution → fixed
  • Status accepted → closed

In 62461:

Code Modernization: Replace strpos() with str_contains().

This changeset replaces recently introduced false !== strpos( ... ) and false === strpos( ... ) with str_contains() in core files, making the code more readable and consistent, as well as better aligned with modern development practices.

Introduced in [60269] and [60939]. Fixed during WCEU2026 contribution day.

Follow-up to [52039], [55988], [56245], [60269] and [60939].

Props Soean, mukesh27.
Fixes #65408.

This ticket was mentioned in ​PR #12123 on ​WordPress/wordpress-develop by ​Dervish12.


4 months ago
#5

## Summary

Replace strpos() !== false with str_contains() in the Cover block's video provider detection logic (src/wp-includes/blocks/cover.php).

str_contains() was introduced in PHP 8.0. WordPress core includes a polyfill for str_contains() on PHP < 8.0 as of WordPress 5.9.

This PR replaces strpos( $lower_src, '...' ) !== false patterns with str_contains() in the Cover block, making the code more readable and consistent, as well as better aligned with modern PHP development practices.

Follow-up to r60269 and r60939.

## Changes

  • Replaced 4 instances of strpos( $lower_src, '...' ) !== false with str_contains( $lower_src, '...' ) in the video provider detection within render_block_core_cover().

## Test plan

  • [ ] npm run test:php -- --filter='cover' — all 47 tests pass
  • [ ] ./vendor/bin/phpcs --standard=phpcs.xml.dist src/wp-includes/blocks/cover.php — no PHPCS violations
  • [ ] Verify Cover block with embedded YouTube, Vimeo, VideoPress, and WordPress.tv videos renders correctly
Note: See TracTickets for help on using tickets.