Gettext_Translations::parenthesize_plural_exression()
Deprecated from version 6.5.0. It is no longer supported and can be removed in future releases. Use
Plural_Forms class
instead.Adds parentheses to the inner parts of ternary operators in plural expressions, because PHP evaluates ternary operators from left to right
Method of the class: Gettext_Translations{}
No Hooks.
Return
String
. the expression with parentheses added
Usage
$Gettext_Translations = new Gettext_Translations(); $Gettext_Translations->parenthesize_plural_exression( $expression );
- $expression(string) (required)
- the expression without parentheses
Notes
- See: Plural_Forms
Changelog
Since 2.8.0 | Introduced. |
Deprecated since 6.5.0 | Use the Plural_Forms class instead. |
Gettext_Translations::parenthesize_plural_exression() Gettext Translations::parenthesize plural exression code WP 6.5.2
public function parenthesize_plural_exression( $expression ) { $expression .= ';'; $res = ''; $depth = 0; for ( $i = 0; $i < strlen( $expression ); ++$i ) { $char = $expression[ $i ]; switch ( $char ) { case '?': $res .= ' ? ('; ++$depth; break; case ':': $res .= ') : ('; break; case ';': $res .= str_repeat( ')', $depth ) . ';'; $depth = 0; break; default: $res .= $char; } } return rtrim( $res, ';' ); }