wp_register_plugin_realpath

The timeline below displays how wordpress function wp_register_plugin_realpath has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Register a plugin's real path.
 *
 * This is used in plugin_basename() to resolve symlinked paths.
 *
 * @since 3.9.0
 *
 * @see wp_normalize_path()
 *
 * @global array $wp_plugin_paths
 *
 * @param string $file Known path to the file.
 * @return bool Whether the path was able to be registered.
 */
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;
}

WordPress Version: 5.4

/**
 * Register a plugin's real path.
 *
 * This is used in plugin_basename() to resolve symlinked paths.
 *
 * @since 3.9.0
 *
 * @see wp_normalize_path()
 *
 * @global array $wp_plugin_paths
 *
 * @staticvar string $wp_plugin_path
 * @staticvar string $wpmu_plugin_path
 *
 * @param string $file Known path to the file.
 * @return bool Whether the path was able to be registered.
 */
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;
}

WordPress Version: 4.6

/**
 * Register a plugin's real path.
 *
 * This is used in plugin_basename() to resolve symlinked paths.
 *
 * @since 3.9.0
 *
 * @see wp_normalize_path()
 *
 * @global array $wp_plugin_paths
 *
 * @staticvar string $wp_plugin_path
 * @staticvar string $wpmu_plugin_path
 *
 * @param string $file Known path to the file.
 * @return bool Whether the path was able to be registered.
 */
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;
}

WordPress Version: 4.3

/**
 * Register a plugin's real path.
 *
 * This is used in plugin_basename() to resolve symlinked paths.
 *
 * @since 3.9.0
 *
 * @see plugin_basename()
 *
 * @global array $wp_plugin_paths
 *
 * @staticvar string $wp_plugin_path
 * @staticvar string $wpmu_plugin_path
 *
 * @param string $file Known path to the file.
 * @return bool Whether the path was able to be registered.
 */
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;
}

WordPress Version: 3.9

/**
 * Register a plugin's real path.
 *
 * This is used in plugin_basename() to resolve symlinked paths.
 *
 * @since 3.9.0
 *
 * @see plugin_basename()
 *
 * @param string $file Known path to the file.
 * @return bool Whether the path was able to be registered.
 */
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, $wpmu_plugin_path;
    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;
}