wpcf7_autop

The Contact Form 7 wpcf7 autop function.

Description

wpcf7_autop( $pee, (int) $br = 1 ); 

Parameters (2)

0. $pee
The pee.
1. $br — Optional. (int) => 1
The br.

Usage

  1. if ( !function_exists( 'wpcf7_autop' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/includes/formatting.php'; 
  3.  
  4. // The pee. 
  5. $pee = null; 
  6.  
  7. // The br. 
  8. $br = 1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wpcf7_autop($pee, $br); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/formatting.php  
  1. function wpcf7_autop( $pee, $br = 1 ) { 
  2. if ( trim( $pee ) === '' ) { 
  3. return ''; 
  4.  
  5. $pee = $pee . "\n"; // just to make things a little easier, pad the end 
  6. $pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee ); 
  7. // Space things out a little 
  8. /**wpcf7 remove select and input */ 
  9. $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; 
  10. $pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee ); 
  11. $pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee ); 
  12.  
  13. /**wpcf7 take care of [response], [recaptcha], and [hidden] tags */ 
  14. $block_hidden_form_tags = '(?:response|recaptcha|hidden)'; 
  15. $pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])!',  
  16. "\n$1\n\n", $pee ); 
  17.  
  18. $pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines 
  19.  
  20. if ( strpos( $pee, '<object' ) !== false ) { 
  21. $pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed 
  22. $pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee ); 
  23.  
  24. $pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates 
  25. // make paragraphs, including one at the end 
  26. $pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY ); 
  27. $pee = ''; 
  28.  
  29. foreach ( $pees as $tinkle ) { 
  30. $pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n"; 
  31.  
  32. $pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace 
  33. $pee = preg_replace( '!<p>([^<]+)</(div|address|form|fieldset)>!', "<p>$1</p></$2>", $pee ); 
  34. $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag 
  35. $pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee ); // problem with nested lists 
  36. $pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee ); 
  37. $pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee ); 
  38. $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee ); 
  39. $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); 
  40.  
  41. /**wpcf7 take care of [response], [recaptcha], and [hidden] tag */ 
  42. $pee = preg_replace( '!<p>\s*(\[' . $block_hidden_form_tags . '[^]]*\])!',  
  43. "$1", $pee ); 
  44. $pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])\s*</p>!',  
  45. "$1", $pee ); 
  46.  
  47. if ( $br ) { 
  48. /**wpcf7 add textarea */ 
  49. $pee = preg_replace_callback( '/<(script|style|textarea).*?<\/\\1>/s', create_function( '$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);' ), $pee ); 
  50. $pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee ); // optionally make line breaks 
  51. $pee = str_replace( '<WPPreserveNewline />', "\n", $pee ); 
  52.  
  53. /**wpcf7 remove extra <br /> just added before [response], [recaptcha], and [hidden] tags */ 
  54. $pee = preg_replace( '!<br />\n(\[' . $block_hidden_form_tags . '[^]]*\])!',  
  55. "\n$1", $pee ); 
  56.  
  57. $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee ); 
  58. $pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee ); 
  59.  
  60. if ( strpos( $pee, '<pre' ) !== false ) { 
  61. $pee = preg_replace_callback( '!(<pre[^>]*>)(.*?)</pre>!is',  
  62. 'clean_pre', $pee ); 
  63.  
  64. $pee = preg_replace( "|\n</p>$|", '</p>', $pee ); 
  65.  
  66. return $pee;