# before_last_bar()

URL: https://chugunov.pro/api-wordpress/functions/before_last_bar/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.8.0.

## Сигнатура

```php
before_last_bar( string $text ): string
```

## Описание

Предназначена для удаления последнего элемента в строке, например ‘Role name|User role’. Если в строке нет символов вертикальной черты ‘|’, возвращается исходная строка.

## Параметры

- `$text` `string` — обязательный. Строка, разделённая вертикальными чертами.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/l10n.php:236`

```php
function before_last_bar( $text ) {
	$last_bar = strrpos( $text, '|' );
	if ( false === $last_bar ) {
		return $text;
	} else {
		return substr( $text, 0, $last_bar );
	}
}
```

## История изменений

- 2.8.0 — Introduced.

## Связанные

Используется в: [`translate_user_role`](https://chugunov.pro/api-wordpress/functions/translate_user_role/), [`_c`](https://chugunov.pro/api-wordpress/functions/_c/), [`translate_with_context`](https://chugunov.pro/api-wordpress/functions/translate_with_context/), [`translate`](https://chugunov.pro/api-wordpress/functions/translate/), [`_nc`](https://chugunov.pro/api-wordpress/functions/_nc/), [`_n`](https://chugunov.pro/api-wordpress/functions/_n/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/before_last_bar/
