before_last_bar( string $string )

Remove last item on a pipe-delimited string.


Description Description

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.


Parameters Parameters

$string

(string) (Required) A pipe-delimited string.


Top ↑

Return Return

(string) Either $string or everything before the last pipe.


Top ↑

Source Source

File: wp-includes/l10n.php

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

Top ↑

Changelog Changelog

Changelog
Version Description
2.8.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.