[wp-trac] [WordPress Trac] #4298: wpautop bugs

WordPress Trac wp-trac at lists.automattic.com
Tue Dec 8 08:11:52 UTC 2009


#4298: wpautop bugs
-------------------------------+--------------------------------------------
 Reporter:  Denis-de-Bernardy  |       Owner:  markjaquith      
     Type:  defect (bug)       |      Status:  accepted         
 Priority:  low                |   Milestone:  3.0              
Component:  Formatting         |     Version:  2.7              
 Severity:  minor              |    Keywords:  needs-patch early
-------------------------------+--------------------------------------------
Changes (by Denis-de-Bernardy):

  * keywords:  has-patch tested commit early => needs-patch early


Comment:

 A quick note on this one, because an issue was brought to my attention a
 few weeks ago. My patch actually breaks things such as:

 {{{
 <?php
 $foo = $bar;
 ?>
 }}}

 What I'm currently doing, in case it inspires a better solution:

 {{{
         /**
          * fix_wpautop()
          *
          * @param string $content
          * @return string $content
          **/

         function fix_wpautop($content) {
                 $content = str_replace(array("\r\n", "\r"), "\n",
 $content);

                 if ( !preg_match("/<[a-z][^<>]*\n/i", $content) )
                         return $content;

                 global $sem_fixes_escape;
                 $sem_fixes_escape = array();

                 $content = preg_replace_callback("/<\?php.+\?>/is",
 array('sem_fixes_admin', 'escape_php_callback'), $content);

                 while ( preg_match("/<[a-z][^<>]*\n/i", $content) ) {
                         $content = preg_replace("/(<[a-z][^<>]*)\n+/i",
 "$1", $content);
                 }

                 if ( $sem_fixes_escape )
                         $content =
 str_replace(array_keys($sem_fixes_escape),
 array_values($sem_fixes_escape), $content);

                 return $content;
         } # fix_wpautop()


         /**
          * escape_php_callback()
          *
          * @param array $match
          * @return string $out
          **/

         function escape_php_callback($match) {
                 global $sem_fixes_escape;

                 $tag_id = "----sem_fixes_escape:" . md5($match[0]) .
 "----";
                 $sem_fixes_escape[$tag_id] = $match[0];

                 return $tag_id;
         } # escape_php_callback()

 # http://core.trac.wordpress.org/ticket/4298
 add_filter('content_save_pre', array('sem_fixes_admin', 'fix_wpautop'),
 0);
 add_filter('excerpt_save_pre', array('sem_fixes_admin', 'fix_wpautop'),
 0);
 add_filter('pre_term_description', array('sem_fixes_admin',
 'fix_wpautop'), 0);
 add_filter('pre_user_description', array('sem_fixes_admin',
 'fix_wpautop'), 0);
 add_filter('pre_link_description', array('sem_fixes_admin',
 'fix_wpautop'), 0);

 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/4298#comment:24>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list