wp_normalize_path( string $path ): string
- Since
- 3.9.0, 4.4.0, 4.5.0, 4.9.7, 7.0.0
- Source
wp-includes/functions.php:2194
Normalizes a filesystem path.
Description
On windows systems, replaces backslashes with forward slashes and forces upper-case drive letters.Allows for two leading slashes for Windows network shares, but ensures that all other duplicate slashes are reduced to a single.
Parameters
$pathstring- Path to normalize.
Return
string- Normalized path.
Uses · 1
- wp_is_stream()Tests if a given path is a stream URL
Used by · 26
- Theme_Installer_Skin::do_overwrite()Checks if the theme can be overwritten and outputs the HTML for overwriting a theme on upload.
- WP_Block_Metadata_Registry::get_collection_block_metadata_files()Gets the list of absolute paths to all block metadata files that are part of the given collection.
- WP_Block_Metadata_Registry::get_default_collection_roots()Gets the default collection root directory paths.
- WP_Block_Metadata_Registry::get_metadata()Retrieves block metadata for a given block within a specific collection.
- WP_Block_Metadata_Registry::register_collection()Registers a block metadata collection.
- WP_Font_Collection::load_from_json()Loads font collection data from a JSON file or URL.
- WP_REST_Attachments_Controller::get_attachment_upload_subdir()Returns the uploads subdirectory an attachment is stored in.
- WP_Recovery_Mode::get_extension_for_error()Gets the extension that the error occurred in.
- _get_plugin_from_callback()Internal helper function to find the plugin from a meta box callback.
- _wp_connectors_resolve_ai_provider_logo_url()Resolves an AI provider logo file path to a URL.
- get_block_asset_url()Gets the URL to a block asset.
- plugin_basename()Gets the basename of a plugin.
Show all 26
- plugins_url()Retrieves a URL within the plugins or mu-plugins directory.
- register_block_script_handle()Finds a script handle for the selected block metadata field.
- register_block_script_module_id()Finds a script module ID for the selected block metadata field.
- register_block_style_handle()Finds a style handle for the block metadata field.
- register_block_type_from_metadata()Registers a block type from the metadata stored in the `block.json` file.
- register_core_block_style_handles()Registers core block style handles.
- validate_file()Validates a file name and path against an allowed set of rules.
- wp_debug_backtrace_summary()Returns a comma-separated string or array of functions that have been called to get to the current point in code.
- wp_delete_file_from_directory()Deletes a file if its path is within the given directory.
- wp_generate_block_templates_export_file()Creates an export of the current templates and template parts from the site editor at the specified path in a ZIP file.
- wp_json_file_decode()Reads and decodes a JSON file.
- wp_privacy_generate_personal_data_export_file()Generate the personal data export file.
- wp_register_plugin_realpath()Register a plugin's real path.
- wp_validate_redirect()Validates a URL for use in a redirect.
Source
function wp_normalize_path( $path ): string { $path = (string) $path; static $cache = array(); if ( isset( $cache[ $path ] ) ) { return $cache[ $path ]; } $original_path = $path; $wrapper = ''; if ( wp_is_stream( $path ) ) { list( $wrapper, $path ) = explode( '://', $path, 2 ); $wrapper .= '://'; } // Standardize all paths to use '/'. $path = str_replace( '\\', '/', $path ); // Replace multiple slashes down to a singular, allowing for network shares having two slashes. $path = (string) preg_replace( '|(?<=.)/+|', '/', $path ); // Windows paths should uppercase the drive letter. if ( ':' === substr( $path, 1, 1 ) ) { $path = ucfirst( $path ); } $cache[ $original_path ] = $wrapper . $path; return $cache[ $original_path ];}History
Introduced in 3.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.0.0
Uses a static cache to store normalized paths.from the docblock
4.9.7
Allows for PHP file wrappers.from the docblock
4.5.0
Allows for Windows network shares.from the docblock
4.4.0
Ensures upper-case drive letters on Windows systems.from the docblock
3.9.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/functions.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.