From 2ec23a82ed4a60e12a40922f08529d9e0b9b25f4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 2 May 2023 15:45:22 +0000 Subject: [PATCH] Code Modernization: Replace usage of `strpos()` with `str_starts_with()`. `str_starts_with()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins with the given substring (needle). WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9. This commit replaces `0 === strpos( ... )` with `str_starts_with()` in core files, making the code more readable and consistent, as well as improving performance. While `strpos()` is slightly faster than the polyfill on PHP < 8.0, `str_starts_with()` is noticeably faster on PHP 8.0+, as it is optimized to avoid unnecessarily searching along the whole haystack if it does not find the needle. Follow-up to [52039], [52040], [52326]. Props spacedmonkey, costdev, sabernhardt, mukesh27, desrosj, jorbin, TobiasBg, ayeshrajans, lgadzhev, SergeyBiryukov. Fixes #58012. Built from https://develop.svn.wordpress.org/trunk@55703 git-svn-id: http://core.svn.wordpress.org/trunk@55215 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 2 +- .../includes/class-file-upload-upgrader.php | 2 +- .../includes/class-wp-media-list-table.php | 4 ++-- .../includes/class-wp-posts-list-table.php | 2 +- .../class-wp-privacy-policy-content.php | 4 ++-- wp-admin/includes/class-wp-site-health.php | 2 +- wp-admin/includes/credits.php | 2 +- wp-admin/includes/file.php | 6 +++--- wp-admin/includes/media.php | 8 ++++---- wp-admin/includes/menu.php | 2 +- wp-admin/includes/network.php | 4 ++-- wp-admin/includes/post.php | 2 +- wp-admin/includes/privacy-tools.php | 2 +- wp-admin/includes/template.php | 4 ++-- wp-admin/includes/update-core.php | 2 +- wp-admin/load-styles.php | 2 +- wp-admin/menu-header.php | 4 ++-- wp-admin/menu.php | 2 +- wp-admin/options-permalink.php | 4 ++-- wp-includes/block-template.php | 2 +- wp-includes/blocks.php | 20 +++++++++---------- wp-includes/bookmark-template.php | 2 +- wp-includes/class-simplepie.php | 2 +- wp-includes/class-wp-customize-manager.php | 2 +- wp-includes/class-wp-customize-widgets.php | 2 +- wp-includes/class-wp-query.php | 2 +- .../class-wp-recovery-mode-email-service.php | 2 +- wp-includes/class-wp-recovery-mode.php | 6 +++--- wp-includes/class-wp-scripts.php | 6 +++--- wp-includes/class-wp-styles.php | 4 ++-- wp-includes/class-wp-theme.php | 2 +- wp-includes/class-wp.php | 2 +- wp-includes/comment.php | 2 +- wp-includes/error-protection.php | 2 +- wp-includes/functions.php | 18 ++++++++--------- wp-includes/general-template.php | 2 +- wp-includes/kses.php | 2 +- wp-includes/l10n.php | 12 +++++------ wp-includes/link-template.php | 2 +- wp-includes/media.php | 4 ++-- wp-includes/pluggable.php | 6 +++--- wp-includes/plugin.php | 2 +- wp-includes/post-template.php | 2 +- wp-includes/post.php | 8 ++++---- wp-includes/rest-api.php | 4 ++-- .../rest-api/class-wp-rest-request.php | 2 +- wp-includes/rest-api/class-wp-rest-server.php | 6 +++--- wp-includes/rewrite.php | 2 +- wp-includes/script-loader.php | 2 +- wp-includes/taxonomy.php | 4 ++-- wp-includes/theme.php | 8 ++++---- wp-includes/user.php | 2 +- wp-includes/version.php | 2 +- wp-includes/widgets/class-wp-widget-block.php | 2 +- wp-login.php | 2 +- 55 files changed, 106 insertions(+), 106 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 2ed1d2e0ae..c33d6905f4 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -3749,7 +3749,7 @@ function wp_ajax_parse_embed() { $wp_embed->usecache = false; } - if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) { + if ( is_ssl() && str_starts_with( $url, 'http://' ) ) { // Admin is ssl and the user pasted non-ssl URL. // Check if the provider supports ssl embeds and use that for the preview. $ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode ); diff --git a/wp-admin/includes/class-file-upload-upgrader.php b/wp-admin/includes/class-file-upload-upgrader.php index d7c459dd60..5e75d40a8b 100644 --- a/wp-admin/includes/class-file-upload-upgrader.php +++ b/wp-admin/includes/class-file-upload-upgrader.php @@ -108,7 +108,7 @@ class File_Upload_Upgrader { $this->filename = sanitize_file_name( $_GET[ $urlholder ] ); $this->package = $uploads['basedir'] . '/' . $this->filename; - if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) { + if ( ! str_starts_with( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) { wp_die( __( 'Please select a file' ) ); } } diff --git a/wp-admin/includes/class-wp-media-list-table.php b/wp-admin/includes/class-wp-media-list-table.php index f3bb488919..69f9484cf8 100644 --- a/wp-admin/includes/class-wp-media-list-table.php +++ b/wp-admin/includes/class-wp-media-list-table.php @@ -140,7 +140,7 @@ class WP_Media_List_Table extends WP_List_Table { } $selected = selected( - $filter && 0 === strpos( $filter, 'post_mime_type:' ) && + $filter && str_starts_with( $filter, 'post_mime_type:' ) && wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ), true, false @@ -652,7 +652,7 @@ class WP_Media_List_Table extends WP_List_Table { $taxonomy = 'category'; } elseif ( 'tags' === $column_name ) { $taxonomy = 'post_tag'; - } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { + } elseif ( str_starts_with( $column_name, 'taxonomy-' ) ) { $taxonomy = substr( $column_name, 9 ); } else { $taxonomy = false; diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 06f8836c76..c142f8802a 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -1271,7 +1271,7 @@ class WP_Posts_List_Table extends WP_List_Table { $taxonomy = 'category'; } elseif ( 'tags' === $column_name ) { $taxonomy = 'post_tag'; - } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { + } elseif ( str_starts_with( $column_name, 'taxonomy-' ) ) { $taxonomy = substr( $column_name, 9 ); } else { $taxonomy = false; diff --git a/wp-admin/includes/class-wp-privacy-policy-content.php b/wp-admin/includes/class-wp-privacy-policy-content.php index c3dc60e1bb..a96c411c77 100644 --- a/wp-admin/includes/class-wp-privacy-policy-content.php +++ b/wp-admin/includes/class-wp-privacy-policy-content.php @@ -656,11 +656,11 @@ final class WP_Privacy_Policy_Content { if ( $blocks ) { foreach ( $strings as $key => $string ) { - if ( 0 === strpos( $string, '

' ) ) { + if ( str_starts_with( $string, '

' ) ) { $strings[ $key ] = '' . $string . ''; } - if ( 0 === strpos( $string, '

' ) ) { + if ( str_starts_with( $string, '

' ) ) { $strings[ $key ] = '' . $string . ''; } } diff --git a/wp-admin/includes/class-wp-site-health.php b/wp-admin/includes/class-wp-site-health.php index 13477a4aee..b375633050 100644 --- a/wp-admin/includes/class-wp-site-health.php +++ b/wp-admin/includes/class-wp-site-health.php @@ -1508,7 +1508,7 @@ class WP_Site_Health { if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { $result['label'] = __( 'Your site is set to log errors to a potentially public file' ); - $result['status'] = ( 0 === strpos( ini_get( 'error_log' ), ABSPATH ) ) ? 'critical' : 'recommended'; + $result['status'] = str_starts_with( ini_get( 'error_log' ), ABSPATH ) ? 'critical' : 'recommended'; $result['description'] .= sprintf( '

%s

', diff --git a/wp-admin/includes/credits.php b/wp-admin/includes/credits.php index 833b676cec..510a0bee29 100644 --- a/wp-admin/includes/credits.php +++ b/wp-admin/includes/credits.php @@ -33,7 +33,7 @@ function wp_credits( $version = '', $locale = '' ) { if ( ! is_array( $results ) || false !== strpos( $version, '-' ) - || ( isset( $results['data']['version'] ) && strpos( $version, $results['data']['version'] ) !== 0 ) + || ( isset( $results['data']['version'] ) && ! str_starts_with( $version, $results['data']['version'] ) ) ) { $url = "http://api.wordpress.org/core/credits/1.1/?version={$version}&locale={$locale}"; $options = array( 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) ); diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 2770a2e15e..99503239d1 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -997,7 +997,7 @@ function _wp_handle_upload( &$file, $overrides, $time, $action ) { } if ( false === $move_new_file ) { - if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) { + if ( str_starts_with( $uploads['basedir'], ABSPATH ) ) { $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; } else { $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; @@ -1196,7 +1196,7 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) { if ( $content_disposition ) { $content_disposition = strtolower( $content_disposition ); - if ( 0 === strpos( $content_disposition, 'attachment; filename=' ) ) { + if ( str_starts_with( $content_disposition, 'attachment; filename=' ) ) { $tmpfname_disposition = sanitize_file_name( substr( $content_disposition, 21 ) ); } else { $tmpfname_disposition = ''; @@ -1937,7 +1937,7 @@ function copy_dir( $from, $to, $skip_list = array() ) { $sub_skip_list = array(); foreach ( $skip_list as $skip_item ) { - if ( 0 === strpos( $skip_item, $filename . '/' ) ) { + if ( str_starts_with( $skip_item, $filename . '/' ) ) { $sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item ); } } diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 69c9717812..b0b9b051ad 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -385,7 +385,7 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid } // Use image exif/iptc data for title and caption defaults if possible. - } elseif ( 0 === strpos( $type, 'image/' ) ) { + } elseif ( str_starts_with( $type, 'image/' ) ) { $image_meta = wp_read_image_metadata( $file ); if ( $image_meta ) { @@ -534,8 +534,8 @@ function wp_iframe( $content_func, ...$args ) { wp_enqueue_style( 'colors' ); // Check callback name for 'media'. if ( - ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) || - ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) + ( is_array( $content_func ) && ! empty( $content_func[1] ) && str_starts_with( (string) $content_func[1], 'media' ) ) || + ( ! is_array( $content_func ) && str_starts_with( $content_func, 'media' ) ) ) { wp_enqueue_style( 'deprecated-media' ); } @@ -3507,7 +3507,7 @@ function wp_add_id3_tag_data( &$metadata, $data ) { if ( 'length' !== $key && ! empty( $list ) ) { $metadata[ $key ] = wp_kses_post( reset( $list ) ); // Fix bug in byte stream analysis. - if ( 'terms_of_use' === $key && 0 === strpos( $metadata[ $key ], 'yright notice.' ) ) { + if ( 'terms_of_use' === $key && str_starts_with( $metadata[ $key ], 'yright notice.' ) ) { $metadata[ $key ] = 'Cop' . $metadata[ $key ]; } } diff --git a/wp-admin/includes/menu.php b/wp-admin/includes/menu.php index 8412284fd4..a4d048c81e 100644 --- a/wp-admin/includes/menu.php +++ b/wp-admin/includes/menu.php @@ -228,7 +228,7 @@ function add_menu_classes( $menu ) { continue; } - if ( 0 === strpos( $top[2], 'separator' ) && false !== $last_order ) { // If separator. + if ( str_starts_with( $top[2], 'separator' ) && false !== $last_order ) { // If separator. $first_item = true; $classes = $menu[ $last_order ][4]; $menu[ $last_order ][4] = add_cssclass( 'menu-top-last', $classes ); diff --git a/wp-admin/includes/network.php b/wp-admin/includes/network.php index d5f68d239d..027297d598 100644 --- a/wp-admin/includes/network.php +++ b/wp-admin/includes/network.php @@ -263,7 +263,7 @@ function network_step1( $errors = false ) { echo '

' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

'; } - $is_www = ( 0 === strpos( $hostname, 'www.' ) ); + $is_www = str_starts_with( $hostname, 'www.' ); if ( $is_www ) : ?>

@@ -394,7 +394,7 @@ function network_step2( $errors = false ) { $base = parse_url( $slashed_home, PHP_URL_PATH ); $document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) ); $abspath_fix = str_replace( '\\', '/', ABSPATH ); - $home_path = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path(); + $home_path = str_starts_with( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path(); $wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix ); $rewrite_base = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : ''; diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index e86cdce43e..6782f19500 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -2438,7 +2438,7 @@ function the_block_editor_meta_box_post_form_hidden_fields( $post ) { $classic_elements = wp_html_split( $classic_output ); $hidden_inputs = ''; foreach ( $classic_elements as $element ) { - if ( 0 !== strpos( $element, '' . esc_html( $value ) . ''; } diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 29910f88c5..21999bbfce 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1257,14 +1257,14 @@ function _get_plugin_from_callback( $callback ) { $filename = wp_normalize_path( $reflection->getFileName() ); $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); - if ( strpos( $filename, $plugin_dir ) === 0 ) { + if ( str_starts_with( $filename, $plugin_dir ) ) { $filename = str_replace( $plugin_dir, '', $filename ); $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); $plugins = get_plugins(); foreach ( $plugins as $name => $plugin ) { - if ( strpos( $name, $filename ) === 0 ) { + if ( str_starts_with( $name, $filename ) ) { return $plugin; } } diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php index 20933b6407..14a0362c84 100644 --- a/wp-admin/includes/update-core.php +++ b/wp-admin/includes/update-core.php @@ -1411,7 +1411,7 @@ function update_core( $from, $to ) { } // Check if the language directory exists first. - if ( ! @is_dir( $lang_dir ) && 0 === strpos( $lang_dir, ABSPATH ) ) { + if ( ! @is_dir( $lang_dir ) && str_starts_with( $lang_dir, ABSPATH ) ) { // If it's within the ABSPATH we can handle it here, otherwise they're out of luck. $wp_filesystem->mkdir( $to . str_replace( ABSPATH, '', $lang_dir ), FS_CHMOD_DIR ); clearstatcache(); // For FTP, need to clear the stat cache. diff --git a/wp-admin/load-styles.php b/wp-admin/load-styles.php index ea3aab5b74..d75cfbe8d8 100644 --- a/wp-admin/load-styles.php +++ b/wp-admin/load-styles.php @@ -73,7 +73,7 @@ foreach ( $load as $handle ) { $content = get_file( $path ) . "\n"; - if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) { + if ( str_starts_with( $style->src, '/' . WPINC . '/css/' ) ) { $content = str_replace( '../images/', '../' . WPINC . '/images/', $content ); $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content ); $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content ); diff --git a/wp-admin/menu-header.php b/wp-admin/menu-header.php index ee90d23152..290d6d1813 100644 --- a/wp-admin/menu-header.php +++ b/wp-admin/menu-header.php @@ -127,12 +127,12 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { if ( 'none' === $item[6] || 'div' === $item[6] ) { $img = '
'; - } elseif ( 0 === strpos( $item[6], 'data:image/svg+xml;base64,' ) ) { + } elseif ( str_starts_with( $item[6], 'data:image/svg+xml;base64,' ) ) { $img = '
'; // The value is base64-encoded data, so esc_attr() is used here instead of esc_url(). $img_style = ' style="background-image:url(\'' . esc_attr( $item[6] ) . '\')"'; $img_class = ' svg'; - } elseif ( 0 === strpos( $item[6], 'dashicons-' ) ) { + } elseif ( str_starts_with( $item[6], 'dashicons-' ) ) { $img = '
'; $img_class = ' dashicons-before ' . sanitize_html_class( $item[6] ); } diff --git a/wp-admin/menu.php b/wp-admin/menu.php index c238b08cd5..a9853e3969 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -130,7 +130,7 @@ foreach ( array_merge( $builtin, $types ) as $ptype ) { $menu_icon = 'dashicons-admin-post'; if ( is_string( $ptype_obj->menu_icon ) ) { // Special handling for data:image/svg+xml and Dashicons. - if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) { + if ( str_starts_with( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || str_starts_with( $ptype_obj->menu_icon, 'dashicons-' ) ) { $menu_icon = $ptype_obj->menu_icon; } else { $menu_icon = esc_url( $ptype_obj->menu_icon ); diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php index 75ba6d23d1..379dc8a0f5 100644 --- a/wp-admin/options-permalink.php +++ b/wp-admin/options-permalink.php @@ -87,7 +87,7 @@ if ( ! got_url_rewrite() ) { * base prefix, WordPress core can no longer account for the possible collision. */ if ( is_multisite() && ! is_subdomain_install() && is_main_site() - && 0 === strpos( $permalink_structure, '/blog/' ) + && str_starts_with( $permalink_structure, '/blog/' ) ) { $blog_prefix = '/blog'; } @@ -231,7 +231,7 @@ printf( 0 ) { @@ -137,8 +137,8 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $theme_path_norm = wp_normalize_path( get_theme_file_path() ); $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ); - $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); - $is_theme_block = 0 === strpos( $script_path_norm, $theme_path_norm ); + $is_core_block = isset( $metadata['file'] ) && str_starts_with( $metadata['file'], $wpinc_path_norm ); + $is_theme_block = str_starts_with( $script_path_norm, $theme_path_norm ); $script_uri = plugins_url( $script_path, $metadata['file'] ); if ( $is_core_block ) { @@ -191,7 +191,7 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) { $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); } - $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); + $is_core_block = isset( $metadata['file'] ) && str_starts_with( $metadata['file'], $wpinc_path_norm ); // Skip registering individual styles for each core block when a bundled version provided. if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) { return false; @@ -359,7 +359,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { $metadata = apply_filters( 'block_type_metadata', $metadata ); // Add `style` and `editor_style` for core blocks if missing. - if ( ! empty( $metadata['name'] ) && 0 === strpos( $metadata['name'], 'core/' ) ) { + if ( ! empty( $metadata['name'] ) && str_starts_with( $metadata['name'], 'core/' ) ) { $block_name = str_replace( 'core/', '', $metadata['name'] ); if ( ! isset( $metadata['style'] ) ) { @@ -698,7 +698,7 @@ function serialize_block_attributes( $block_attributes ) { * @return string Block name to use for serialization. */ function strip_core_block_namespace( $block_name = null ) { - if ( is_string( $block_name ) && 0 === strpos( $block_name, 'core/' ) ) { + if ( is_string( $block_name ) && str_starts_with( $block_name, 'core/' ) ) { return substr( $block_name, 5 ); } diff --git a/wp-includes/bookmark-template.php b/wp-includes/bookmark-template.php index 4c9cbeebc0..0573329daa 100644 --- a/wp-includes/bookmark-template.php +++ b/wp-includes/bookmark-template.php @@ -125,7 +125,7 @@ function _walk_bookmarks( $bookmarks, $args = '' ) { $output .= $parsed_args['link_before']; if ( null != $bookmark->link_image && $parsed_args['show_images'] ) { - if ( strpos( $bookmark->link_image, 'http' ) === 0 ) { + if ( str_starts_with( $bookmark->link_image, 'http' ) ) { $output .= "link_image\" $alt $title />"; } else { // If it's a relative path. $output .= 'link_image\" $alt $title />"; diff --git a/wp-includes/class-simplepie.php b/wp-includes/class-simplepie.php index 3d639fc709..4e9cd1c09e 100644 --- a/wp-includes/class-simplepie.php +++ b/wp-includes/class-simplepie.php @@ -22,7 +22,7 @@ require ABSPATH . WPINC . '/SimplePie/Author.php'; * @since 3.5.0 */ function wp_simplepie_autoload( $class ) { - if ( 0 !== strpos( $class, 'SimplePie_' ) ) + if ( ! str_starts_with( $class, 'SimplePie_' ) ) return; $file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php'; diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index dedb6fe319..cc78611982 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -1981,7 +1981,7 @@ final class WP_Customize_Manager { && $parsed_allowed_url['host'] === $parsed_original_url['host'] && - 0 === strpos( $parsed_original_url['path'], $parsed_allowed_url['path'] ) + str_starts_with( $parsed_original_url['path'], $parsed_allowed_url['path'] ) ); if ( $is_allowed ) { break; diff --git a/wp-includes/class-wp-customize-widgets.php b/wp-includes/class-wp-customize-widgets.php index b81390b6ed..41a57dc66b 100644 --- a/wp-includes/class-wp-customize-widgets.php +++ b/wp-includes/class-wp-customize-widgets.php @@ -2059,7 +2059,7 @@ final class WP_Customize_Widgets { * @return bool Whether the option capture is ignored. */ protected function is_option_capture_ignored( $option_name ) { - return ( 0 === strpos( $option_name, '_transient_' ) ); + return ( str_starts_with( $option_name, '_transient_' ) ); } /** diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index 38d76a73d2..29380e7df3 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -4757,7 +4757,7 @@ class WP_Query { $content = str_replace( '', '', $content ); // Ignore nextpage at the beginning of the content. - if ( 0 === strpos( $content, '' ) ) { + if ( str_starts_with( $content, '' ) ) { $content = substr( $content, 15 ); } diff --git a/wp-includes/class-wp-recovery-mode-email-service.php b/wp-includes/class-wp-recovery-mode-email-service.php index 75f271c010..fb329da21c 100644 --- a/wp-includes/class-wp-recovery-mode-email-service.php +++ b/wp-includes/class-wp-recovery-mode-email-service.php @@ -314,7 +314,7 @@ When seeking help with this issue, you may be asked for some of the following in return $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ]; } else { foreach ( $plugins as $file => $plugin_data ) { - if ( 0 === strpos( $file, "{$extension['slug']}/" ) || $file === $extension['slug'] ) { + if ( str_starts_with( $file, "{$extension['slug']}/" ) || $file === $extension['slug'] ) { return $plugin_data; } } diff --git a/wp-includes/class-wp-recovery-mode.php b/wp-includes/class-wp-recovery-mode.php index b30eb408e3..bed00d4ef8 100644 --- a/wp-includes/class-wp-recovery-mode.php +++ b/wp-includes/class-wp-recovery-mode.php @@ -362,7 +362,7 @@ class WP_Recovery_Mode { $error_file = wp_normalize_path( $error['file'] ); $wp_plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); - if ( 0 === strpos( $error_file, $wp_plugin_dir ) ) { + if ( str_starts_with( $error_file, $wp_plugin_dir ) ) { $path = str_replace( $wp_plugin_dir . '/', '', $error_file ); $parts = explode( '/', $path ); @@ -379,7 +379,7 @@ class WP_Recovery_Mode { foreach ( $wp_theme_directories as $theme_directory ) { $theme_directory = wp_normalize_path( $theme_directory ); - if ( 0 === strpos( $error_file, $theme_directory ) ) { + if ( str_starts_with( $error_file, $theme_directory ) ) { $path = str_replace( $theme_directory . '/', '', $error_file ); $parts = explode( '/', $path ); @@ -413,7 +413,7 @@ class WP_Recovery_Mode { $network_plugins = wp_get_active_network_plugins(); foreach ( $network_plugins as $plugin ) { - if ( 0 === strpos( $plugin, $extension['slug'] . '/' ) ) { + if ( str_starts_with( $plugin, $extension['slug'] . '/' ) ) { return true; } } diff --git a/wp-includes/class-wp-scripts.php b/wp-includes/class-wp-scripts.php index 5374aa912a..ddaa270c6d 100644 --- a/wp-includes/class-wp-scripts.php +++ b/wp-includes/class-wp-scripts.php @@ -375,7 +375,7 @@ class WP_Scripts extends WP_Dependencies { return true; } - if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { + if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && str_starts_with( $src, $this->content_url ) ) ) { $src = $this->base_url . $src; } @@ -702,12 +702,12 @@ JS; return true; } - if ( 0 === strpos( $src, '/' . WPINC . '/js/l10n' ) ) { + if ( str_starts_with( $src, '/' . WPINC . '/js/l10n' ) ) { return false; } foreach ( (array) $this->default_dirs as $test ) { - if ( 0 === strpos( $src, $test ) ) { + if ( str_starts_with( $src, $test ) ) { return true; } } diff --git a/wp-includes/class-wp-styles.php b/wp-includes/class-wp-styles.php index b14ad7cbef..76883b54ca 100644 --- a/wp-includes/class-wp-styles.php +++ b/wp-includes/class-wp-styles.php @@ -393,7 +393,7 @@ class WP_Styles extends WP_Dependencies { * @return string Style's fully-qualified URL. */ public function _css_href( $src, $ver, $handle ) { - if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { + if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && str_starts_with( $src, $this->content_url ) ) ) { $src = $this->base_url . $src; } @@ -427,7 +427,7 @@ class WP_Styles extends WP_Dependencies { } foreach ( (array) $this->default_dirs as $test ) { - if ( 0 === strpos( $src, $test ) ) { + if ( str_starts_with( $src, $test ) ) { return true; } } diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index a8975457d2..3b520782c1 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -1768,7 +1768,7 @@ final class WP_Theme implements ArrayAccess { * @param WP_Theme[] $themes Array of theme objects to sort (passed by reference). */ public static function sort_by_name( &$themes ) { - if ( 0 === strpos( get_user_locale(), 'en_' ) ) { + if ( str_starts_with( get_user_locale(), 'en_' ) ) { uasort( $themes, array( 'WP_Theme', '_name_sort' ) ); } else { foreach ( $themes as $key => $theme ) { diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 67985c147b..f669b670ff 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -227,7 +227,7 @@ class WP { } else { foreach ( (array) $rewrite as $match => $query ) { // If the requested file is the anchor of the match, prepend it to the path info. - if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) { + if ( ! empty( $requested_file ) && str_starts_with( $match, $requested_file ) && $requested_file != $requested_path ) { $request_match = $requested_file . '/' . $requested_path; } diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 692d591d7f..ea4340d504 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -2816,7 +2816,7 @@ function discover_pingback_server_uri( $url, $deprecated = '' ) { // Do not search for a pingback server on our own uploads. $uploads_dir = wp_get_upload_dir(); - if ( 0 === strpos( $url, $uploads_dir['baseurl'] ) ) { + if ( str_starts_with( $url, $uploads_dir['baseurl'] ) ) { return false; } diff --git a/wp-includes/error-protection.php b/wp-includes/error-protection.php index dea49be023..08c4159665 100644 --- a/wp-includes/error-protection.php +++ b/wp-includes/error-protection.php @@ -50,7 +50,7 @@ function wp_get_extension_error_description( $error ) { $core_errors = array(); foreach ( $constants as $constant => $value ) { - if ( 0 === strpos( $constant, 'E_' ) ) { + if ( str_starts_with( $constant, 'E_' ) ) { $core_errors[ $value ] = $constant; } } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 1860598865..52c447d996 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2378,7 +2378,7 @@ function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false $uploads['error'] = $tested_paths[ $path ]; } else { if ( ! wp_mkdir_p( $path ) ) { - if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) { + if ( str_starts_with( $uploads['basedir'], ABSPATH ) ) { $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; } else { $error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir']; @@ -2413,7 +2413,7 @@ function _wp_upload_dir( $time = null ) { if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) { $dir = WP_CONTENT_DIR . '/uploads'; - } elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) { + } elseif ( ! str_starts_with( $upload_path, ABSPATH ) ) { // $dir is absolute, $upload_path is (maybe) relative to ABSPATH. $dir = path_join( ABSPATH, $upload_path ); } else { @@ -2575,7 +2575,7 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) $file_type = wp_check_filetype( $filename ); $mime_type = $file_type['type']; - $is_image = ( ! empty( $mime_type ) && 0 === strpos( $mime_type, 'image/' ) ); + $is_image = ( ! empty( $mime_type ) && str_starts_with( $mime_type, 'image/' ) ); $upload_dir = wp_get_upload_dir(); $lc_filename = null; @@ -2913,7 +2913,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { $new_file = $upload['path'] . "/$filename"; if ( ! wp_mkdir_p( dirname( $new_file ) ) ) { - if ( 0 === strpos( $upload['basedir'], ABSPATH ) ) { + if ( str_starts_with( $upload['basedir'], ABSPATH ) ) { $error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir']; } else { $error_path = wp_basename( $upload['basedir'] ) . $upload['subdir']; @@ -3082,7 +3082,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { $real_mime = false; // Validate image types. - if ( $type && 0 === strpos( $type, 'image/' ) ) { + if ( $type && str_starts_with( $type, 'image/' ) ) { // Attempt to figure out what type of image it actually is. $real_mime = wp_get_image_mime( $file ); @@ -3153,7 +3153,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { $type = false; $ext = false; } - } elseif ( 0 === strpos( $real_mime, 'video/' ) || 0 === strpos( $real_mime, 'audio/' ) ) { + } elseif ( str_starts_with( $real_mime, 'video/' ) || str_starts_with( $real_mime, 'audio/' ) ) { /* * For these types, only the major type must match the real value. * This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip, @@ -3311,7 +3311,7 @@ function wp_get_image_mime( $file ) { $magic = bin2hex( $magic ); if ( // RIFF. - ( 0 === strpos( $magic, '52494646' ) ) && + ( str_starts_with( $magic, '52494646' ) ) && // WEBP. ( 16 === strpos( $magic, '57454250' ) ) ) { @@ -7183,7 +7183,7 @@ function wp_auth_check_load() { function wp_auth_check_html() { $login_url = wp_login_url(); $current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST']; - $same_domain = ( strpos( $login_url, $current_domain ) === 0 ); + $same_domain = str_starts_with( $login_url, $current_domain ); /** * Filters whether the authentication check originated at the same domain. @@ -7431,7 +7431,7 @@ function wp_delete_file_from_directory( $file, $directory ) { $real_directory = wp_normalize_path( $real_directory ); } - if ( false === $real_file || false === $real_directory || strpos( $real_file, trailingslashit( $real_directory ) ) !== 0 ) { + if ( false === $real_file || false === $real_directory || ! str_starts_with( $real_file, trailingslashit( $real_directory ) ) ) { return false; } diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 04e011a334..9c889d8198 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -4860,7 +4860,7 @@ function wp_admin_css_uri( $file = 'wp-admin' ) { */ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { // For backward compatibility. - $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; + $handle = str_starts_with( $file, 'css/' ) ? substr( $file, 4 ) : $file; if ( wp_styles()->query( $handle ) ) { if ( $force_echo || did_action( 'wp_print_styles' ) ) { diff --git a/wp-includes/kses.php b/wp-includes/kses.php index eef6632487..31dc1125ec 100644 --- a/wp-includes/kses.php +++ b/wp-includes/kses.php @@ -1260,7 +1260,7 @@ function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowe * Note: the attribute name should only contain `A-Za-z0-9_-` chars, * double hyphens `--` are not accepted by WordPress. */ - if ( strpos( $name_low, 'data-' ) === 0 && ! empty( $allowed_attr['data-*'] ) + if ( str_starts_with( $name_low, 'data-' ) && ! empty( $allowed_attr['data-*'] ) && preg_match( '/^data(?:-[a-z0-9_]+)+$/', $name_low, $match ) ) { /* diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index eb1a2cc5a9..9d6135b470 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -1084,7 +1084,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { $src = $wp_scripts->registered[ $handle ]->src; - if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) { + if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && str_starts_with( $src, $wp_scripts->content_url ) ) ) { $src = $wp_scripts->base_url . $src; } @@ -1098,7 +1098,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { // If the host is the same or it's a relative URL. if ( - ( ! isset( $content_url['path'] ) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) && + ( ! isset( $content_url['path'] ) || str_starts_with( $src_url['path'], $content_url['path'] ) ) && ( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] ) ) { // Make the src relative the specific plugin or theme. @@ -1115,7 +1115,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { $relative = array_slice( $relative, 2 ); // Remove plugins/ or themes/. $relative = implode( '/', $relative ); } elseif ( - ( ! isset( $plugins_url['path'] ) || strpos( $src_url['path'], $plugins_url['path'] ) === 0 ) && + ( ! isset( $plugins_url['path'] ) || str_starts_with( $src_url['path'], $plugins_url['path'] ) ) && ( ! isset( $src_url['host'] ) || ! isset( $plugins_url['host'] ) || $src_url['host'] === $plugins_url['host'] ) ) { // Make the src relative the specific plugin. @@ -1134,7 +1134,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { } elseif ( ! isset( $src_url['host'] ) || ! isset( $site_url['host'] ) || $src_url['host'] === $site_url['host'] ) { if ( ! isset( $site_url['path'] ) ) { $relative = trim( $src_url['path'], '/' ); - } elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) { + } elseif ( str_starts_with( $src_url['path'], trailingslashit( $site_url['path'] ) ) ) { // Make the src relative to the WP root. $relative = substr( $src_url['path'], strlen( $site_url['path'] ) ); $relative = trim( $relative, '/' ); @@ -1373,8 +1373,8 @@ function get_available_languages( $dir = null ) { if ( $lang_files ) { foreach ( $lang_files as $lang_file ) { $lang_file = basename( $lang_file, '.mo' ); - if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && - 0 !== strpos( $lang_file, 'admin-' ) ) { + if ( ! str_starts_with( $lang_file, 'continents-cities' ) && ! str_starts_with( $lang_file, 'ms-' ) && + ! str_starts_with( $lang_file, 'admin-' ) ) { $languages[] = $lang_file; } } diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index c5951c15ba..dccfc4bc8f 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -3636,7 +3636,7 @@ function plugins_url( $path = '', $plugin = '' ) { $plugin = wp_normalize_path( $plugin ); $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); - if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) { + if ( ! empty( $plugin ) && str_starts_with( $plugin, $mu_plugin_dir ) ) { $url = WPMU_PLUGIN_URL; } else { $url = WP_PLUGIN_URL; diff --git a/wp-includes/media.php b/wp-includes/media.php index 95836d98a2..281e896fa0 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -3730,7 +3730,7 @@ function get_taxonomies_for_attachments( $output = 'names' ) { foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { foreach ( $taxonomy->object_type as $object_type ) { - if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { + if ( 'attachment' === $object_type || str_starts_with( $object_type, 'attachment:' ) ) { if ( 'names' === $output ) { $taxonomies[] = $taxonomy->name; } else { @@ -5120,7 +5120,7 @@ function attachment_url_to_postid( $url ) { $path = str_replace( $image_path['scheme'], $site_url['scheme'], $path ); } - if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) { + if ( str_starts_with( $path, $dir['baseurl'] . '/' ) ) { $path = substr( $path, strlen( $dir['baseurl'] . '/' ) ); } diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 2a93f91325..9a811edc3a 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1187,7 +1187,7 @@ if ( ! function_exists( 'auth_redirect' ) ) : // If https is required and request is http, redirect. if ( $secure && ! is_ssl() && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) { - if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { + if ( str_starts_with( $_SERVER['REQUEST_URI'], 'http' ) ) { wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); exit; } else { @@ -1218,7 +1218,7 @@ if ( ! function_exists( 'auth_redirect' ) ) : // If the user wants ssl but the session is not ssl, redirect. if ( ! $secure && get_user_option( 'use_ssl', $user_id ) && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) { - if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { + if ( str_starts_with( $_SERVER['REQUEST_URI'], 'http' ) ) { wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); exit; } else { @@ -1281,7 +1281,7 @@ if ( ! function_exists( 'check_admin_referer' ) ) : */ do_action( 'check_admin_referer', $action, $result ); - if ( ! $result && ! ( -1 === $action && strpos( $referer, $adminurl ) === 0 ) ) { + if ( ! $result && ! ( -1 === $action && str_starts_with( $referer, $adminurl ) ) ) { wp_nonce_ays( $action ); die(); } diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php index 4200af990d..c10f9a3aa1 100644 --- a/wp-includes/plugin.php +++ b/wp-includes/plugin.php @@ -770,7 +770,7 @@ function plugin_basename( $file ) { arsort( $wp_plugin_paths ); foreach ( $wp_plugin_paths as $dir => $realdir ) { - if ( strpos( $file, $realdir ) === 0 ) { + if ( str_starts_with( $file, $realdir ) ) { $file = $dir . substr( $file, strlen( $realdir ) ); } } diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 90688254b1..083af5ad6d 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -887,7 +887,7 @@ function post_password_required( $post = null ) { $hasher = new PasswordHash( 8, true ); $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); - if ( 0 !== strpos( $hash, '$P$B' ) ) { + if ( ! str_starts_with( $hash, '$P$B' ) ) { $required = true; } else { $required = ! $hasher->CheckPassword( $post->post_password, $hash ); diff --git a/wp-includes/post.php b/wp-includes/post.php index 876a1f7d0d..3a89ed51fc 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -723,7 +723,7 @@ function get_attached_file( $attachment_id, $unfiltered = false ) { $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); // If the file is relative, prepend upload dir. - if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) { + if ( $file && ! str_starts_with( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) { $uploads = wp_get_upload_dir(); if ( false === $uploads['error'] ) { $file = $uploads['basedir'] . "/$file"; @@ -795,7 +795,7 @@ function _wp_relative_upload_path( $path ) { $new_path = $path; $uploads = wp_get_upload_dir(); - if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) { + if ( str_starts_with( $new_path, $uploads['basedir'] ) ) { $new_path = str_replace( $uploads['basedir'], '', $new_path ); $new_path = ltrim( $new_path, '/' ); } @@ -6483,7 +6483,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) { $uploads = wp_get_upload_dir(); if ( $uploads && false === $uploads['error'] ) { // Check that the upload base exists in the file location. - if ( 0 === strpos( $file, $uploads['basedir'] ) ) { + if ( str_starts_with( $file, $uploads['basedir'] ) ) { // Replace file location with url location. $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file ); } elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) { @@ -6612,7 +6612,7 @@ function wp_attachment_is( $type, $post = null ) { return false; } - if ( 0 === strpos( $post->post_mime_type, $type . '/' ) ) { + if ( str_starts_with( $post->post_mime_type, $type . '/' ) ) { return true; } diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index 33fcdd5b8a..d9dd834c90 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -939,12 +939,12 @@ function rest_is_field_included( $field, $fields ) { foreach ( $fields as $accepted_field ) { // Check to see if $field is the parent of any item in $fields. // A field "parent" should be accepted if "parent.child" is accepted. - if ( strpos( $accepted_field, "$field." ) === 0 ) { + if ( str_starts_with( $accepted_field, "$field." ) ) { return true; } // Conversely, if "parent" is accepted, all "parent.child" fields // should also be accepted. - if ( strpos( $field, "$accepted_field." ) === 0 ) { + if ( str_starts_with( $field, "$accepted_field." ) ) { return true; } } diff --git a/wp-includes/rest-api/class-wp-rest-request.php b/wp-includes/rest-api/class-wp-rest-request.php index 18e867de3a..b708df6cc7 100644 --- a/wp-includes/rest-api/class-wp-rest-request.php +++ b/wp-includes/rest-api/class-wp-rest-request.php @@ -1031,7 +1031,7 @@ class WP_REST_Request implements ArrayAccess { } $api_root = rest_url(); - if ( get_option( 'permalink_structure' ) && 0 === strpos( $url, $api_root ) ) { + if ( get_option( 'permalink_structure' ) && str_starts_with( $url, $api_root ) ) { // Pretty permalinks on, and URL is under the API root. $api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) ); $route = parse_url( $api_url_part, PHP_URL_PATH ); diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php index 40666f82e5..cc32c828ab 100644 --- a/wp-includes/rest-api/class-wp-rest-server.php +++ b/wp-includes/rest-api/class-wp-rest-server.php @@ -648,7 +648,7 @@ class WP_REST_Server { // Convert $rel URIs to their compact versions if they exist. foreach ( $curies as $curie ) { $href_prefix = substr( $curie['href'], 0, strpos( $curie['href'], '{rel}' ) ); - if ( strpos( $rel, $href_prefix ) !== 0 ) { + if ( ! str_starts_with( $rel, $href_prefix ) ) { continue; } @@ -1044,7 +1044,7 @@ class WP_REST_Server { $with_namespace = array(); foreach ( $this->get_namespaces() as $namespace ) { - if ( 0 === strpos( trailingslashit( ltrim( $path, '/' ) ), $namespace ) ) { + if ( str_starts_with( trailingslashit( ltrim( $path, '/' ) ), $namespace ) ) { $with_namespace[] = $this->get_routes( $namespace ); } } @@ -1827,7 +1827,7 @@ class WP_REST_Server { ); foreach ( $server as $key => $value ) { - if ( strpos( $key, 'HTTP_' ) === 0 ) { + if ( str_starts_with( $key, 'HTTP_' ) ) { $headers[ substr( $key, 5 ) ] = $value; } elseif ( 'REDIRECT_HTTP_AUTHORIZATION' === $key && empty( $server['HTTP_AUTHORIZATION'] ) ) { /* diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index 4c92a4293c..2b0a5e2528 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -600,7 +600,7 @@ function url_to_postid( $url ) { // If the requesting file is the anchor of the match, // prepend it to the path info. - if ( ! empty( $url ) && ( $url != $request ) && ( strpos( $match, $url ) === 0 ) ) { + if ( ! empty( $url ) && ( $url != $request ) && str_starts_with( $match, $url ) ) { $request_match = $url . '/' . $request; } diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index f48e8debeb..20c7bf2591 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -184,7 +184,7 @@ function wp_get_script_polyfill( $scripts, $tests ) { $src = $scripts->registered[ $handle ]->src; $ver = $scripts->registered[ $handle ]->ver; - if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) { + if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && str_starts_with( $src, $scripts->content_url ) ) ) { $src = $scripts->base_url . $src; } diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 0832bffbe8..178aa08f7b 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2262,7 +2262,7 @@ function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { $terms_from_remaining_taxonomies = get_terms( $args ); // Array keys should be preserved for values of $fields that use term_id for keys. - if ( ! empty( $args['fields'] ) && 0 === strpos( $args['fields'], 'id=>' ) ) { + if ( ! empty( $args['fields'] ) && str_starts_with( $args['fields'], 'id=>' ) ) { $terms = $terms + $terms_from_remaining_taxonomies; } else { $terms = array_merge( $terms, $terms_from_remaining_taxonomies ); @@ -3506,7 +3506,7 @@ function wp_update_term_count_now( $terms, $taxonomy ) { } else { $object_types = (array) $taxonomy->object_type; foreach ( $object_types as &$object_type ) { - if ( 0 === strpos( $object_type, 'attachment:' ) ) { + if ( str_starts_with( $object_type, 'attachment:' ) ) { list( $object_type ) = explode( ':', $object_type ); } } diff --git a/wp-includes/theme.php b/wp-includes/theme.php index d51a79593d..9c53a9ecc6 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -457,7 +457,7 @@ function search_theme_directories( $force = false ) { * to use in get_theme_root(). */ foreach ( $wp_theme_directories as $theme_root ) { - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { + if ( str_starts_with( $theme_root, WP_CONTENT_DIR ) ) { $relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; } else { $relative_theme_roots[ $theme_root ] = $theme_root; @@ -634,11 +634,11 @@ function get_theme_root_uri( $stylesheet_or_template = '', $theme_root = '' ) { if ( $stylesheet_or_template && $theme_root ) { if ( in_array( $theme_root, (array) $wp_theme_directories, true ) ) { // Absolute path. Make an educated guess. YMMV -- but note the filter below. - if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) { + if ( str_starts_with( $theme_root, WP_CONTENT_DIR ) ) { $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); - } elseif ( 0 === strpos( $theme_root, ABSPATH ) ) { + } elseif ( str_starts_with( $theme_root, ABSPATH ) ) { $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); - } elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) { + } elseif ( str_starts_with( $theme_root, WP_PLUGIN_DIR ) || str_starts_with( $theme_root, WPMU_PLUGIN_DIR ) ) { $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); } else { $theme_root_uri = $theme_root; diff --git a/wp-includes/user.php b/wp-includes/user.php index 02f30dd36b..8f70f2a739 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -989,7 +989,7 @@ function get_blogs_of_user( $user_id, $all = false ) { if ( 'capabilities' !== substr( $key, -12 ) ) { continue; } - if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) { + if ( $wpdb->base_prefix && ! str_starts_with( $key, $wpdb->base_prefix ) ) { continue; } $site_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); diff --git a/wp-includes/version.php b/wp-includes/version.php index bcdbdcad2b..b3b6203bf4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55702'; +$wp_version = '6.3-alpha-55703'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets/class-wp-widget-block.php b/wp-includes/widgets/class-wp-widget-block.php index 44534c7fa8..44371825ac 100644 --- a/wp-includes/widgets/class-wp-widget-block.php +++ b/wp-includes/widgets/class-wp-widget-block.php @@ -223,7 +223,7 @@ class WP_Widget_Block extends WP_Widget { * @return bool Updated `is_wide` value. */ public function set_is_wide_widget_in_customizer( $is_wide, $widget_id ) { - if ( strpos( $widget_id, 'block-' ) === 0 ) { + if ( str_starts_with( $widget_id, 'block-' ) ) { return false; } diff --git a/wp-login.php b/wp-login.php index 9a1bbb5bce..ccd7a91f78 100644 --- a/wp-login.php +++ b/wp-login.php @@ -13,7 +13,7 @@ require __DIR__ . '/wp-load.php'; // Redirect to HTTPS login if forced to use SSL. if ( force_ssl_admin() && ! is_ssl() ) { - if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { + if ( str_starts_with( $_SERVER['REQUEST_URI'], 'http' ) ) { wp_safe_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); exit; } else {