Balances tags if forced to, or if the ‘use_balanceTags’ option is set to true.
Parameters
$text
stringrequired- Text to be balanced
$force
booloptional- If true, forces balancing, ignoring the value of the option.
Default:
false
Source
function balanceTags( $text, $force = false ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( $force || (int) get_option( 'use_balanceTags' ) === 1 ) {
return force_balance_tags( $text );
} else {
return $text;
}
}
Changelog
Version | Description |
---|---|
0.71 | Introduced. |
Unclosed LI tags
Will output this HTML:
The `use_balanceTags` option has default 0. The admin UI for it was removed several years ago, along with the UI for `use_smilies` (default 1), in Dashboard/Settings/Writing. So the core filters calling `balanceTags() `, such as ‘content_save_pre’, do nothing unless the user set an option in the distant past, or a plugin/theme changed the setting.
The bug ticket back then said the TinyMCE editor handles the balancing in ‘Visual’ mode, and users in ‘Text’ mode should be allowed to do their own balancing, by default. Opinion changed to that as the ticket developed: https://core.trac.wordpress.org/ticket/5161
Most coders will want to use `force_balance_tags() ` instead of `balanceTags() `.