Advertisement
tolikpunkoff

raw-formatter

Feb 13th, 2017
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: raw-formatter
  4.  */
  5.  
  6. function my_formatter($content) {
  7. $new_content = '';
  8. $pattern_full = '{(\[raw\].*?\[/raw\])}is';
  9. $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
  10. $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
  11.  
  12. foreach ($pieces as $piece) {
  13. if (preg_match($pattern_contents, $piece, $matches)) {
  14. $new_content .= $matches[1];
  15. } else {
  16. $new_content .= wptexturize(wpautop($piece));
  17. }
  18. }
  19.  
  20. return $new_content;
  21. }
  22.  
  23. remove_filter('the_content', 'wpautop');
  24. remove_filter('the_content', 'wptexturize');
  25.  
  26. add_filter('the_content', 'my_formatter', 99);
  27.  
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement