Encodes text in posts between special quicktags.

Check out the article/tutorial →

<?php
function dbdb_quick_encode($content_text) {
$charset = get_bloginfo('charset');
$replaced_text = preg_replace('#(<!--encode-->)(.*?)(<!--/encode-->)#isme', "'$1'.str_replace(array('<!--nextpage-->', '<!--more-->'), array('&lt;!--nextpage--&gt;', '&lt;!--more--&gt;'), '$2').'$3'", $content_text);
foreach($replaced_text as $k => $v ) {
$encoded_text[$k] = str_replace(array('"'),array('"'), $v);
}
return $encoded_text;
};
add_filter('wp_insert_post_data','dbdb_quick_encode', 1, 1);
function dbdb_post_encode($text) {
$text = str_replace(array("rn", "r"), "n", $text);
$text = preg_replace_callback("#(<!--encode-->)(.*?)(<!--/encode-->)#is", 'dbdb_code_encode', $text);
return $text;
};
add_filter('the_content','dbdb_post_encode', 1, 1);
function dbdb_code_encode( $matches ) {
$charset = get_bloginfo('charset');
$text = trim($matches[2]);
$text = str_replace(array('&lt;!--nextpage--&gt;', '&lt;!--more--&gt;'), array('<!--nextpage-->', '<!--more-->'), $text);
$text = htmlspecialchars($text, ENT_QUOTES, $charset);
$text = str_replace('[','&#91;', $text);
$text = str_replace(array("rn", "r"), "n", $text);
$text = preg_replace("#nnn+#", "nn", $text);
if ( "<!--encode-->" != $matches[1] ) {
$text = $matches[1].$text.$matches[3];
}
return $text;
};
view raw raw_html.php hosted with ❤ by GitHub
Tagged: