path_is_absolute

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

WordPress Version: 6.1

/**
 * Tests if a given filesystem path is absolute.
 *
 * For example, '/foo/bar', or 'c:\windows'.
 *
 * @since 2.5.0
 *
 * @param string $path File path.
 * @return bool True if path is absolute, false is not absolute.
 */
function path_is_absolute($path)
{
    /*
     * Check to see if the path is a stream and check to see if its an actual
     * path or file as realpath() does not support stream wrappers.
     */
    if (wp_is_stream($path) && (is_dir($path) || is_file($path))) {
        return true;
    }
    /*
     * This is definitive if true but fails if $path does not exist or contains
     * a symbolic link.
     */
    if (realpath($path) === $path) {
        return true;
    }
    if (strlen($path) === 0 || '.' === $path[0]) {
        return false;
    }
    // Windows allows absolute paths like this.
    if (preg_match('#^[a-zA-Z]:\\\\#', $path)) {
        return true;
    }
    // A path starting with / or \ is absolute; anything else is relative.
    return '/' === $path[0] || '\\' === $path[0];
}

WordPress Version: 5.4

/**
 * Test if a given filesystem path is absolute.
 *
 * For example, '/foo/bar', or 'c:\windows'.
 *
 * @since 2.5.0
 *
 * @param string $path File path.
 * @return bool True if path is absolute, false is not absolute.
 */
function path_is_absolute($path)
{
    /*
     * Check to see if the path is a stream and check to see if its an actual
     * path or file as realpath() does not support stream wrappers.
     */
    if (wp_is_stream($path) && (is_dir($path) || is_file($path))) {
        return true;
    }
    /*
     * This is definitive if true but fails if $path does not exist or contains
     * a symbolic link.
     */
    if (realpath($path) == $path) {
        return true;
    }
    if (strlen($path) == 0 || '.' === $path[0]) {
        return false;
    }
    // Windows allows absolute paths like this.
    if (preg_match('#^[a-zA-Z]:\\\\#', $path)) {
        return true;
    }
    // A path starting with / or \ is absolute; anything else is relative.
    return '/' === $path[0] || '\\' === $path[0];
}

WordPress Version: 5.2

/**
 * Test if a given filesystem path is absolute.
 *
 * For example, '/foo/bar', or 'c:\windows'.
 *
 * @since 2.5.0
 *
 * @param string $path File path.
 * @return bool True if path is absolute, false is not absolute.
 */
function path_is_absolute($path)
{
    /*
     * Check to see if the path is a stream and check to see if its an actual
     * path or file as realpath() does not support stream wrappers.
     */
    if (wp_is_stream($path) && (is_dir($path) || is_file($path))) {
        return true;
    }
    /*
     * This is definitive if true but fails if $path does not exist or contains
     * a symbolic link.
     */
    if (realpath($path) == $path) {
        return true;
    }
    if (strlen($path) == 0 || $path[0] == '.') {
        return false;
    }
    // Windows allows absolute paths like this.
    if (preg_match('#^[a-zA-Z]:\\\\#', $path)) {
        return true;
    }
    // A path starting with / or \ is absolute; anything else is relative.
    return $path[0] == '/' || $path[0] == '\\';
}

WordPress Version: 4.9

/**
 * Test if a given filesystem path is absolute.
 *
 * For example, '/foo/bar', or 'c:\windows'.
 *
 * @since 2.5.0
 *
 * @param string $path File path.
 * @return bool True if path is absolute, false is not absolute.
 */
function path_is_absolute($path)
{
    /*
     * This is definitive if true but fails if $path does not exist or contains
     * a symbolic link.
     */
    if (realpath($path) == $path) {
        return true;
    }
    if (strlen($path) == 0 || $path[0] == '.') {
        return false;
    }
    // Windows allows absolute paths like this.
    if (preg_match('#^[a-zA-Z]:\\\\#', $path)) {
        return true;
    }
    // A path starting with / or \ is absolute; anything else is relative.
    return $path[0] == '/' || $path[0] == '\\';
}

WordPress Version: 4.0

/**
 * Test if a give filesystem path is absolute.
 *
 * For example, '/foo/bar', or 'c:\windows'.
 *
 * @since 2.5.0
 *
 * @param string $path File path.
 * @return bool True if path is absolute, false is not absolute.
 */
function path_is_absolute($path)
{
    /*
     * This is definitive if true but fails if $path does not exist or contains
     * a symbolic link.
     */
    if (realpath($path) == $path) {
        return true;
    }
    if (strlen($path) == 0 || $path[0] == '.') {
        return false;
    }
    // Windows allows absolute paths like this.
    if (preg_match('#^[a-zA-Z]:\\\\#', $path)) {
        return true;
    }
    // A path starting with / or \ is absolute; anything else is relative.
    return $path[0] == '/' || $path[0] == '\\';
}

WordPress Version: 3.7

/**
 * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows').
 *
 * @since 2.5.0
 *
 * @param string $path File path
 * @return bool True if path is absolute, false is not absolute.
 */
function path_is_absolute($path)
{
    // this is definitive if true but fails if $path does not exist or contains a symbolic link
    if (realpath($path) == $path) {
        return true;
    }
    if (strlen($path) == 0 || $path[0] == '.') {
        return false;
    }
    // windows allows absolute paths like this
    if (preg_match('#^[a-zA-Z]:\\\\#', $path)) {
        return true;
    }
    // a path starting with / or \ is absolute; anything else is relative
    return $path[0] == '/' || $path[0] == '\\';
}