mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 09:07:59 +01:00
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
This commit is contained in:
parent
c1facaa4ce
commit
2ec23a82ed
@ -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 );
|
||||
|
@ -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' ) );
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -656,11 +656,11 @@ final class WP_Privacy_Policy_Content {
|
||||
|
||||
if ( $blocks ) {
|
||||
foreach ( $strings as $key => $string ) {
|
||||
if ( 0 === strpos( $string, '<p>' ) ) {
|
||||
if ( str_starts_with( $string, '<p>' ) ) {
|
||||
$strings[ $key ] = '<!-- wp:paragraph -->' . $string . '<!-- /wp:paragraph -->';
|
||||
}
|
||||
|
||||
if ( 0 === strpos( $string, '<h2>' ) ) {
|
||||
if ( str_starts_with( $string, '<h2>' ) ) {
|
||||
$strings[ $key ] = '<!-- wp:heading -->' . $string . '<!-- /wp:heading -->';
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
'<p>%s</p>',
|
||||
|
@ -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( '/' ) );
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
@ -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 ];
|
||||
}
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -263,7 +263,7 @@ function network_step1( $errors = false ) {
|
||||
echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
|
||||
}
|
||||
|
||||
$is_www = ( 0 === strpos( $hostname, 'www.' ) );
|
||||
$is_www = str_starts_with( $hostname, 'www.' );
|
||||
if ( $is_www ) :
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Server Address' ); ?></h3>
|
||||
@ -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 ), '/' ) : '';
|
||||
|
||||
|
@ -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, '<input ' ) ) {
|
||||
if ( ! str_starts_with( $element, '<input ' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ function wp_privacy_generate_personal_data_export_group_html( $group_data, $grou
|
||||
foreach ( (array) $group_item_data as $group_item_datum ) {
|
||||
$value = $group_item_datum['value'];
|
||||
// If it looks like a link, make it a link.
|
||||
if ( false === strpos( $value, ' ' ) && ( 0 === strpos( $value, 'http://' ) || 0 === strpos( $value, 'https://' ) ) ) {
|
||||
if ( false === strpos( $value, ' ' ) && ( str_starts_with( $value, 'http://' ) || str_starts_with( $value, 'https://' ) ) ) {
|
||||
$value = '<a href="' . esc_url( $value ) . '">' . esc_html( $value ) . '</a>';
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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 );
|
||||
|
@ -127,12 +127,12 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
|
||||
|
||||
if ( 'none' === $item[6] || 'div' === $item[6] ) {
|
||||
$img = '<br />';
|
||||
} elseif ( 0 === strpos( $item[6], 'data:image/svg+xml;base64,' ) ) {
|
||||
} elseif ( str_starts_with( $item[6], 'data:image/svg+xml;base64,' ) ) {
|
||||
$img = '<br />';
|
||||
// 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 = '<br />';
|
||||
$img_class = ' dashicons-before ' . sanitize_html_class( $item[6] );
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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(
|
||||
|
||||
<?php
|
||||
if ( is_multisite() && ! is_subdomain_install() && is_main_site()
|
||||
&& 0 === strpos( $permalink_structure, '/blog/' )
|
||||
&& str_starts_with( $permalink_structure, '/blog/' )
|
||||
) {
|
||||
$permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
|
||||
$category_base = preg_replace( '|^/?blog|', '', $category_base );
|
||||
|
@ -165,7 +165,7 @@ function resolve_block_template( $template_type, $template_hierarchy, $fallback_
|
||||
|
||||
// Is the active theme a child theme, and is the PHP fallback template part of it?
|
||||
if (
|
||||
strpos( $fallback_template, $theme_base_path ) === 0 &&
|
||||
str_starts_with( $fallback_template, $theme_base_path ) &&
|
||||
strpos( $fallback_template, $parent_theme_base_path ) === false
|
||||
) {
|
||||
$fallback_template_slug = substr(
|
||||
|
@ -17,14 +17,14 @@
|
||||
*/
|
||||
function remove_block_asset_path_prefix( $asset_handle_or_path ) {
|
||||
$path_prefix = 'file:';
|
||||
if ( 0 !== strpos( $asset_handle_or_path, $path_prefix ) ) {
|
||||
if ( ! str_starts_with( $asset_handle_or_path, $path_prefix ) ) {
|
||||
return $asset_handle_or_path;
|
||||
}
|
||||
$path = substr(
|
||||
$asset_handle_or_path,
|
||||
strlen( $path_prefix )
|
||||
);
|
||||
if ( strpos( $path, './' ) === 0 ) {
|
||||
if ( str_starts_with( $path, './' ) ) {
|
||||
$path = substr( $path, 2 );
|
||||
}
|
||||
return $path;
|
||||
@ -44,12 +44,12 @@ function remove_block_asset_path_prefix( $asset_handle_or_path ) {
|
||||
* @return string Generated asset name for the block's field.
|
||||
*/
|
||||
function generate_block_asset_handle( $block_name, $field_name, $index = 0 ) {
|
||||
if ( 0 === strpos( $block_name, 'core/' ) ) {
|
||||
if ( str_starts_with( $block_name, 'core/' ) ) {
|
||||
$asset_handle = str_replace( 'core/', 'wp-block-', $block_name );
|
||||
if ( 0 === strpos( $field_name, 'editor' ) ) {
|
||||
if ( str_starts_with( $field_name, 'editor' ) ) {
|
||||
$asset_handle .= '-editor';
|
||||
}
|
||||
if ( 0 === strpos( $field_name, 'view' ) ) {
|
||||
if ( str_starts_with( $field_name, 'view' ) ) {
|
||||
$asset_handle .= '-view';
|
||||
}
|
||||
if ( $index > 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 );
|
||||
}
|
||||
|
||||
|
@ -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 .= "<img src=\"$bookmark->link_image\" $alt $title />";
|
||||
} else { // If it's a relative path.
|
||||
$output .= '<img src="' . get_option( 'siteurl' ) . "$bookmark->link_image\" $alt $title />";
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
|
@ -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_' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4757,7 +4757,7 @@ class WP_Query {
|
||||
$content = str_replace( '<!-- /wp:nextpage -->', '', $content );
|
||||
|
||||
// Ignore nextpage at the beginning of the content.
|
||||
if ( 0 === strpos( $content, '<!--nextpage-->' ) ) {
|
||||
if ( str_starts_with( $content, '<!--nextpage-->' ) ) {
|
||||
$content = substr( $content, 15 );
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 ) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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' ) ) {
|
||||
|
@ -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 )
|
||||
) {
|
||||
/*
|
||||
|
@ -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/<plugin name> or themes/<theme name>.
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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'] . '/' ) );
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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'] ) ) {
|
||||
/*
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user