wp_register_plugin_realpath() WordPress Function

The wp_register_plugin_realpath() function allows a plugin to register its real path with WordPress. This is useful for plugins that need to store data in files outside of the WordPress directory, such as when using the wp_filesystem() function.

wp_register_plugin_realpath( string $file ) #

Register a plugin’s real path.


Description

This is used in plugin_basename() to resolve symlinked paths.

Top ↑

See also


Top ↑

Parameters

$file

(string)(Required)Known path to the file.


Top ↑

Return

(bool) Whether the path was able to be registered.


Top ↑

Source

File: wp-includes/plugin.php

function wp_register_plugin_realpath( $file ) {
	global $wp_plugin_paths;

	// Normalize, but store as static to avoid recalculation of a constant value.
	static $wp_plugin_path = null, $wpmu_plugin_path = null;

	if ( ! isset( $wp_plugin_path ) ) {
		$wp_plugin_path   = wp_normalize_path( WP_PLUGIN_DIR );
		$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
	}

	$plugin_path     = wp_normalize_path( dirname( $file ) );
	$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );

	if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) {
		return false;
	}

	if ( $plugin_path !== $plugin_realpath ) {
		$wp_plugin_paths[ $plugin_path ] = $plugin_realpath;
	}

	return true;
}


Top ↑

Changelog

Changelog
VersionDescription
3.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.