You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jeherve
changed the title
Code modernization: Replace usage of substr with str_starts_with and str_ends_with https://core.trac.wordpress.org/ticket/58220
Code modernization: Replace usage of substr with str_starts_with and str_ends_withSep 5, 2023
Note we can only do that in contexts that run under WordPress. Code that is intended to be useful outside of WordPress won't have WordPress's polyfill.
Fixes#32864
str_starts_with() and str_ends_with() were introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins or ends with the given substring (needle).
WordPress core includes a polyfill for these functions on PHP < 8.0 as of WordPress 5.9.
This commit uses str_starts_with() and str_ends_with() where appropriate.
This aims to make the code more readable and consistent, as well as better aligned with modern development practices.
Note: this doesn't update uses in a few places, like the autoloader since it can be used outside of WordPress.
Matching core change: https://core.trac.wordpress.org/changeset/55990
Source: https://core.trac.wordpress.org/ticket/58220
Let's follow Core's lead once Jetpack requires WordPress 6.3.
Primary issue: #32865
The text was updated successfully, but these errors were encountered: