mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Code Modernization: Use str_contains() in a few more places.
`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 commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices. Follow-up to [55988], [56021]. See #58206. git-svn-id: https://develop.svn.wordpress.org/trunk@56031 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1060,13 +1060,18 @@ class WP_Rewrite {
|
||||
* 2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
|
||||
* minute all present). Set these flags now as we need them for the endpoints.
|
||||
*/
|
||||
if ( strpos( $struct, '%postname%' ) !== false
|
||||
|| strpos( $struct, '%post_id%' ) !== false
|
||||
|| strpos( $struct, '%pagename%' ) !== false
|
||||
|| ( strpos( $struct, '%year%' ) !== false && strpos( $struct, '%monthnum%' ) !== false && strpos( $struct, '%day%' ) !== false && strpos( $struct, '%hour%' ) !== false && strpos( $struct, '%minute%' ) !== false && strpos( $struct, '%second%' ) !== false )
|
||||
) {
|
||||
if ( str_contains( $struct, '%postname%' )
|
||||
|| str_contains( $struct, '%post_id%' )
|
||||
|| str_contains( $struct, '%pagename%' )
|
||||
|| ( str_contains( $struct, '%year%' )
|
||||
&& str_contains( $struct, '%monthnum%' )
|
||||
&& str_contains( $struct, '%day%' )
|
||||
&& str_contains( $struct, '%hour%' )
|
||||
&& str_contains( $struct, '%minute%' )
|
||||
&& str_contains( $struct, '%second%' ) )
|
||||
) {
|
||||
$post = true;
|
||||
if ( strpos( $struct, '%pagename%' ) !== false ) {
|
||||
if ( str_contains( $struct, '%pagename%' ) ) {
|
||||
$page = true;
|
||||
}
|
||||
}
|
||||
@@ -1074,7 +1079,7 @@ class WP_Rewrite {
|
||||
if ( ! $post ) {
|
||||
// For custom post types, we need to add on endpoints as well.
|
||||
foreach ( get_post_types( array( '_builtin' => false ) ) as $ptype ) {
|
||||
if ( strpos( $struct, "%$ptype%" ) !== false ) {
|
||||
if ( str_contains( $struct, "%$ptype%" ) ) {
|
||||
$post = true;
|
||||
|
||||
// This is for page style attachment URLs.
|
||||
@@ -1555,7 +1560,7 @@ class WP_Rewrite {
|
||||
// Apache 1.3 does not support the reluctant (non-greedy) modifier.
|
||||
$match = str_replace( '.+?', '.+', $match );
|
||||
|
||||
if ( strpos( $query, $this->index ) !== false ) {
|
||||
if ( str_contains( $query, $this->index ) ) {
|
||||
$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
|
||||
} else {
|
||||
$rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n";
|
||||
|
||||
Reference in New Issue
Block a user