_wptexturize_pushpop_element

Search for disabled element tags.

Description

_wptexturize_pushpop_element( (string) $text, (array) &$stack, (array) $disabled_elements ); 

Push element to stack on tag open and pop on tag close.

Assumes first char of $text is tag opening and last char is tag closing. Assumes second char of $text is optionally / to indicate closing as in.

Parameters (3)

0. $text (string)
Text to check. Must be a tag like or [shortcode]..
1. $stack (array) => &$stack
List of open tag elements.
2. $disabled_elements (array)
The tag names to match against. Spaces are not allowed in tag names.

Usage

  1. if ( !function_exists( '_wptexturize_pushpop_element' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // Text to check. Must be a tag like `` or `[shortcode]`. 
  5. $text = ''; 
  6.  
  7. // List of open tag elements. 
  8. $stack = array(); 
  9.  
  10. // The tag names to match against. Spaces are not allowed in tag names. 
  11. $disabled_elements = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _wptexturize_pushpop_element($text, $stack, $disabled_elements); 
  15.  

Defined (1)

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

/wp-includes/formatting.php  
  1. function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) { 
  2. // Is it an opening tag or closing tag? 
  3. if ( isset( $text[1] ) && '/' !== $text[1] ) { 
  4. $opening_tag = true; 
  5. $name_offset = 1; 
  6. } elseif ( 0 == count( $stack ) ) { 
  7. // Stack is empty. Just stop. 
  8. return; 
  9. } else { 
  10. $opening_tag = false; 
  11. $name_offset = 2; 
  12.  
  13. // Parse out the tag name. 
  14. $space = strpos( $text, ' ' ); 
  15. if ( false === $space ) { 
  16. $space = -1; 
  17. } else { 
  18. $space -= $name_offset; 
  19. $tag = substr( $text, $name_offset, $space ); 
  20.  
  21. // Handle disabled tags. 
  22. if ( in_array( $tag, $disabled_elements ) ) { 
  23. if ( $opening_tag ) { 
  24. /** 
  25. * This disables texturize until we find a closing tag of our type 
  26. * (e.g. <pre>) even if there was invalid nesting before that 
  27. * Example: in the case <pre>sadsadasd</code>"baba"</pre> 
  28. * "baba" won't be texturize 
  29. */ 
  30.  
  31. array_push( $stack, $tag ); 
  32. } elseif ( end( $stack ) == $tag ) { 
  33. array_pop( $stack );