mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Code Modernization: Replace usage of substr()
with str_starts_with()
and str_ends_with()
.
`str_starts_with()` and `str_ends_with()` were introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins or ends with the given substring (needle). WordPress core includes a polyfill for these functions on PHP < 8.0 as of WordPress 5.9. This commit uses `str_starts_with()` and `str_ends_with()` in core files where appropriate: * `$needle === substr( $string, 0, $length )`, where `$length` is the length of `$needle`, is replaced with `str_starts_with( $haystack, $needle )`. * `$needle === substr( $string, $offset )`, where `$offset` is negative and the absolute value of `$offset` is the length of `$needle`, is replaced with `str_ends_with( $haystack, $needle )`. This aims to make the code more readable and consistent, as well as better aligned with modern development practices. Follow-up to [52039], [52040], [52326], [55703], [55710], [55987], [55988]. Props Soean, spacedmonkey, Clorith, ocean90, azaozz, sabernhardt, SergeyBiryukov. Fixes #58220. Built from https://develop.svn.wordpress.org/trunk@55990 git-svn-id: http://core.svn.wordpress.org/trunk@55502 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
372d9c07e5
commit
84e9601e5a
@ -3323,7 +3323,7 @@ function wp_ajax_send_attachment_to_editor() {
|
||||
|
||||
remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
|
||||
|
||||
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
|
||||
if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
|
||||
$align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
|
||||
$size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
|
||||
$alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
|
||||
|
@ -405,7 +405,7 @@ class Core_Upgrader extends WP_Upgrader {
|
||||
|
||||
foreach ( $checksums as $file => $checksum ) {
|
||||
// Skip files which get updated.
|
||||
if ( 'wp-content' === substr( $file, 0, 10 ) ) {
|
||||
if ( str_starts_with( $file, 'wp-content' ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
|
||||
|
@ -336,9 +336,9 @@ class Language_Pack_Upgrader extends WP_Upgrader {
|
||||
$po = false;
|
||||
$mo = false;
|
||||
foreach ( (array) $files as $file => $filedata ) {
|
||||
if ( '.po' === substr( $file, -3 ) ) {
|
||||
if ( str_ends_with( $file, '.po' ) ) {
|
||||
$po = true;
|
||||
} elseif ( '.mo' === substr( $file, -3 ) ) {
|
||||
} elseif ( str_ends_with( $file, '.mo' ) ) {
|
||||
$mo = true;
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ final class WP_Screen {
|
||||
$post_type = $id;
|
||||
$id = 'post'; // Changes later. Ends up being $base.
|
||||
} else {
|
||||
if ( '.php' === substr( $id, -4 ) ) {
|
||||
if ( str_ends_with( $id, '.php' ) ) {
|
||||
$id = substr( $id, 0, -4 );
|
||||
}
|
||||
|
||||
@ -241,16 +241,16 @@ final class WP_Screen {
|
||||
}
|
||||
|
||||
if ( ! $post_type && $hook_name ) {
|
||||
if ( '-network' === substr( $id, -8 ) ) {
|
||||
if ( str_ends_with( $id, '-network' ) ) {
|
||||
$id = substr( $id, 0, -8 );
|
||||
$in_admin = 'network';
|
||||
} elseif ( '-user' === substr( $id, -5 ) ) {
|
||||
} elseif ( str_ends_with( $id, '-user' ) ) {
|
||||
$id = substr( $id, 0, -5 );
|
||||
$in_admin = 'user';
|
||||
}
|
||||
|
||||
$id = sanitize_key( $id );
|
||||
if ( 'edit-comments' !== $id && 'edit-tags' !== $id && 'edit-' === substr( $id, 0, 5 ) ) {
|
||||
if ( 'edit-comments' !== $id && 'edit-tags' !== $id && str_starts_with( $id, 'edit-' ) ) {
|
||||
$maybe = substr( $id, 5 );
|
||||
if ( taxonomy_exists( $maybe ) ) {
|
||||
$id = 'edit-tags';
|
||||
|
@ -358,7 +358,7 @@ class WP_Site_Health_Auto_Updates {
|
||||
|
||||
$unwritable_files = array();
|
||||
foreach ( array_keys( $checksums ) as $file ) {
|
||||
if ( 'wp-content' === substr( $file, 0, 10 ) ) {
|
||||
if ( str_starts_with( $file, 'wp-content' ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! file_exists( ABSPATH . $file ) ) {
|
||||
|
@ -1365,7 +1365,7 @@ function wp_dashboard_plugins_output( $rss, $args = array() ) {
|
||||
// Is this random plugin's slug already installed? If so, try again.
|
||||
reset( $plugin_slugs );
|
||||
foreach ( $plugin_slugs as $plugin_slug ) {
|
||||
if ( $slug === substr( $plugin_slug, 0, strlen( $slug ) ) ) {
|
||||
if ( str_starts_with( $plugin_slug, $slug ) ) {
|
||||
unset( $items[$item_key] );
|
||||
continue 2;
|
||||
}
|
||||
|
@ -1253,7 +1253,7 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) {
|
||||
|
||||
$signature_url = false;
|
||||
|
||||
if ( is_string( $url_path ) && ( '.zip' === substr( $url_path, -4 ) || '.tar.gz' === substr( $url_path, -7 ) ) ) {
|
||||
if ( is_string( $url_path ) && ( str_ends_with( $url_path, '.zip' ) || str_ends_with( $url_path, '.tar.gz' ) ) ) {
|
||||
$signature_url = str_replace( $url_path, $url_path . '.sig', $url );
|
||||
}
|
||||
|
||||
@ -1646,7 +1646,7 @@ function _unzip_file_ziparchive( $file, $to, $needed_dirs = array() ) {
|
||||
return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
|
||||
}
|
||||
|
||||
if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory.
|
||||
if ( str_starts_with( $info['name'], '__MACOSX/' ) ) { // Skip the OS X-created __MACOSX directory.
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1659,7 +1659,7 @@ function _unzip_file_ziparchive( $file, $to, $needed_dirs = array() ) {
|
||||
|
||||
$dirname = dirname( $info['name'] );
|
||||
|
||||
if ( '/' === substr( $info['name'], -1 ) ) {
|
||||
if ( str_ends_with( $info['name'], '/' ) ) {
|
||||
// Directory.
|
||||
$needed_dirs[] = $to . untrailingslashit( $info['name'] );
|
||||
} elseif ( '.' !== $dirname ) {
|
||||
@ -1726,11 +1726,11 @@ function _unzip_file_ziparchive( $file, $to, $needed_dirs = array() ) {
|
||||
return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
|
||||
}
|
||||
|
||||
if ( '/' === substr( $info['name'], -1 ) ) { // Directory.
|
||||
if ( str_ends_with( $info['name'], '/' ) ) { // Directory.
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( '__MACOSX/' === substr( $info['name'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files.
|
||||
if ( str_starts_with( $info['name'], '__MACOSX/' ) ) { // Don't extract the OS X-created __MACOSX directory files.
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1800,7 +1800,7 @@ function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) {
|
||||
|
||||
// Determine any children directories needed (From within the archive).
|
||||
foreach ( $archive_files as $file ) {
|
||||
if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Skip the OS X-created __MACOSX directory.
|
||||
if ( str_starts_with( $file['filename'], '__MACOSX/' ) ) { // Skip the OS X-created __MACOSX directory.
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1866,7 +1866,7 @@ function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( '__MACOSX/' === substr( $file['filename'], 0, 9 ) ) { // Don't extract the OS X-created __MACOSX directory files.
|
||||
if ( str_starts_with( $file['filename'], '__MACOSX/' ) ) { // Don't extract the OS X-created __MACOSX directory files.
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1354,7 +1354,7 @@ function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
|
||||
function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
|
||||
$post = get_post( $attachment_id );
|
||||
|
||||
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
|
||||
if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
|
||||
$url = $attachment['url'];
|
||||
$align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none';
|
||||
$size = ! empty( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
|
||||
@ -1465,7 +1465,7 @@ function get_attachment_fields_to_edit( $post, $errors = null ) {
|
||||
$form_fields = array_merge_recursive( $form_fields, (array) $errors );
|
||||
|
||||
// This was formerly in image_attachment_fields_to_edit().
|
||||
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
|
||||
if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
|
||||
$alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
|
||||
|
||||
if ( empty( $alt ) ) {
|
||||
@ -3220,7 +3220,7 @@ function edit_form_image_editor( $post ) {
|
||||
?>
|
||||
</div>
|
||||
<div class="wp_attachment_details edit-form-section">
|
||||
<?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
|
||||
<?php if ( str_starts_with( $post->post_mime_type, 'image' ) ) : ?>
|
||||
<p class="attachment-alt-text">
|
||||
<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
|
||||
<textarea class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" aria-describedby="alt-text-description"><?php echo esc_attr( $alt_text ); ?></textarea>
|
||||
|
@ -81,7 +81,7 @@ function extract_from_markers( $filename, $marker ) {
|
||||
}
|
||||
|
||||
if ( $state ) {
|
||||
if ( '#' === substr( $markerline, 0, 1 ) ) {
|
||||
if ( str_starts_with( $markerline, '#' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -750,7 +750,7 @@ function set_screen_options() {
|
||||
default:
|
||||
$screen_option = false;
|
||||
|
||||
if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) {
|
||||
if ( str_ends_with( $option, '_page' ) || 'layout_columns' === $option ) {
|
||||
/**
|
||||
* Filters a screen option value before it is set.
|
||||
*
|
||||
|
@ -294,7 +294,7 @@ function get_plugins( $plugin_folder = '' ) {
|
||||
|
||||
if ( $plugins_dir ) {
|
||||
while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
|
||||
if ( '.' === substr( $file, 0, 1 ) ) {
|
||||
if ( str_starts_with( $file, '.' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -303,11 +303,11 @@ function get_plugins( $plugin_folder = '' ) {
|
||||
|
||||
if ( $plugins_subdir ) {
|
||||
while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) {
|
||||
if ( '.' === substr( $subfile, 0, 1 ) ) {
|
||||
if ( str_starts_with( $subfile, '.' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( '.php' === substr( $subfile, -4 ) ) {
|
||||
if ( str_ends_with( $subfile, '.php' ) ) {
|
||||
$plugin_files[] = "$file/$subfile";
|
||||
}
|
||||
}
|
||||
@ -315,7 +315,7 @@ function get_plugins( $plugin_folder = '' ) {
|
||||
closedir( $plugins_subdir );
|
||||
}
|
||||
} else {
|
||||
if ( '.php' === substr( $file, -4 ) ) {
|
||||
if ( str_ends_with( $file, '.php' ) ) {
|
||||
$plugin_files[] = $file;
|
||||
}
|
||||
}
|
||||
@ -371,7 +371,7 @@ function get_mu_plugins() {
|
||||
$plugins_dir = @opendir( WPMU_PLUGIN_DIR );
|
||||
if ( $plugins_dir ) {
|
||||
while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
|
||||
if ( '.php' === substr( $file, -4 ) ) {
|
||||
if ( str_ends_with( $file, '.php' ) ) {
|
||||
$plugin_files[] = $file;
|
||||
}
|
||||
}
|
||||
|
@ -1242,7 +1242,7 @@ function update_core( $from, $to ) {
|
||||
|
||||
if ( is_array( $checksums ) ) {
|
||||
foreach ( $checksums as $file => $checksum ) {
|
||||
if ( 'wp-content' === substr( $file, 0, 10 ) ) {
|
||||
if ( str_starts_with( $file, 'wp-content' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1349,7 +1349,7 @@ function update_core( $from, $to ) {
|
||||
|
||||
if ( isset( $checksums ) && is_array( $checksums ) ) {
|
||||
foreach ( $checksums as $file => $checksum ) {
|
||||
if ( 'wp-content' === substr( $file, 0, 10 ) ) {
|
||||
if ( str_starts_with( $file, 'wp-content' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ switch ( $step ) {
|
||||
|
||||
$key = 0;
|
||||
foreach ( $config_file as $line_num => $line ) {
|
||||
if ( '$table_prefix =' === substr( $line, 0, 15 ) ) {
|
||||
if ( str_starts_with( $line, '$table_prefix =' ) ) {
|
||||
$config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
|
||||
continue;
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ if ( isset( $_GET['editwidget'] ) && $_GET['editwidget'] ) {
|
||||
<?php
|
||||
foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
|
||||
echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr( $sbname ) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
|
||||
if ( 'wp_inactive_widgets' === $sbname || 'orphaned_widgets' === substr( $sbname, 0, 16 ) ) {
|
||||
if ( 'wp_inactive_widgets' === $sbname || str_starts_with( $sbname, 'orphaned_widgets' ) ) {
|
||||
echo ' ';
|
||||
} else {
|
||||
if ( ! isset( $sidebars_widgets[ $sbname ] ) || ! is_array( $sidebars_widgets[ $sbname ] ) ) {
|
||||
@ -450,7 +450,7 @@ do_action( 'widgets_admin_page' );
|
||||
|
||||
$theme_sidebars = array();
|
||||
foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
|
||||
if ( str_contains( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
|
||||
if ( str_contains( $registered_sidebar['class'], 'inactive-sidebar' ) || str_starts_with( $sidebar, 'orphaned_widgets' ) ) {
|
||||
$wrap_class = 'widgets-holder-wrap';
|
||||
if ( ! empty( $registered_sidebar['class'] ) ) {
|
||||
$wrap_class .= ' ' . $registered_sidebar['class'];
|
||||
|
@ -83,7 +83,7 @@ function _walk_bookmarks( $bookmarks, $args = '' ) {
|
||||
$title = $desc;
|
||||
|
||||
if ( $parsed_args['show_updated'] ) {
|
||||
if ( '00' !== substr( $bookmark->link_updated_f, 0, 2 ) ) {
|
||||
if ( ! str_starts_with( $bookmark->link_updated_f, '00' ) ) {
|
||||
$title .= ' (';
|
||||
$title .= sprintf(
|
||||
/* translators: %s: Date and time of last update. */
|
||||
|
@ -6076,7 +6076,7 @@ final class WP_Customize_Manager {
|
||||
__( 'This video file is too large to use as a header video. Try a shorter video or optimize the compression settings and re-upload a file that is less than 8MB. Or, upload your video to YouTube and link it with the option below.' )
|
||||
);
|
||||
}
|
||||
if ( '.mp4' !== substr( $video, -4 ) && '.mov' !== substr( $video, -4 ) ) { // Check for .mp4 or .mov format, which (assuming h.264 encoding) are the only cross-browser-supported formats.
|
||||
if ( ! str_ends_with( $video, '.mp4' ) && ! str_ends_with( $video, '.mov' ) ) { // Check for .mp4 or .mov format, which (assuming h.264 encoding) are the only cross-browser-supported formats.
|
||||
$validity->add(
|
||||
'invalid_file_type',
|
||||
sprintf(
|
||||
|
@ -1472,7 +1472,7 @@ final class WP_Customize_Nav_Menus {
|
||||
(
|
||||
! empty( $args['container'] )
|
||||
||
|
||||
( isset( $args['items_wrap'] ) && '<' === substr( $args['items_wrap'], 0, 1 ) )
|
||||
( isset( $args['items_wrap'] ) && str_starts_with( $args['items_wrap'], '<' ) )
|
||||
)
|
||||
);
|
||||
$args['can_partial_refresh'] = $can_partial_refresh;
|
||||
|
@ -388,7 +388,7 @@ class WP_Embed {
|
||||
}
|
||||
|
||||
foreach ( $post_metas as $post_meta_key ) {
|
||||
if ( '_oembed_' === substr( $post_meta_key, 0, 8 ) ) {
|
||||
if ( str_starts_with( $post_meta_key, '_oembed_' ) ) {
|
||||
delete_post_meta( $post_id, $post_meta_key );
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class WP_Http_Cookie {
|
||||
$this->domain = $parsed_url['host'];
|
||||
}
|
||||
$this->path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
|
||||
if ( '/' !== substr( $this->path, -1 ) ) {
|
||||
if ( ! str_ends_with( $this->path, '/' ) ) {
|
||||
$this->path = dirname( $this->path ) . '/';
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ class WP_Http_Cookie {
|
||||
}
|
||||
|
||||
// Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
|
||||
$domain = ( '.' === substr( $domain, 0, 1 ) ) ? substr( $domain, 1 ) : $domain;
|
||||
$domain = ( str_starts_with( $domain, '.' ) ) ? substr( $domain, 1 ) : $domain;
|
||||
if ( substr( $url['host'], -strlen( $domain ) ) !== $domain ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class WP_Http_Encoding {
|
||||
public static function compatible_gzinflate( $gz_data ) {
|
||||
|
||||
// Compressed data might contain a full header, if so strip it for gzinflate().
|
||||
if ( "\x1f\x8b\x08" === substr( $gz_data, 0, 3 ) ) {
|
||||
if ( str_starts_with( $gz_data, "\x1f\x8b\x08" ) ) {
|
||||
$i = 10;
|
||||
$flg = ord( substr( $gz_data, 3, 1 ) );
|
||||
if ( $flg > 0 ) {
|
||||
|
@ -306,7 +306,7 @@ class WP_Network {
|
||||
}
|
||||
|
||||
$this->cookie_domain = $this->domain;
|
||||
if ( 'www.' === substr( $this->cookie_domain, 0, 4 ) ) {
|
||||
if ( str_starts_with( $this->cookie_domain, 'www.' ) ) {
|
||||
$this->cookie_domain = substr( $this->cookie_domain, 4 );
|
||||
}
|
||||
}
|
||||
|
@ -1564,7 +1564,7 @@ class wpdb {
|
||||
$type = substr( $placeholder, -1 );
|
||||
|
||||
if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters
|
||||
&& '%' === substr( $split_query[ $key - 1 ], -1, 1 )
|
||||
&& str_ends_with( $split_query[ $key - 1 ], '%' )
|
||||
) {
|
||||
|
||||
/*
|
||||
@ -1625,7 +1625,7 @@ class wpdb {
|
||||
* Second, if "%s" has a "%" before it, even if it's unrelated (e.g. "LIKE '%%%s%%'").
|
||||
*/
|
||||
if ( true !== $this->allow_unsafe_unquoted_parameters
|
||||
|| ( '' === $format && '%' !== substr( $split_query[ $key - 1 ], -1, 1 ) )
|
||||
|| ( '' === $format && ! str_ends_with( $split_query[ $key - 1 ], '%' ) )
|
||||
) {
|
||||
$placeholder = "'%" . $format . "s'";
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ function get_comment_author_url_link( $link_text = '', $before = '', $after = ''
|
||||
$display = str_replace( 'http://www.', '', $display );
|
||||
$display = str_replace( 'http://', '', $display );
|
||||
|
||||
if ( '/' === substr( $display, -1 ) ) {
|
||||
if ( str_ends_with( $display, '/' ) ) {
|
||||
$display = substr( $display, 0, -1 );
|
||||
}
|
||||
|
||||
|
@ -1042,7 +1042,7 @@ function get_links_list($order = 'name') {
|
||||
|
||||
// Handle link category sorting.
|
||||
$direction = 'ASC';
|
||||
if ( '_' === substr($order,0,1) ) {
|
||||
if ( str_starts_with( $order, '_' ) ) {
|
||||
$direction = 'DESC';
|
||||
$order = substr($order,1);
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ function wptexturize( $text, $reset = false ) {
|
||||
// Only call _wptexturize_pushpop_element if $curl is a delimiter.
|
||||
$first = $curl[0];
|
||||
if ( '<' === $first ) {
|
||||
if ( '<!--' === substr( $curl, 0, 4 ) ) {
|
||||
if ( str_starts_with( $curl, '<!--' ) ) {
|
||||
// This is an HTML comment delimiter.
|
||||
continue;
|
||||
} else {
|
||||
@ -260,7 +260,7 @@ function wptexturize( $text, $reset = false ) {
|
||||
} elseif ( '[' === $first && $found_shortcodes && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
|
||||
// This is a shortcode delimiter.
|
||||
|
||||
if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, -2 ) ) {
|
||||
if ( ! str_starts_with( $curl, '[[' ) && ! str_ends_with( $curl, ']]' ) ) {
|
||||
// Looks like a normal shortcode.
|
||||
_wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
|
||||
} else {
|
||||
@ -2627,7 +2627,7 @@ function force_balance_tags( $text ) {
|
||||
$is_single_tag = in_array( $tag, $single_tags, true );
|
||||
$pre_attribute_ws = isset( $regex[4] ) ? $regex[4] : '';
|
||||
$attributes = trim( isset( $regex[5] ) ? $regex[5] : $regex[3] );
|
||||
$has_self_closer = '/' === substr( $attributes, -1 );
|
||||
$has_self_closer = str_ends_with( $attributes, '/' );
|
||||
|
||||
$newtext .= $tagqueue;
|
||||
|
||||
@ -3693,7 +3693,7 @@ function iso8601_timezone_to_offset( $timezone ) {
|
||||
if ( 'Z' === $timezone ) {
|
||||
$offset = 0;
|
||||
} else {
|
||||
$sign = ( '+' === substr( $timezone, 0, 1 ) ) ? 1 : -1;
|
||||
$sign = ( str_starts_with( $timezone, '+' ) ) ? 1 : -1;
|
||||
$hours = (int) substr( $timezone, 1, 2 );
|
||||
$minutes = (int) substr( $timezone, 3, 4 ) / 60;
|
||||
$offset = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
|
||||
@ -5266,7 +5266,7 @@ function wp_sprintf( $pattern, ...$args ) {
|
||||
*/
|
||||
function wp_sprintf_l( $pattern, $args ) {
|
||||
// Not a match.
|
||||
if ( '%l' !== substr( $pattern, 0, 2 ) ) {
|
||||
if ( ! str_starts_with( $pattern, '%l' ) ) {
|
||||
return $pattern;
|
||||
}
|
||||
|
||||
|
@ -513,7 +513,7 @@ function human_readable_duration( $duration = '' ) {
|
||||
$duration = trim( $duration );
|
||||
|
||||
// Remove prepended negative sign.
|
||||
if ( '-' === substr( $duration, 0, 1 ) ) {
|
||||
if ( str_starts_with( $duration, '-' ) ) {
|
||||
$duration = substr( $duration, 1 );
|
||||
}
|
||||
|
||||
@ -743,7 +743,7 @@ function is_serialized_string( $data ) {
|
||||
return false;
|
||||
} elseif ( ':' !== $data[1] ) {
|
||||
return false;
|
||||
} elseif ( ';' !== substr( $data, -1 ) ) {
|
||||
} elseif ( ! str_ends_with( $data, ';' ) ) {
|
||||
return false;
|
||||
} elseif ( 's' !== $data[0] ) {
|
||||
return false;
|
||||
@ -6361,17 +6361,17 @@ function _wp_timezone_choice_usort_callback( $a, $b ) {
|
||||
// Don't use translated versions of Etc.
|
||||
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
|
||||
// Make the order of these more like the old dropdown.
|
||||
if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
|
||||
if ( str_starts_with( $a['city'], 'GMT+' ) && str_starts_with( $b['city'], 'GMT+' ) ) {
|
||||
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
|
||||
}
|
||||
if ( 'UTC' === $a['city'] ) {
|
||||
if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
|
||||
if ( str_starts_with( $b['city'], 'GMT+' ) ) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if ( 'UTC' === $b['city'] ) {
|
||||
if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
|
||||
if ( str_starts_with( $a['city'], 'GMT+' ) ) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
|
@ -694,10 +694,10 @@ function wp_parse_url( $url, $component = -1 ) {
|
||||
$to_unset = array();
|
||||
$url = (string) $url;
|
||||
|
||||
if ( '//' === substr( $url, 0, 2 ) ) {
|
||||
if ( str_starts_with( $url, '//' ) ) {
|
||||
$to_unset[] = 'scheme';
|
||||
$url = 'placeholder:' . $url;
|
||||
} elseif ( '/' === substr( $url, 0, 1 ) ) {
|
||||
} elseif ( str_starts_with( $url, '/' ) ) {
|
||||
$to_unset[] = 'scheme';
|
||||
$to_unset[] = 'host';
|
||||
$url = 'placeholder://placeholder' . $url;
|
||||
|
@ -1079,12 +1079,12 @@ function wp_kses_split2( $content, $allowed_html, $allowed_protocols ) {
|
||||
$content = wp_kses_stripslashes( $content );
|
||||
|
||||
// It matched a ">" character.
|
||||
if ( '<' !== substr( $content, 0, 1 ) ) {
|
||||
if ( ! str_starts_with( $content, '<' ) ) {
|
||||
return '>';
|
||||
}
|
||||
|
||||
// Allow HTML comments.
|
||||
if ( '<!--' === substr( $content, 0, 4 ) ) {
|
||||
if ( str_starts_with( $content, '<!--' ) ) {
|
||||
$content = str_replace( array( '<!--', '-->' ), '', $content );
|
||||
while ( ( $newstring = wp_kses( $content, $allowed_html, $allowed_protocols ) ) != $content ) {
|
||||
$content = $newstring;
|
||||
|
@ -1181,7 +1181,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) {
|
||||
}
|
||||
|
||||
// Translations are always based on the unminified filename.
|
||||
if ( substr( $relative, -7 ) === '.min.js' ) {
|
||||
if ( str_ends_with( $relative, '.min.js' ) ) {
|
||||
$relative = substr( $relative, 0, -7 ) . '.js';
|
||||
}
|
||||
|
||||
@ -1454,7 +1454,7 @@ function wp_get_installed_translations( $type ) {
|
||||
if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( substr( $file, -3 ) !== '.po' ) {
|
||||
if ( ! str_ends_with( $file, '.po' ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) {
|
||||
|
@ -835,7 +835,7 @@ function wp_get_mu_plugins() {
|
||||
return $mu_plugins;
|
||||
}
|
||||
while ( ( $plugin = readdir( $dh ) ) !== false ) {
|
||||
if ( '.php' === substr( $plugin, -4 ) ) {
|
||||
if ( str_ends_with( $plugin, '.php' ) ) {
|
||||
$mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
|
||||
}
|
||||
}
|
||||
|
@ -1324,7 +1324,7 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
|
||||
* If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain
|
||||
* (which is to say, when they share the domain name of the current request).
|
||||
*/
|
||||
if ( is_ssl() && 'https' !== substr( $image_baseurl, 0, 5 ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
|
||||
if ( is_ssl() && ! str_starts_with( $image_baseurl, 'https' ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
|
||||
$image_baseurl = set_url_scheme( $image_baseurl, 'https' );
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ function get_blog_details( $fields = null, $get_all = true ) {
|
||||
if ( false !== $blog ) {
|
||||
return $blog;
|
||||
}
|
||||
if ( 'www.' === substr( $fields['domain'], 0, 4 ) ) {
|
||||
if ( str_starts_with( $fields['domain'], 'www.' ) ) {
|
||||
$nowww = substr( $fields['domain'], 4 );
|
||||
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
|
||||
} else {
|
||||
@ -155,7 +155,7 @@ function get_blog_details( $fields = null, $get_all = true ) {
|
||||
if ( false !== $blog ) {
|
||||
return $blog;
|
||||
}
|
||||
if ( 'www.' === substr( $fields['domain'], 0, 4 ) ) {
|
||||
if ( str_starts_with( $fields['domain'], 'www.' ) ) {
|
||||
$nowww = substr( $fields['domain'], 4 );
|
||||
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
|
||||
} else {
|
||||
|
@ -295,7 +295,7 @@ function wpmu_admin_do_redirect( $url = '' ) {
|
||||
if ( isset( $_GET['redirect'] ) && isset( $_POST['redirect'] ) && $_GET['redirect'] !== $_POST['redirect'] ) {
|
||||
wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 );
|
||||
} elseif ( isset( $_GET['redirect'] ) ) {
|
||||
if ( 's_' === substr( $_GET['redirect'], 0, 2 ) )
|
||||
if ( str_starts_with( $_GET['redirect'], 's_' ) )
|
||||
$url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
|
||||
} elseif ( isset( $_POST['redirect'] ) ) {
|
||||
$url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
|
||||
|
@ -46,7 +46,7 @@ function wp_get_active_network_plugins() {
|
||||
|
||||
foreach ( $active_plugins as $plugin ) {
|
||||
if ( ! validate_file( $plugin ) // $plugin must validate as file.
|
||||
&& '.php' === substr( $plugin, -4 ) // $plugin must end with '.php'.
|
||||
&& str_ends_with( $plugin, '.php' ) // $plugin must end with '.php'.
|
||||
&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.
|
||||
) {
|
||||
$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
|
||||
@ -229,7 +229,7 @@ function get_site_by_path( $domain, $path, $segments = null ) {
|
||||
// Either www or non-www is supported, not both. If a www domain is requested,
|
||||
// query for both to provide the proper redirect.
|
||||
$domains = array( $domain );
|
||||
if ( 'www.' === substr( $domain, 0, 4 ) ) {
|
||||
if ( str_starts_with( $domain, 'www.' ) ) {
|
||||
$domains[] = substr( $domain, 4 );
|
||||
}
|
||||
|
||||
|
@ -55,10 +55,10 @@ ms_subdomain_constants();
|
||||
if ( ! isset( $current_site ) || ! isset( $current_blog ) ) {
|
||||
|
||||
$domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) );
|
||||
if ( ':80' === substr( $domain, -3 ) ) {
|
||||
if ( str_ends_with( $domain, ':80' ) ) {
|
||||
$domain = substr( $domain, 0, -3 );
|
||||
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
|
||||
} elseif ( ':443' === substr( $domain, -4 ) ) {
|
||||
} elseif ( str_ends_with( $domain, ':443' ) ) {
|
||||
$domain = substr( $domain, 0, -4 );
|
||||
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
$from_email = 'wordpress@';
|
||||
|
||||
if ( null !== $sitename ) {
|
||||
if ( 'www.' === substr( $sitename, 0, 4 ) ) {
|
||||
if ( str_starts_with( $sitename, 'www.' ) ) {
|
||||
$sitename = substr( $sitename, 4 );
|
||||
}
|
||||
|
||||
@ -1557,7 +1557,7 @@ if ( ! function_exists( 'wp_validate_redirect' ) ) :
|
||||
function wp_validate_redirect( $location, $fallback_url = '' ) {
|
||||
$location = wp_sanitize_redirect( trim( $location, " \t\n\r\0\x08\x0B" ) );
|
||||
// Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
|
||||
if ( '//' === substr( $location, 0, 2 ) ) {
|
||||
if ( str_starts_with( $location, '//' ) ) {
|
||||
$location = 'http:' . $location;
|
||||
}
|
||||
|
||||
|
@ -505,10 +505,10 @@ if ( ! class_exists( 'PO', false ) ) :
|
||||
* @return string
|
||||
*/
|
||||
public static function trim_quotes( $s ) {
|
||||
if ( '"' === substr( $s, 0, 1 ) ) {
|
||||
if ( str_starts_with( $s, '"' ) ) {
|
||||
$s = substr( $s, 1 );
|
||||
}
|
||||
if ( '"' === substr( $s, -1, 1 ) ) {
|
||||
if ( str_ends_with( $s, '"' ) ) {
|
||||
$s = substr( $s, 0, -1 );
|
||||
}
|
||||
return $s;
|
||||
|
@ -6762,7 +6762,7 @@ function wp_mime_type_icon( $mime = 0 ) {
|
||||
if ( $dh ) {
|
||||
while ( false !== $file = readdir( $dh ) ) {
|
||||
$file = wp_basename( $file );
|
||||
if ( '.' === substr( $file, 0, 1 ) ) {
|
||||
if ( str_starts_with( $file, '.' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -7813,7 +7813,7 @@ function wp_add_trashed_suffix_to_post_name_for_post( $post ) {
|
||||
|
||||
$post = get_post( $post );
|
||||
|
||||
if ( '__trashed' === substr( $post->post_name, -9 ) ) {
|
||||
if ( str_ends_with( $post->post_name, '__trashed' ) ) {
|
||||
return $post->post_name;
|
||||
}
|
||||
add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name );
|
||||
|
@ -423,7 +423,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) {
|
||||
if ( $ignore_html || str_starts_with( $element, '<!--' ) || str_starts_with( $element, '<![CDATA[' ) ) {
|
||||
// Encode all '[' and ']' chars.
|
||||
$element = strtr( $element, $trans );
|
||||
continue;
|
||||
|
@ -986,7 +986,7 @@ function get_blogs_of_user( $user_id, $all = false ) {
|
||||
$keys = array_keys( $keys );
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
if ( 'capabilities' !== substr( $key, -12 ) ) {
|
||||
if ( ! str_ends_with( $key, 'capabilities' ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( $wpdb->base_prefix && ! str_starts_with( $key, $wpdb->base_prefix ) ) {
|
||||
|
@ -39,7 +39,7 @@ if ( is_admin() ) {
|
||||
} else {
|
||||
preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
|
||||
$pagenow = strtolower( $self_matches[1] );
|
||||
if ( '.php' !== substr( $pagenow, -4, 4 ) ) {
|
||||
if ( ! str_ends_with( $pagenow, '.php' ) ) {
|
||||
$pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried).
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.3-alpha-55989';
|
||||
$wp_version = '6.3-alpha-55990';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
@ -908,7 +908,7 @@ function is_active_widget( $callback = false, $widget_id = false, $id_base = fal
|
||||
|
||||
if ( is_array( $sidebars_widgets ) ) {
|
||||
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
|
||||
if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
|
||||
if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || str_starts_with( $sidebar, 'orphaned_widgets' ) ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1382,7 +1382,7 @@ function wp_map_sidebars_widgets( $existing_sidebars_widgets ) {
|
||||
}
|
||||
|
||||
foreach ( $existing_sidebars_widgets as $sidebar => $widgets ) {
|
||||
if ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
|
||||
if ( 'wp_inactive_widgets' === $sidebar || str_starts_with( $sidebar, 'orphaned_widgets' ) ) {
|
||||
$new_sidebars_widgets['wp_inactive_widgets'] = array_merge( $new_sidebars_widgets['wp_inactive_widgets'], (array) $widgets );
|
||||
unset( $existing_sidebars_widgets[ $sidebar ] );
|
||||
}
|
||||
@ -1490,7 +1490,7 @@ function wp_map_sidebars_widgets( $existing_sidebars_widgets ) {
|
||||
|
||||
// Remove orphaned widgets, we're only interested in previously active sidebars.
|
||||
foreach ( $old_sidebars_widgets as $sidebar => $widgets ) {
|
||||
if ( 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
|
||||
if ( str_starts_with( $sidebar, 'orphaned_widgets' ) ) {
|
||||
unset( $old_sidebars_widgets[ $sidebar ] );
|
||||
}
|
||||
}
|
||||
@ -1627,7 +1627,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
|
||||
$summary = $desc;
|
||||
|
||||
// Change existing [...] to […].
|
||||
if ( '[...]' === substr( $summary, -5 ) ) {
|
||||
if ( str_ends_with( $summary, '[...]' ) ) {
|
||||
$summary = substr( $summary, 0, -5 ) . '[…]';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user