On this page
before_last_bar( string $string ): string
Removes last item on a pipe-delimited string.
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
$stringstring Required-
A pipe-delimited string.
Return
string Either $string or everything before the last pipe.
Source
File: wp-includes/l10n.php. View all references
function before_last_bar( $string ) {
$last_bar = strrpos( $string, '|' );
if ( false === $last_bar ) {
return $string;
} else {
return substr( $string, 0, $last_bar );
}
}
Related
Used By
| Used By | Description |
|---|---|
| translate_user_role() wp-includes/l10n.php | Translates role name. |
| _c() wp-includes/deprecated.php | Retrieve translated string with vertical bar context |
| translate_with_context() wp-includes/deprecated.php | Translates $text like translate() , but assumes that the text contains a context after its last vertical bar. |
| _nc() wp-includes/deprecated.php | Legacy version of _n() , which supports contexts. |
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/before_last_bar