Last active
February 13, 2016 02:13
-
-
Save dboutote/72de272491da33a02285 to your computer and use it in GitHub Desktop.
Encoding HTML in WordPress Posts: https://wordpress.org/plugins/wp-post-encode/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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('<!--nextpage-->', '<!--more-->'), '$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('<!--nextpage-->', '<!--more-->'), array('<!--nextpage-->', '<!--more-->'), $text); | |
$text = htmlspecialchars($text, ENT_QUOTES, $charset); | |
$text = str_replace('[','[', $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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment