• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / _wp_check_existing_file_names() – Helper function to check if a file name could match an existing image sub-size file name.

You appear to be a bot. Output may be restricted

Description

Helper function to check if a file name could match an existing image sub-size file name.

Usage

$bool = _wp_check_existing_file_names( $filename, $files );

Parameters

$filename
( string ) required – The file name to check.
$files
( array ) required – An array of existing files in the directory.

Returns

bool True if the tested file name could match an existing file, false otherwise.

Source

File name: wordpress/wp-includes/functions.php
Lines:

1 to 23 of 23
function _wp_check_existing_file_names( $filename, $files ) {
  $fname = pathinfo( $filename, PATHINFO_FILENAME );
  $ext   = pathinfo( $filename, PATHINFO_EXTENSION );

  // Edge case, file names like `.ext`.
  if ( empty( $fname ) ) {
    return false;
  }

  if ( $ext ) {
    $ext = ".$ext";
  }

  $regex = '/^' . preg_quote( $fname ) . '-(?:\d+x\d+|scaled|rotated)' . preg_quote( $ext ) . '$/i';

  foreach ( $files as $file ) {
    if ( preg_match( $regex, $file ) ) {
      return true;
    }
  }

  return false;
}
 

 View on GitHub View on Trac

Published: 13th December 2019 | Last updated: 2nd April 2020

Primary Sidebar

Information

Function name: _wp_check_existing_file_names
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/functions.php
File ref: wp-includes/functions.php
API type: private
Deprecated?: No
API Letters: _,C,E,F,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites