PodsField_HTML

The Pods - Custom Content Types and Fields PodsField HTML class.

Defined (1)

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

/classes/fields/html.php  
  1. class PodsField_HTML extends PodsField { 
  2.  
  3. /** 
  4. * Field Type Group 
  5. * @var string 
  6. * @since 2.0 
  7. */ 
  8. public static $group = 'Layout Blocks'; 
  9.  
  10. /** 
  11. * Field Type Identifier 
  12. * @var string 
  13. * @since 2.0 
  14. */ 
  15. public static $type = 'html'; 
  16.  
  17. /** 
  18. * Field Type Label 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $label = 'HTML'; 
  23.  
  24. /** 
  25. * Field Type Preparation 
  26. * @var string 
  27. * @since 2.0 
  28. */ 
  29. public static $prepare = '%s'; 
  30.  
  31. /** 
  32. * Do things like register/enqueue scripts and stylesheets 
  33. * @since 2.0 
  34. */ 
  35. public function __construct () { 
  36.  
  37.  
  38. /** 
  39. * Add options and set defaults to 
  40. * @return array 
  41. * @since 2.0 
  42. */ 
  43. public function options () { 
  44. $options = array( 
  45. 'output_options' => array( 
  46. 'label' => __( 'Output Options', 'pods' ),  
  47. 'group' => array( 
  48. self::$type . '_allow_html' => array( 
  49. 'label' => __( 'Allow HTML?', 'pods' ),  
  50. 'default' => 1,  
  51. 'type' => 'boolean',  
  52. 'dependency' => true 
  53. ),  
  54. self::$type . '_oembed' => array( 
  55. 'label' => __( 'Enable oEmbed?', 'pods' ),  
  56. 'default' => 0,  
  57. 'type' => 'boolean',  
  58. 'help' => array( 
  59. __( 'Embed videos, images, tweets, and other content.', 'pods' ),  
  60. 'http://codex.wordpress.org/Embeds' 
  61. ),  
  62. self::$type . '_wptexturize' => array( 
  63. 'label' => __( 'Enable wptexturize?', 'pods' ),  
  64. 'default' => 1,  
  65. 'type' => 'boolean',  
  66. 'help' => array( 
  67. __( 'Transforms less-beautfiul text characters into stylized equivalents.', 'pods' ),  
  68. 'http://codex.wordpress.org/Function_Reference/wptexturize' 
  69. ),  
  70. self::$type . '_convert_chars' => array( 
  71. 'label' => __( 'Enable convert_chars?', 'pods' ),  
  72. 'default' => 1,  
  73. 'type' => 'boolean',  
  74. 'help' => array( 
  75. __( 'Converts text into valid XHTML and Unicode', 'pods' ),  
  76. 'http://codex.wordpress.org/Function_Reference/convert_chars' 
  77. ),  
  78. self::$type . '_wpautop' => array( 
  79. 'label' => __( 'Enable wpautop?', 'pods' ),  
  80. 'default' => 1,  
  81. 'type' => 'boolean',  
  82. 'help' => array( 
  83. __( 'Changes double line-breaks in the text into HTML htmls', 'pods' ),  
  84. 'http://codex.wordpress.org/Function_Reference/wpautop' 
  85. ),  
  86. self::$type . '_allow_shortcode' => array( 
  87. 'label' => __( 'Allow Shortcodes?', 'pods' ),  
  88. 'default' => 0,  
  89. 'type' => 'boolean',  
  90. 'dependency' => true,  
  91. 'help' => array( 
  92. __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ),  
  93. 'http://codex.wordpress.org/Shortcode_API' 
  94. ); 
  95.  
  96. return $options; 
  97.  
  98. /** 
  99. * Define the current field's schema for DB table storage 
  100. * @param array $options 
  101. * @return array 
  102. * @since 2.0 
  103. */ 
  104. public function schema ( $options = null ) { 
  105. return false; 
  106.  
  107. /** 
  108. * Change the way the value of the field is displayed with Pods::get 
  109. * @param mixed $value 
  110. * @param string $name 
  111. * @param array $options 
  112. * @param array $pod 
  113. * @param int $id 
  114. * @return mixed|null|string 
  115. * @since 2.0 
  116. */ 
  117. public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  118. $value = $this->strip_html( $value, $options ); 
  119.  
  120. if ( 1 == pods_var( self::$type . '_oembed', $options, 0 ) ) { 
  121. $embed = $GLOBALS[ 'wp_embed' ]; 
  122. $value = $embed->run_shortcode( $value ); 
  123. $value = $embed->autoembed( $value ); 
  124.  
  125. if ( 1 == pods_var( self::$type . '_wptexturize', $options, 1 ) ) 
  126. $value = wptexturize( $value ); 
  127.  
  128. if ( 1 == pods_var( self::$type . '_convert_chars', $options, 1 ) ) 
  129. $value = convert_chars( $value ); 
  130.  
  131. if ( 1 == pods_var( self::$type . '_wpautop', $options, 1 ) ) 
  132. $value = wpautop( $value ); 
  133.  
  134. if ( 1 == pods_var( self::$type . '_allow_shortcode', $options, 0 ) ) { 
  135. if ( 1 == pods_var( self::$type . '_wpautop', $options, 1 ) ) 
  136. $value = shortcode_unautop( $value ); 
  137.  
  138. $value = do_shortcode( $value ); 
  139.  
  140. return $value; 
  141.  
  142. /** 
  143. * Customize output of the form field 
  144. * @param string $name 
  145. * @param mixed $value 
  146. * @param array $options 
  147. * @param array $pod 
  148. * @param int $id 
  149. * @since 2.0 
  150. */ 
  151. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  152. $options = (array) $options; 
  153.  
  154. echo $this->display( $value, $name, $options, $pod, $id ); 
  155.  
  156. /** 
  157. * Customize the Pods UI manage table column output 
  158. * @param int $id 
  159. * @param mixed $value 
  160. * @param string $name 
  161. * @param array $options 
  162. * @param array $fields 
  163. * @param array $pod 
  164. * @return mixed|string 
  165. * @since 2.0 
  166. */ 
  167. public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { 
  168. $value = $this->strip_html( $value, $options ); 
  169.  
  170. $value = wp_trim_words( $value ); 
  171.  
  172. return $value; 
  173.  
  174. /** 
  175. * Strip HTML based on options 
  176. * @param string $value 
  177. * @param array $options 
  178. * @return string 
  179. */ 
  180. public function strip_html ( $value, $options = null ) { 
  181. if ( is_array( $value ) ) 
  182. $value = @implode( ' ', $value ); 
  183.  
  184. $value = trim( $value ); 
  185.  
  186. if ( empty( $value ) ) 
  187. return $value; 
  188.  
  189. $options = (array) $options; 
  190.  
  191. if ( 1 != pods_var( self::$type . '_allow_html', $options ) ) { 
  192. $value = strip_tags( $value ); 
  193.  
  194. return $value;