before_last_bar

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

WordPress Version: 6.2

/**
 * Removes last item on a pipe-delimited string.
 *
 * Meant for removing the last item in a string, such as 'Role name|User role'. The original
 * string will be returned if no pipe '|' characters are found in the string.
 *
 * @since 2.8.0
 *
 * @param string $text A pipe-delimited string.
 * @return string Either $text or everything before the last pipe.
 */
function before_last_bar($text)
{
    $last_bar = strrpos($text, '|');
    if (false === $last_bar) {
        return $text;
    } else {
        return substr($text, 0, $last_bar);
    }
}

WordPress Version: 6.1

/**
 * Removes last item on a pipe-delimited string.
 *
 * Meant for removing the last item in a string, such as 'Role name|User role'. The original
 * string will be returned if no pipe '|' characters are found in the string.
 *
 * @since 2.8.0
 *
 * @param string $string A pipe-delimited string.
 * @return string Either $string or everything before the last pipe.
 */
function before_last_bar($string)
{
    $last_bar = strrpos($string, '|');
    if (false === $last_bar) {
        return $string;
    } else {
        return substr($string, 0, $last_bar);
    }
}

WordPress Version: 4.3

/**
 * Remove last item on a pipe-delimited string.
 *
 * Meant for removing the last item in a string, such as 'Role name|User role'. The original
 * string will be returned if no pipe '|' characters are found in the string.
 *
 * @since 2.8.0
 *
 * @param string $string A pipe-delimited string.
 * @return string Either $string or everything before the last pipe.
 */
function before_last_bar($string)
{
    $last_bar = strrpos($string, '|');
    if (false === $last_bar) {
        return $string;
    } else {
        return substr($string, 0, $last_bar);
    }
}

WordPress Version: 3.7

/**
 * Remove last item on a pipe-delimited string.
 *
 * Meant for removing the last item in a string, such as 'Role name|User role'. The original
 * string will be returned if no pipe '|' characters are found in the string.
 *
 * @since 2.8.0
 *
 * @param string $string A pipe-delimited string.
 * @return string Either $string or everything before the last pipe.
 */
function before_last_bar($string)
{
    $last_bar = strrpos($string, '|');
    if (false == $last_bar) {
        return $string;
    } else {
        return substr($string, 0, $last_bar);
    }
}