WP_Textdomain_Registry::get_language_files_from_path( string $path ): array
- Since
- 6.5.0
- Source
wp-includes/class-wp-textdomain-registry.php:180
Description
Allows early retrieval through the 'pre_get_mo_files_from_path' filter to optimize performance, especially in directories with many files.
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pathstring- The directory path to search for translation files.
Return value
array- Array of translation file paths. Can contain .mo and .l10n.php files.
Performance profile
How much work a call to WP_Textdomain_Registry::get_language_files_from_path() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 16–54
- Plugin surface
- 1 hook
- Called by
- 1
Reads or writes the filesystem via glob().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 55.
Third-party callbacks on 'pre_get_language_files_from_path' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()called directly - filesystemfilesystem access
glob()called directly
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Textdomain_Registry::get_language_files_from_path() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$files !== null | 16 | rtrim(), apply_filters() |
$files === null && $files !== false | 27 | rtrim(), apply_filters(), md5(), wp_cache_get() |
$files === null && $files === false && !is_array($php_files) | 48–49 | rtrim(), apply_filters(), md5(), wp_cache_get(), glob(), glob(), wp_cache_set() |
$files === null && $files === false && is_array($php_files) | 53–54 | rtrim(), apply_filters(), md5(), wp_cache_get(), glob(), glob(), array_merge(), wp_cache_set() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 55 instructions, 16–54 executed per call, 4 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while WP_Textdomain_Registry::get_language_files_from_path() runs, in this order:
- apply_filters( pre_get_language_files_from_path )filterline 197 (+17 into the body)
Filters the translation files retrieved from a specified path before the actual lookup.
Uses · 3
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- wp_cache_set()Saves the data to the cache.
Used by · 1
- WP_Textdomain_Registry::get_path_from_lang_dir()Gets the path to the language directory for the current domain and locale.
Source code
public function get_language_files_from_path( $path ) { $path = rtrim( $path, '/' ) . '/'; /** * Filters the translation files retrieved from a specified path before the actual lookup. * * Returning a non-null value from the filter will effectively short-circuit * the MO files lookup, returning that value instead. * * This can be useful in situations where the directory contains a large number of files * and the default glob() function becomes expensive in terms of performance. * * @since 6.5.0 * * @param null|array $files List of translation files. Default null. * @param string $path The path from which translation files are being fetched. */ $files = apply_filters( 'pre_get_language_files_from_path', null, $path ); if ( null !== $files ) { return $files; } $cache_key = md5( $path ); $files = wp_cache_get( $cache_key, 'translation_files' ); if ( false === $files ) { $files = glob( $path . '*.mo' ); if ( false === $files ) { $files = array(); } $php_files = glob( $path . '*.l10n.php' ); if ( is_array( $php_files ) ) { $files = array_merge( $files, $php_files ); } wp_cache_set( $cache_key, $files, 'translation_files', HOUR_IN_SECONDS ); } return $files; }Changelog
Introduced in 6.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-textdomain-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.