<?php
/*
Plugin Name: Break Comment Text
Plugin URI: http://wordpress.org/support/topic/58622
Description: Break long (unspaced) strings of text in comments (for "wrap-a-bility").
Version: 0.2
Author: Kaf Oseo
Author URI: http://szub.net
Copyright (c) 2004, 2006 Kaf Oseo (http://szub.net)
Break Comment Text is released under the GNU General Public
License (GPL) http://www.gnu.org/licenses/gpl.txt
This is a WordPress plugin (http://wordpress.org).
~Changelog:
0.2 (Jan-29-2006)
Plugin made more *hands-off* by not requiring changes to any template
or template tag.
*/
function szub_break_text($text) {
/* >> user-configurable variables */
$cols = 60; // maximum (characters) allowed for text string
$break = ' '; // break character (space is default)
/* << user-configurable variables */
$len = strlen($text);
$tag = 0;
for ($i = 0; $i < $len; $i++) {
$chr = $text[$i];
if ($chr == '<') {
$tag = 1;
} elseif ($chr == '>') {
$tag = 0;
}
if (ctype_space($chr)) {
$cols_len = 0;
} else {
$cols_len++;
}
if ((!$tag) && ($cols_len >= $cols)) {
$chr .= $break;
$cols_len = 0;
}
$cut_text .= $chr;
}
return $cut_text;
}
add_filter('comment_text', 'szub_break_text', 42);
?>