diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index ad48c2f3b4..9e9315dede 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -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'] : ''; diff --git a/wp-admin/includes/class-core-upgrader.php b/wp-admin/includes/class-core-upgrader.php index 138f904e22..dc8fb4b806 100644 --- a/wp-admin/includes/class-core-upgrader.php +++ b/wp-admin/includes/class-core-upgrader.php @@ -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 ) { diff --git a/wp-admin/includes/class-language-pack-upgrader.php b/wp-admin/includes/class-language-pack-upgrader.php index 8f99dd35e8..0309570031 100644 --- a/wp-admin/includes/class-language-pack-upgrader.php +++ b/wp-admin/includes/class-language-pack-upgrader.php @@ -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; } } diff --git a/wp-admin/includes/class-wp-screen.php b/wp-admin/includes/class-wp-screen.php index 1901bc8f25..739a182ded 100644 --- a/wp-admin/includes/class-wp-screen.php +++ b/wp-admin/includes/class-wp-screen.php @@ -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'; diff --git a/wp-admin/includes/class-wp-site-health-auto-updates.php b/wp-admin/includes/class-wp-site-health-auto-updates.php index 15b382ceb8..d1655eb1d8 100644 --- a/wp-admin/includes/class-wp-site-health-auto-updates.php +++ b/wp-admin/includes/class-wp-site-health-auto-updates.php @@ -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 ) ) { diff --git a/wp-admin/includes/deprecated.php b/wp-admin/includes/deprecated.php index 63aa7f7fa0..91d47446f5 100644 --- a/wp-admin/includes/deprecated.php +++ b/wp-admin/includes/deprecated.php @@ -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; } diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 562fece43e..3ead3d98cd 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -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; } diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 8313c0235d..a8e5f18a70 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -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 ) { ?>