before_last_bar()WP 2.8.0

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.

Хуков нет.

Возвращает

Строку. Either $text or everything before the last pipe.

Использование

before_last_bar( $text );
$text(строка) (обязательный)
A pipe-delimited string.

Список изменений

С версии 2.8.0 Введена.

Код before_last_bar() WP 6.5.2

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