PodsForm

The Pods - Custom Content Types and Fields PodsForm class.

Defined (1)

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

/classes/PodsForm.php  
  1. class PodsForm { 
  2.  
  3. /** 
  4. * @var PodsForm 
  5. */ 
  6. protected static $instance = null; 
  7.  
  8. /** 
  9. * @var string 
  10. */ 
  11. static $field = null; 
  12.  
  13. /** 
  14. * @var string 
  15. */ 
  16. static $field_group = null; 
  17.  
  18. /** 
  19. * @var string 
  20. */ 
  21. static $field_type = null; 
  22.  
  23. /** 
  24. * @var array 
  25. */ 
  26. static $field_types = array(); 
  27.  
  28. /** 
  29. * @var array 
  30. */ 
  31. static $loaded = array(); 
  32.  
  33. /** 
  34. * @var int 
  35. */ 
  36. static $form_counter = 0; 
  37.  
  38. /** 
  39. * Singleton handling for a basic pods_form() request 
  40. * @return \PodsForm 
  41. * @since 2.3.5 
  42. */ 
  43. public static function init () { 
  44. if ( !is_object( self::$instance ) ) 
  45. self::$instance = new PodsForm(); 
  46.  
  47. return self::$instance; 
  48.  
  49. /** 
  50. * Master handler for all field / form methods 
  51. * @return \PodsForm 
  52. * @license http://www.gnu.org/licenses/gpl-2.0.html 
  53. * @since 2.0 
  54. */ 
  55. private function __construct() { 
  56. add_action( 'admin_init', array( $this, 'admin_init' ), 14 ); 
  57.  
  58. /** 
  59. * Prevent clones 
  60. * @since 2.3 
  61. */ 
  62. private function __clone() { 
  63. // Hulk smash 
  64.  
  65. /** 
  66. * Output a field's label 
  67. * @since 2.0 
  68. */ 
  69.  
  70. /** 
  71. * Output a field's label 
  72. * @param string $name Field name 
  73. * @param string $label Label text 
  74. * @param string $help Help text 
  75. * @param array $options Field options 
  76. * @return string Label HTML 
  77. * @since 2.0 
  78. */ 
  79. public static function label( $name, $label, $help = '', $options = null ) { 
  80. if ( is_array( $label ) || is_object( $label ) ) { 
  81. $options = $label; 
  82. $label = $options[ 'label' ]; 
  83.  
  84. if ( empty( $label ) ) 
  85. $label = ucwords( str_replace( '_', ' ', $name ) ); 
  86.  
  87. $help = $options[ 'help' ]; 
  88. else 
  89. $options = self::options( null, $options ); 
  90.  
  91. $label = apply_filters( 'pods_form_ui_label_text', $label, $name, $help, $options ); 
  92. $help = apply_filters( 'pods_form_ui_label_help', $help, $name, $label, $options ); 
  93.  
  94. ob_start(); 
  95.  
  96. $name_clean = self::clean( $name ); 
  97. $name_more_clean = self::clean( $name, true ); 
  98.  
  99. $type = 'label'; 
  100. $attributes = array(); 
  101. $attributes[ 'class' ] = 'pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean; 
  102. $attributes[ 'for' ] = ( false === strpos( $name_clean, 'pods-form-ui-' ) ? 'pods-form-ui-' : '' ) . $name_clean; 
  103. $attributes = self::merge_attributes( $attributes, $name, $type, $options, false ); 
  104.  
  105. pods_view( PODS_DIR . 'ui/fields/_label.php', compact( array_keys( get_defined_vars() ) ) ); 
  106.  
  107. $output = ob_get_clean(); 
  108.  
  109. return apply_filters( 'pods_form_ui_' . $type, $output, $name, $label, $help, $attributes, $options ); 
  110.  
  111. /** 
  112. * Output a Field Comment Paragraph 
  113. * @param string $name Field name 
  114. * @param string $message Field comments 
  115. * @param array $options Field options 
  116. * @return string Comment HTML 
  117. * @since 2.0 
  118. */ 
  119. public static function comment( $name, $message = null, $options = null ) { 
  120. $options = self::options( null, $options ); 
  121.  
  122. $name_more_clean = self::clean( $name, true ); 
  123.  
  124. if ( isset( $options[ 'description' ] ) && !empty( $options[ 'description' ] ) ) 
  125. $message = $options[ 'description' ]; 
  126. elseif ( empty( $message ) ) 
  127. return ''; 
  128.  
  129. $message = apply_filters( 'pods_form_ui_comment_text', $message, $name, $options ); 
  130.  
  131. ob_start(); 
  132.  
  133. $type = 'comment'; 
  134. $attributes = array(); 
  135. $attributes[ 'class' ] = 'pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean; 
  136. $attributes = self::merge_attributes( $attributes, $name, $type, $options, false ); 
  137.  
  138. pods_view( PODS_DIR . 'ui/fields/_comment.php', compact( array_keys( get_defined_vars() ) ) ); 
  139.  
  140. $output = ob_get_clean(); 
  141.  
  142. return apply_filters( 'pods_form_ui_' . $type, $output, $name, $message, $attributes, $options ); 
  143.  
  144. /** 
  145. * Output a field 
  146. * @param string $name Field name 
  147. * @param mixed $value Field value 
  148. * @param string $type Field type 
  149. * @param array $options Field options 
  150. * @param array $pod Pod data 
  151. * @param int $id Item ID 
  152. * @return string Field HTML 
  153. * @since 2.0 
  154. */ 
  155. public static function field( $name, $value, $type = 'text', $options = null, $pod = null, $id = null ) { 
  156. // Take a field array 
  157. if ( is_array( $name ) || is_object( $name ) ) { 
  158. $options = $name; 
  159.  
  160. if ( is_object( $type ) ) { 
  161. $pod = $type; 
  162. $id = $options; 
  163.  
  164. $name = pods_v( 'name', $options ); 
  165. $type = pods_v( 'type', $options ); 
  166.  
  167. $options = self::options( $type, $options ); 
  168.  
  169. if ( null === $value || ( '' === $value && 'boolean' == $type ) || ( !empty( $pod ) && empty( $id ) ) ) 
  170. $value = self::default_value( $value, $type, $name, $options, $pod, $id ); 
  171.  
  172. if ( false === self::permission( $type, $name, $options, null, $pod, $id ) ) 
  173. return false; 
  174.  
  175. $value = apply_filters( 'pods_form_ui_field_' . $type . '_value', $value, $name, $options, $pod, $id ); 
  176. $form_field_type = self::$field_type; 
  177.  
  178. ob_start(); 
  179.  
  180. $helper = false; 
  181.  
  182. if ( 0 < strlen( pods_v( 'input_helper', $options ) ) ) 
  183. $helper = pods_api()->load_helper( array( 'name' => $options[ 'input_helper' ] ) ); 
  184.  
  185. if ( ( !isset( $options[ 'data' ] ) || empty( $options[ 'data' ] ) ) && is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'data' ) ) 
  186. $data = $options[ 'data' ] = self::$loaded[ $type ]->data( $name, $value, $options, $pod, $id, true ); 
  187.  
  188. if ( true === apply_filters( 'pods_form_ui_field_' . $type . '_override', false, $name, $value, $options, $pod, $id ) ) 
  189. do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id ); 
  190. elseif ( !empty( $helper ) && 0 < strlen( pods_v( 'code', $helper ) ) && false === strpos( $helper[ 'code' ], '$this->' ) && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) ) 
  191. eval( '?>' . $helper[ 'code' ] ); 
  192. elseif ( method_exists( get_class(), 'field_' . $type ) ) 
  193. echo call_user_func( array( get_class(), 'field_' . $type ), $name, $value, $options ); 
  194. elseif ( is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'input' ) ) 
  195. self::$loaded[ $type ]->input( $name, $value, $options, $pod, $id ); 
  196. else 
  197. do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id ); 
  198.  
  199. $output = ob_get_clean(); 
  200.  
  201. return apply_filters( 'pods_form_ui_field_' . $type, $output, $name, $value, $options, $pod, $id ); 
  202.  
  203. /** 
  204. * Output field type 'db' 
  205. * Used for field names and other places where only [a-z0-9_] is accepted 
  206. * @since 2.0 
  207. */ 
  208. protected static function field_db( $name, $value = null, $options = null ) { 
  209. $form_field_type = self::$field_type; 
  210.  
  211. ob_start(); 
  212.  
  213. pods_view( PODS_DIR . 'ui/fields/_db.php', compact( array_keys( get_defined_vars() ) ) ); 
  214.  
  215. $output = ob_get_clean(); 
  216.  
  217. return apply_filters( 'pods_form_ui_field_db', $output, $name, $value, $options ); 
  218.  
  219. /** 
  220. * Output a hidden field 
  221. */ 
  222. protected static function field_hidden( $name, $value = null, $options = null ) { 
  223. $form_field_type = self::$field_type; 
  224.  
  225. ob_start(); 
  226.  
  227. pods_view( PODS_DIR . 'ui/fields/_hidden.php', compact( array_keys( get_defined_vars() ) ) ); 
  228.  
  229. $output = ob_get_clean(); 
  230.  
  231. return apply_filters( 'pods_form_ui_field_hidden', $output, $name, $value, $options ); 
  232.  
  233. /** 
  234. * Returns a submit button, with provided text and appropriate class, copied from WP Core for use on the frontend 
  235. * @see get_submit_button 
  236. * @param string $text The text of the button (defaults to 'Save Changes') 
  237. * @param string $type The type of button. One of: primary, secondary, delete 
  238. * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute 
  239. * is given in $other_attributes below, $name will be used as the button's id. 
  240. * @param bool $wrap True if the output button should be wrapped in a paragraph tag,  
  241. * false otherwise. Defaults to true 
  242. * @param array|string $other_attributes Other attributes that should be output with the button,  
  243. * mapping attributes to their values, such as array( 'tabindex' => '1' ). 
  244. * These attributes will be output as attribute="value", such as tabindex="1". 
  245. * Defaults to no other attributes. Other attributes can also be provided as a 
  246. * string such as 'tabindex="1"', though the array format is typically cleaner. 
  247. * @since 3.0 
  248. */ 
  249. public static function submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) { 
  250.  
  251. if ( function_exists( 'get_submit_button' ) ) { 
  252. return get_submit_button( $text, $type, $name, $wrap, $other_attributes ); 
  253.  
  254. if ( !is_array( $type ) ) { 
  255. $type = explode( ' ', $type ); 
  256.  
  257. $button_shorthand = array( 
  258. 'primary',  
  259. 'small',  
  260. 'large' 
  261. ); 
  262.  
  263. $classes = array( 
  264. 'button' 
  265. ); 
  266.  
  267. foreach ( $type as $t ) { 
  268. if ( 'secondary' === $t || 'button-secondary' === $t ) { 
  269. continue; 
  270.  
  271. $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t; 
  272.  
  273. $class = implode( ' ', array_unique( $classes ) ); 
  274.  
  275. if ( 'delete' === $type ) { 
  276. $class = 'button-secondary delete'; 
  277.  
  278. $text = $text ? $text : __( 'Save Changes' ); 
  279.  
  280. // Default the id attribute to $name unless an id was specifically provided in $other_attributes 
  281. $id = $name; 
  282.  
  283. if ( is_array( $other_attributes ) && isset( $other_attributes[ 'id' ] ) ) { 
  284. $id = $other_attributes[ 'id' ]; 
  285. unset( $other_attributes[ 'id' ] ); 
  286.  
  287. $attributes = ''; 
  288.  
  289. if ( is_array( $other_attributes ) ) { 
  290. foreach ( $other_attributes as $attribute => $value ) { 
  291. $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important 
  292. elseif ( !empty( $other_attributes ) ) { // Attributes provided as a string 
  293. $attributes = $other_attributes; 
  294.  
  295. $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ); 
  296. $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />'; 
  297.  
  298. if ( $wrap ) { 
  299. $button = '<p class="submit">' . $button . '</p>'; 
  300.  
  301. return $button; 
  302.  
  303.  
  304. /** 
  305. * Output a row (label, field, and comment) 
  306. * @param string $name Field name 
  307. * @param mixed $value Field value 
  308. * @param string $type Field type 
  309. * @param array $options Field options 
  310. * @param array $pod Pod data 
  311. * @param int $id Item ID 
  312. * @return string Row HTML 
  313. * @since 2.0 
  314. */ 
  315. public static function row( $name, $value, $type = 'text', $options = null, $pod = null, $id = null ) { 
  316. $options = self::options( null, $options ); 
  317.  
  318. ob_start(); 
  319.  
  320. pods_view( PODS_DIR . 'ui/fields/_row.php', compact( array_keys( get_defined_vars() ) ) ); 
  321.  
  322. $output = ob_get_clean(); 
  323.  
  324. return apply_filters( 'pods_form_ui_field_row', $output, $name, $value, $options, $pod, $id ); 
  325.  
  326. /** 
  327. * Output a field's attributes 
  328. * @since 2.0 
  329. */ 
  330. public static function attributes( $attributes, $name = null, $type = null, $options = null ) { 
  331. $attributes = (array) apply_filters( 'pods_form_ui_field_' . $type . '_attributes', $attributes, $name, $options ); 
  332.  
  333. foreach ( $attributes as $attribute => $value ) { 
  334. if ( null === $value ) 
  335. continue; 
  336.  
  337. echo ' ' . esc_attr( (string) $attribute ) . '="' . esc_attr( (string) $value ) . '"'; 
  338.  
  339. /** 
  340. * Output a field's data (for use with jQuery) 
  341. * @since 2.0 
  342. */ 
  343. public static function data( $data, $name = null, $type = null, $options = null ) { 
  344. $data = (array) apply_filters( 'pods_form_ui_field_' . $type . '_data', $data, $name, $options ); 
  345.  
  346. foreach ( $data as $key => $value ) { 
  347. if ( null === $value ) 
  348. continue; 
  349.  
  350. $key = sanitize_title( $key ); 
  351.  
  352. if ( is_array( $value ) ) 
  353. $value = implode( ', ', $value ); 
  354.  
  355. echo ' data-' . esc_attr( (string) $key ) . '="' . esc_attr( (string) $value ) . '"'; 
  356.  
  357. /** 
  358. * Merge attributes and handle classes 
  359. * @since 2.0 
  360. */ 
  361. public static function merge_attributes( $attributes, $name = null, $type = null, $options = null, $classes = '' ) { 
  362. $options = (array) $options; 
  363.  
  364. if ( !in_array( $type, array( 'label', 'comment' ) ) ) { 
  365. $name_clean = self::clean( $name ); 
  366. $name_more_clean = self::clean( $name, true ); 
  367. $_attributes = array(); 
  368. $_attributes[ 'name' ] = $name; 
  369. $_attributes[ 'data-name-clean' ] = $name_more_clean; 
  370.  
  371. if ( 0 < strlen( pods_v( 'label', $options, '' ) ) ) 
  372. $_attributes[ 'data-label' ] = strip_tags( pods_v( 'label', $options ) ); 
  373.  
  374. $_attributes[ 'id' ] = 'pods-form-ui-' . $name_clean; 
  375. $_attributes[ 'class' ] = 'pods-form-ui-field-type-' . $type . ' pods-form-ui-field-name-' . $name_more_clean; 
  376.  
  377. if ( isset( $options[ 'dependency' ] ) && false !== $options[ 'dependency' ] ) 
  378. $_attributes[ 'class' ] .= ' pods-dependent-toggle'; 
  379.  
  380. $attributes = array_merge( $_attributes, (array) $attributes ); 
  381.  
  382. if ( isset( $options[ 'attributes' ] ) && is_array( $options[ 'attributes' ] ) && !empty( $options[ 'attributes' ] ) ) 
  383. $attributes = array_merge( $attributes, $options[ 'attributes' ] ); 
  384. elseif ( isset( $options[ $type . '_attributes' ] ) && is_array( $options[ $type . '_attributes' ] ) && !empty( $options[ $type . '_attributes' ] ) ) 
  385. $attributes = array_merge( $attributes, $options[ $type . '_attributes' ] ); 
  386.  
  387. if ( isset( $options[ 'class' ] ) && !empty( $options[ 'class' ] ) ) { 
  388. if ( is_array( $options[ 'class' ] ) ) 
  389. $options[ 'class' ] = implode( ' ', $options[ 'class' ] ); 
  390.  
  391. $options[ 'class' ] = (string) $options[ 'class' ]; 
  392. if ( isset( $attributes[ 'class' ] ) ) 
  393. $attributes[ 'class' ] = $attributes[ 'class' ] . ' ' . $options[ 'class' ]; 
  394. else 
  395. $attributes[ 'class' ] = $options[ 'class' ]; 
  396.  
  397. $attributes[ 'class' ] = trim( $attributes[ 'class' ] ); 
  398.  
  399. if ( !empty( $classes ) ) { 
  400. if ( isset( $attributes[ 'class' ] ) ) 
  401. $attributes[ 'class' ] = $attributes[ 'class' ] . ' ' . $classes; 
  402. else 
  403. $attributes[ 'class' ] = $classes; 
  404.  
  405. if ( isset( $options[ 'placeholder' ] ) && !empty( $options[ 'placeholder' ] ) ) { 
  406. if ( is_array( $options[ 'placeholder' ] ) ) 
  407. $options[ 'placeholder' ] = implode( ' ', $options[ 'placeholder' ] ); 
  408.  
  409. $options[ 'placeholder' ] = (string) $options[ 'placeholder' ]; 
  410. $attributes[ 'placeholder' ] = trim( $options[ 'placeholder' ] ); 
  411.  
  412. if ( 1 == pods_v( 'required', $options, 0 ) ) 
  413. $attributes[ 'class' ] .= ' pods-validate pods-validate-required'; 
  414.  
  415. $max_length = (int) pods_var( 'maxlength', $options, pods_v( $type . '_max_length', $options, 0 ), null, true ); 
  416.  
  417. if ( 0 < $max_length ) 
  418. $attributes[ 'maxlength' ] = $max_length; 
  419.  
  420. $attributes = (array) apply_filters( 'pods_form_ui_field_' . $type . '_merge_attributes', $attributes, $name, $options ); 
  421. return $attributes; 
  422.  
  423. /** 
  424. * Setup options for a field and store them for later use 
  425. * @param $type 
  426. * @param $options 
  427. * @return array 
  428. * @static 
  429. * @since 2.0 
  430. */ 
  431. public static function options( $type, $options ) { 
  432. $options = (array) $options; 
  433.  
  434. if ( !is_object( $options ) && isset( $options[ 'options' ] ) ) { 
  435. $options_temp = $options[ 'options' ]; 
  436.  
  437. unset( $options[ 'options' ] ); 
  438.  
  439. $options = array_merge( $options_temp, $options ); 
  440.  
  441. $override = array( 
  442. 'class' 
  443. ); 
  444.  
  445. foreach ( $override as $check ) { 
  446. if ( isset( $options_temp[ $check ] ) ) 
  447. $options[ $check ] = $options_temp[ $check ]; 
  448.  
  449. $defaults = self::options_setup( $type, $options ); 
  450.  
  451. $core_defaults = array( 
  452. 'id' => 0,  
  453. 'label' => '',  
  454. 'description' => '',  
  455. 'help' => '',  
  456. 'default' => null,  
  457. 'attributes' => array(),  
  458. 'class' => '',  
  459. 'grouped' => 0,  
  460. ); 
  461.  
  462. $defaults = array_merge( $core_defaults, $defaults ); 
  463.  
  464. foreach ( $defaults as $option => $settings ) { 
  465. $default = $settings; 
  466.  
  467. if ( is_array( $settings ) && isset( $settings[ 'default' ] ) ) 
  468. $default = $settings[ 'default' ]; 
  469.  
  470. if ( !isset( $options[ $option ] ) ) 
  471. $options[ $option ] = $default; 
  472.  
  473. return $options; 
  474.  
  475. /** 
  476. * Get options for a field type and setup defaults 
  477. * @static 
  478. * @param $type 
  479. * @return array|null 
  480. * @since 2.0 
  481. */ 
  482. public static function options_setup( $type = null, $options = null ) { 
  483. $core_defaults = array( 
  484. 'id' => 0,  
  485. 'name' => '',  
  486. 'label' => '',  
  487. 'description' => '',  
  488. 'help' => '',  
  489. 'default' => null,  
  490. 'attributes' => array(),  
  491. 'class' => '',  
  492. 'type' => 'text',  
  493. 'group' => 0,  
  494. 'grouped' => 0,  
  495. 'developer_mode' => false,  
  496. 'dependency' => false,  
  497. 'depends-on' => array(),  
  498. 'excludes-on' => array(),  
  499. 'options' => array() 
  500. ); 
  501.  
  502. if ( !empty( $options ) && is_array( $options ) ) 
  503. $core_defaults = array_merge( $core_defaults, $options ); 
  504.  
  505. if ( null === $type ) 
  506. return $core_defaults; 
  507. else 
  508. self::field_loader( $type ); 
  509.  
  510. $options = apply_filters( 'pods_field_' . $type . '_options', (array) self::$loaded[ $type ]->options(), $type ); 
  511.  
  512. $first_field = current( $options ); 
  513.  
  514. if ( !empty( $options ) && !isset( $first_field[ 'name' ] ) && !isset( $first_field[ 'label' ] ) ) { 
  515. $all_options = array(); 
  516.  
  517. foreach ( $options as $group => $group_options ) { 
  518. $all_options = array_merge( $all_options, self::fields_setup( $group_options, $core_defaults ) ); 
  519.  
  520. $options = $all_options; 
  521. else 
  522. $options = self::fields_setup( $options, $core_defaults ); 
  523.  
  524. return $options; 
  525.  
  526. /** 
  527. * Get Admin options for a field type and setup defaults 
  528. * @static 
  529. * @param $type 
  530. * @return array|null 
  531. * @since 2.0 
  532. */ 
  533. public static function ui_options( $type ) { 
  534. $core_defaults = array( 
  535. 'id' => 0,  
  536. 'name' => '',  
  537. 'label' => '',  
  538. 'description' => '',  
  539. 'help' => '',  
  540. 'default' => null,  
  541. 'attributes' => array(),  
  542. 'class' => '',  
  543. 'type' => 'text',  
  544. 'group' => 0,  
  545. 'grouped' => 0,  
  546. 'developer_mode' => false,  
  547. 'dependency' => false,  
  548. 'depends-on' => array(),  
  549. 'excludes-on' => array(),  
  550. 'options' => array() 
  551. ); 
  552.  
  553. self::field_loader( $type ); 
  554.  
  555. $options = apply_filters( 'pods_field_' . $type . '_ui_options', (array) self::$loaded[ $type ]->ui_options(), $type ); 
  556.  
  557. $first_field = current( $options ); 
  558.  
  559. if ( !empty( $options ) && !isset( $first_field[ 'name' ] ) && !isset( $first_field[ 'label' ] ) ) { 
  560. foreach ( $options as $group => $group_options ) { 
  561. $options[ $group ] = self::fields_setup( $group_options, $core_defaults ); 
  562. else 
  563. $options = self::fields_setup( $options, $core_defaults ); 
  564.  
  565. return $options; 
  566.  
  567. /** 
  568. * Get options for a field and setup defaults 
  569. * @param null $fields 
  570. * @param null $core_defaults 
  571. * @param bool $single 
  572. * @return array|null 
  573. * @static 
  574. * @since 2.0 
  575. */ 
  576. public static function fields_setup( $fields = null, $core_defaults = null, $single = false ) { 
  577. if ( empty( $core_defaults ) ) { 
  578. $core_defaults = array( 
  579. 'id' => 0,  
  580. 'name' => '',  
  581. 'label' => '',  
  582. 'description' => '',  
  583. 'help' => '',  
  584. 'default' => null,  
  585. 'attributes' => array(),  
  586. 'class' => '',  
  587. 'type' => 'text',  
  588. 'group' => 0,  
  589. 'grouped' => 0,  
  590. 'developer_mode' => false,  
  591. 'dependency' => false,  
  592. 'depends-on' => array(),  
  593. 'excludes-on' => array(),  
  594. 'options' => array() 
  595. ); 
  596.  
  597. if ( $single ) 
  598. $fields = array( $fields ); 
  599.  
  600. foreach ( $fields as $f => $field ) { 
  601. $fields[ $f ] = self::field_setup( $field, $core_defaults, pods_v( 'type', $field, 'text' ) ); 
  602.  
  603. if ( !$single && strlen( $fields[ $f ][ 'name' ] ) < 1 ) 
  604. $fields[ $f ][ 'name' ] = $f; 
  605.  
  606. if ( $single ) 
  607. $fields = $fields[ 0 ]; 
  608.  
  609. return $fields; 
  610.  
  611. /** 
  612. * Get options for a field and setup defaults 
  613. * @static 
  614. * @param null $field 
  615. * @param null $core_defaults 
  616. * @param null $type 
  617. * @return array|null 
  618. * @since 2.0 
  619. */ 
  620. public static function field_setup( $field = null, $core_defaults = null, $type = null ) { 
  621. $options = array(); 
  622.  
  623. if ( empty( $core_defaults ) ) { 
  624. $core_defaults = array( 
  625. 'id' => 0,  
  626. 'name' => '',  
  627. 'label' => '',  
  628. 'description' => '',  
  629. 'help' => '',  
  630. 'default' => null,  
  631. 'attributes' => array(),  
  632. 'class' => '',  
  633. 'type' => 'text',  
  634. 'group' => 0,  
  635. 'grouped' => 0,  
  636. 'developer_mode' => false,  
  637. 'dependency' => false,  
  638. 'depends-on' => array(),  
  639. 'excludes-on' => array(),  
  640. 'options' => array() 
  641. ); 
  642.  
  643. if ( null !== $type ) { 
  644. self::field_loader( $type ); 
  645.  
  646. if ( method_exists( self::$loaded[ $type ], 'options' ) ) 
  647. $options = apply_filters( 'pods_field_' . $type . '_options', (array) self::$loaded[ $type ]->options(), $type ); 
  648.  
  649. if ( !is_array( $field ) ) 
  650. $field = array( 'default' => $field ); 
  651.  
  652. if ( isset( $field[ 'group' ] ) && is_array( $field[ 'group' ] ) ) { 
  653. foreach ( $field[ 'group' ] as $g => $group_option ) { 
  654. $field[ 'group' ][ $g ] = array_merge( $core_defaults, $group_option ); 
  655.  
  656. if ( strlen( $field[ 'group' ][ $g ][ 'name' ] ) < 1 ) 
  657. $field[ 'group' ][ $g ][ 'name' ] = $g; 
  658.  
  659. $field = array_merge( $core_defaults, $field ); 
  660.  
  661. foreach ( $options as $option => $settings ) { 
  662. $v = null; 
  663.  
  664. if ( isset( $settings[ 'default' ] ) ) 
  665. $v = $settings[ 'default' ]; 
  666.  
  667. if ( !isset( $field[ 'options' ][ $option ] ) ) 
  668. $field[ 'options' ][ $option ] = $v; 
  669.  
  670. return $field; 
  671.  
  672. /** 
  673. * Setup dependency / exclusion classes 
  674. * @param array $options array( 'depends-on' => ..., 'excludes-on' => ...) 
  675. * @param string $prefix 
  676. * @return string 
  677. * @static 
  678. * @since 2.0 
  679. */ 
  680. public static function dependencies( $options, $prefix = '' ) { 
  681. $options = (array) $options; 
  682.  
  683. $depends_on = $excludes_on = array(); 
  684. if ( isset( $options[ 'depends-on' ] ) ) 
  685. $depends_on = (array) $options[ 'depends-on' ]; 
  686.  
  687. if ( isset( $options[ 'excludes-on' ] ) ) 
  688. $excludes_on = (array) $options[ 'excludes-on' ]; 
  689.  
  690. $classes = array(); 
  691.  
  692. if ( !empty( $depends_on ) ) { 
  693. $classes[] = 'pods-depends-on'; 
  694.  
  695. foreach ( $depends_on as $depends => $on ) { 
  696. $classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true ); 
  697.  
  698. if ( !is_bool( $on ) ) { 
  699. $on = (array) $on; 
  700.  
  701. foreach ( $on as $o ) { 
  702. $classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true ) . '-' . self::clean( $o, true ); 
  703.  
  704. if ( !empty( $excludes_on ) ) { 
  705. $classes[] = 'pods-excludes-on'; 
  706. foreach ( $excludes_on as $excludes => $on ) { 
  707. $classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true ); 
  708.  
  709. $on = (array) $on; 
  710.  
  711. foreach ( $on as $o ) { 
  712. $classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true ) . '-' . self::clean( $o, true ); 
  713.  
  714. $classes = implode( ' ', $classes ); 
  715.  
  716. return $classes; 
  717.  
  718. /** 
  719. * Change the value of the field 
  720. * @param mixed $value 
  721. * @param string $name 
  722. * @param array $options 
  723. * @param array $fields 
  724. * @param array $pod 
  725. * @param int $id 
  726. * @param array $traverse 
  727. * @since 2.3 
  728. */ 
  729. public static function value( $type, $value = null, $name = null, $options = null, $pod = null, $id = null, $traverse = null ) { 
  730. self::field_loader( $type ); 
  731.  
  732. if ( in_array( $type, self::repeatable_field_types() ) && 1 == pods_v( $type . '_repeatable', $options, 0 ) && !is_array( $value ) ) { 
  733. if ( 0 < strlen( $value ) ) { 
  734. $simple = @json_decode( $value, true ); 
  735.  
  736. if ( is_array( $simple ) ) 
  737. $value = $simple; 
  738. else 
  739. $value = (array) $value; 
  740. else 
  741. $value = array(); 
  742.  
  743. if ( method_exists( self::$loaded[ $type ], 'value' ) ) { 
  744. if ( is_array( $value ) && in_array( $type, self::tableless_field_types() ) ) { 
  745. foreach ( $value as &$display_value ) { 
  746. $display_value = call_user_func_array( array( self::$loaded[ $type ], 'value' ), array( $display_value, $name, $options, $pod, $id, $traverse ) ); 
  747. else 
  748. $value = call_user_func_array( array( self::$loaded[ $type ], 'value' ), array( $value, $name, $options, $pod, $id, $traverse ) ); 
  749.  
  750. return $value; 
  751.  
  752. /** 
  753. * Change the way the value of the field is displayed with Pods::get 
  754. * @param mixed $value 
  755. * @param string $name 
  756. * @param array $options 
  757. * @param array $fields 
  758. * @param array $pod 
  759. * @param int $id 
  760. * @param array $traverse 
  761. * @since 2.0 
  762. */ 
  763. public static function display( $type, $value = null, $name = null, $options = null, $pod = null, $id = null, $traverse = null ) { 
  764. self::field_loader( $type ); 
  765.  
  766. $tableless_field_types = self::tableless_field_types(); 
  767.  
  768. if ( method_exists( self::$loaded[ $type ], 'display' ) ) { 
  769. if ( is_array( $value ) && !in_array( $type, $tableless_field_types ) ) { 
  770. foreach ( $value as $k => $display_value ) { 
  771. $value[ $k ] = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $display_value, $name, $options, $pod, $id, $traverse ) ); 
  772. else 
  773. $value = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $value, $name, $options, $pod, $id, $traverse ) ); 
  774.  
  775. $value = apply_filters( 'pods_form_display_' . $type, $value, $name, $options, $pod, $id, $traverse ); 
  776.  
  777. return $value; 
  778.  
  779. /** 
  780. * Setup regex for JS / PHP 
  781. * @static 
  782. * @param $type 
  783. * @param $options 
  784. * @return mixed|void 
  785. * @since 2.0 
  786. */ 
  787. public static function regex( $type, $options ) { 
  788. self::field_loader( $type ); 
  789.  
  790. $regex = false; 
  791.  
  792. if ( method_exists( self::$loaded[ $type ], 'regex' ) ) 
  793. $regex = self::$loaded[ $type ]->regex( $options ); 
  794.  
  795. $regex = apply_filters( 'pods_field_' . $type . '_regex', $regex, $options, $type ); 
  796.  
  797. return $regex; 
  798.  
  799. /** 
  800. * Setup value preparation for sprintf 
  801. * @static 
  802. * @param $type 
  803. * @param $options 
  804. * @return mixed|void 
  805. * @since 2.0 
  806. */ 
  807. public static function prepare( $type, $options ) { 
  808. self::field_loader( $type ); 
  809.  
  810. $prepare = '%s'; 
  811.  
  812. if ( method_exists( self::$loaded[ $type ], 'prepare' ) ) 
  813. $prepare = self::$loaded[ $type ]->prepare( $options ); 
  814.  
  815. $prepare = apply_filters( 'pods_field_' . $type . '_prepare', $prepare, $options, $type ); 
  816.  
  817. return $prepare; 
  818.  
  819. /** 
  820. * Validate a value before it's saved 
  821. * @param string $type 
  822. * @param mixed $value 
  823. * @param string $name 
  824. * @param array $options 
  825. * @param array $fields 
  826. * @param array $pod 
  827. * @param int $id 
  828. * @param array|object $params 
  829. * @static 
  830. * @since 2.0 
  831. */ 
  832. public static function validate( $type, $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { 
  833. self::field_loader( $type ); 
  834.  
  835. $validate = true; 
  836.  
  837. if ( 1 == pods_v( 'pre_save', $options, 1 ) && method_exists( self::$loaded[ $type ], 'validate' ) ) 
  838. $validate = self::$loaded[ $type ]->validate( $value, $name, $options, $fields, $pod, $id, $params ); 
  839.  
  840. $validate = apply_filters( 'pods_field_' . $type . '_validate', $validate, $value, $name, $options, $fields, $pod, $id, $type, $params ); 
  841.  
  842. return $validate; 
  843.  
  844. /** 
  845. * Change the value or perform actions after validation but before saving to the DB 
  846. * @param string $type 
  847. * @param mixed $value 
  848. * @param int $id 
  849. * @param string $name 
  850. * @param array $options 
  851. * @param array $fields 
  852. * @param array $pod 
  853. * @param object $params 
  854. * @static 
  855. * @since 2.0 
  856. */ 
  857. public static function pre_save( $type, $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  858. self::field_loader( $type ); 
  859.  
  860. if ( 1 == pods_v( 'field_pre_save', $options, 1 ) && method_exists( self::$loaded[ $type ], 'pre_save' ) ) 
  861. $value = self::$loaded[ $type ]->pre_save( $value, $id, $name, $options, $fields, $pod, $params ); 
  862.  
  863. return $value; 
  864.  
  865. /** 
  866. * Save the value to the DB 
  867. * @param string $type 
  868. * @param mixed $value 
  869. * @param int $id 
  870. * @param string $name 
  871. * @param array $options 
  872. * @param array $fields 
  873. * @param array $pod 
  874. * @param object $params 
  875. * @static 
  876. * @since 2.3 
  877. */ 
  878. public static function save( $type, $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  879. self::field_loader( $type ); 
  880.  
  881. $saved = null; 
  882.  
  883. if ( 1 == pods_v( 'field_save', $options, 1 ) && method_exists( self::$loaded[ $type ], 'save' ) ) 
  884. $saved = self::$loaded[ $type ]->save( $value, $id, $name, $options, $fields, $pod, $params ); 
  885.  
  886. return $saved; 
  887.  
  888. /** 
  889. * Delete the value from the DB 
  890. * @param string $type 
  891. * @param int $id 
  892. * @param string $name 
  893. * @param array $options 
  894. * @param array $pod 
  895. * @static 
  896. * @since 2.3 
  897. */ 
  898. public static function delete( $type, $id = null, $name = null, $options = null, $pod = null ) { 
  899. self::field_loader( $type ); 
  900.  
  901. $deleted = null; 
  902.  
  903. if ( 1 == pods_v( 'field_delete', $options, 1 ) && method_exists( self::$loaded[ $type ], 'delete' ) ) 
  904. $deleted = self::$loaded[ $type ]->delete( $id, $name, $options, $pod ); 
  905.  
  906. return $deleted; 
  907.  
  908. /** 
  909. * Check if a user has permission to be editing a field 
  910. * @param $type 
  911. * @param null $name 
  912. * @param null $options 
  913. * @param null $fields 
  914. * @param null $pod 
  915. * @param null $id 
  916. * @param null $params 
  917. * @static 
  918. * @since 2.0 
  919. */ 
  920. public static function permission( $type, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { 
  921. $permission = pods_permission( $options ); 
  922.  
  923. $permission = (boolean) apply_filters( 'pods_form_field_permission', $permission, $type, $name, $options, $fields, $pod, $id, $params ); 
  924.  
  925. return $permission; 
  926.  
  927. /** 
  928. * Parse the default the value 
  929. * @since 2.0 
  930. */ 
  931. public static function default_value( $value, $type = 'text', $name = null, $options = null, $pod = null, $id = null ) { 
  932. $default_value = pods_v( 'default_value', $options ); 
  933.  
  934. if ( '' === $default_value || null === $default_value ) { 
  935. $default_value = $value; 
  936.  
  937. $default = pods_v( 'default', $options, $default_value, true ); 
  938.  
  939. if ( is_string( $default ) ) { 
  940. $default_value = str_replace( array( '{@', '}' ), '', trim( $default ) ); 
  941.  
  942. if ( $default != $default_value && 1 == (int) pods_v( 'default_evaluate_tags', $options, 1 ) ) 
  943. $default = pods_evaluate_tags( $default ); 
  944.  
  945. $default = pods_var_raw( pods_v( 'default_value_parameter', $options ), 'request', $default, null, true ); 
  946.  
  947. if ( $default != $value ) 
  948. $value = $default; 
  949.  
  950. if ( is_array( $value ) ) 
  951. $value = pods_serial_comma( $value ); 
  952.  
  953. return apply_filters( 'pods_form_field_default_value', $value, $default, $type, $options, $pod, $id ); 
  954.  
  955. /** 
  956. * Clean a value for use in class / id 
  957. * @since 2.0 
  958. */ 
  959. public static function clean( $input, $noarray = false, $db_field = false ) { 
  960. $input = str_replace( array( '--1', '__1' ), '00000', (string) $input ); 
  961. if ( false !== $noarray ) 
  962. $input = preg_replace( '/\[\d*\]/', '-', $input ); 
  963. $output = str_replace( array( '[', ']' ), '-', strtolower( $input ) ); 
  964. $output = preg_replace( '/([^a-z0-9\-_])/', '', $output ); 
  965. $output = trim( str_replace( array( '__', '_', '--' ), '-', $output ), '-' ); 
  966. $output = str_replace( '00000', '--1', $output ); 
  967. if ( false !== $db_field ) 
  968. $output = str_replace( '-', '_', $output ); 
  969. return $output; 
  970.  
  971. /** 
  972. * Run admin_init methods for each field type 
  973. * @since 2.3 
  974. */ 
  975. public function admin_init() { 
  976. $admin_field_types = pods_transient_get( 'pods_form_admin_init_field_types' ); 
  977.  
  978. if ( empty( $admin_field_types ) ) { 
  979. $admin_field_types = array(); 
  980.  
  981. $field_types = self::field_types(); 
  982.  
  983. foreach ( $field_types as $field_type => $field_type_data ) { 
  984. $has_ajax = self::field_method( $field_type_data[ 'type' ], 'admin_init' ); 
  985.  
  986. if ( false !== $has_ajax ) 
  987. $admin_field_types[] = $field_type; 
  988.  
  989. pods_transient_set( 'pods_form_admin_init_field_types', $admin_field_types ); 
  990. else { 
  991. foreach ( $admin_field_types as $field_type ) { 
  992. self::field_method( $field_type, 'admin_init' ); 
  993.  
  994. /** 
  995. * Autoload a Field Type's class 
  996. * @param string $field_type Field Type indentifier 
  997. * @param string $file The Field Type class file location 
  998. * @return string 
  999. * @access public 
  1000. * @static 
  1001. * @since 2.0 
  1002. */ 
  1003. public static function field_loader( $field_type, $file = '' ) { 
  1004. if ( isset( self::$loaded[ $field_type ] ) ) { 
  1005. $class_vars = get_class_vars( get_class( self::$loaded[ $field_type ] ) ); // PHP 5.2.x workaround 
  1006.  
  1007. self::$field_group = ( isset( $class_vars[ 'group' ] ) ? $class_vars[ 'group' ] : '' ); 
  1008. self::$field_type = $class_vars[ 'type' ]; 
  1009.  
  1010. if ( 'Unknown' != $class_vars[ 'label' ] ) 
  1011. return self::$loaded[ $field_type ]; 
  1012.  
  1013. include_once PODS_DIR . 'classes/PodsField.php'; 
  1014.  
  1015. $field_type = self::clean( $field_type, true, true ); 
  1016.  
  1017. $class_name = ucfirst( $field_type ); 
  1018. $class_name = "PodsField_{$class_name}"; 
  1019.  
  1020. $content_dir = realpath( WP_CONTENT_DIR ); 
  1021. $plugins_dir = realpath( WP_PLUGIN_DIR ); 
  1022. $muplugins_dir = realpath( WPMU_PLUGIN_DIR ); 
  1023. $abspath_dir = realpath( ABSPATH ); 
  1024.  
  1025. if ( !class_exists( $class_name ) ) { 
  1026. if ( isset( self::$field_types[ $field_type ] ) && !empty( self::$field_types[ $field_type ][ 'file' ] ) ) 
  1027. $file = realpath( self::$field_types[ $field_type ][ 'file' ] ); 
  1028.  
  1029. if ( !empty( $file ) && 0 === strpos( $file, $abspath_dir ) && file_exists( $file ) ) 
  1030. include_once $file; 
  1031. else { 
  1032. $file = str_replace( '../', '', apply_filters( 'pods_form_field_include', PODS_DIR . 'classes/fields/' . basename( $field_type ) . '.php', $field_type ) ); 
  1033. $file = realpath( $file ); 
  1034.  
  1035. if ( file_exists( $file ) && ( 0 === strpos( $file, $content_dir ) || 0 === strpos( $file, $plugins_dir ) || 0 === strpos( $file, $muplugins_dir ) || 0 === strpos( $file, $abspath_dir ) ) ) 
  1036. include_once $file; 
  1037.  
  1038. if ( class_exists( $class_name ) ) 
  1039. $class = new $class_name(); 
  1040. else { 
  1041. $class = new PodsField(); 
  1042. $class_name = 'PodsField'; 
  1043.  
  1044. $class_vars = get_class_vars( $class_name ); // PHP 5.2.x workaround 
  1045.  
  1046. self::$field_group = ( isset( $class_vars[ 'group' ] ) ? $class_vars[ 'group' ] : '' ); 
  1047. self::$field_type = $class_vars[ 'type' ]; 
  1048.  
  1049. self::$loaded[ $field_type ] =& $class; 
  1050.  
  1051. return self::$loaded[ $field_type ]; 
  1052.  
  1053. /** 
  1054. * Run a method from a Field Type's class 
  1055. * @param string $field_type Field Type indentifier 
  1056. * @param string $method Method name 
  1057. * @param mixed $arg More arguments 
  1058. * @return mixed 
  1059. * @access public 
  1060. * @static 
  1061. * @since 2.0 
  1062. */ 
  1063. public static function field_method() { 
  1064. $args = func_get_args(); 
  1065.  
  1066. if ( empty( $args ) && count( $args ) < 2 ) 
  1067. return false; 
  1068.  
  1069. $field_type = array_shift( $args ); 
  1070. $method = array_shift( $args ); 
  1071.  
  1072. $class = self::field_loader( $field_type ); 
  1073.  
  1074. if ( method_exists( $class, $method ) ) 
  1075. return call_user_func_array( array( $class, $method ), $args ); 
  1076.  
  1077. return false; 
  1078.  
  1079. /** 
  1080. * Add a new Pod field type 
  1081. * @param string $type The new field type identifier 
  1082. * @param string $file The new field type class file location 
  1083. * @return array Field Type data 
  1084. * @since 2.3 
  1085. */ 
  1086. public static function register_field_type( $type, $file = null ) { 
  1087. $field_type = pods_transient_get( 'pods_field_type_' . $type ); 
  1088.  
  1089. if ( empty( $field_type ) || $field_type[ 'type' ] != $type || $field_type[ 'file' ] != $file ) { 
  1090. self::field_loader( $type, $file ); 
  1091.  
  1092. $class_vars = get_class_vars( get_class( self::$loaded[ $type ] ) ); // PHP 5.2.x workaround 
  1093.  
  1094. self::$field_types[ $type ] = $class_vars; 
  1095. self::$field_types[ $type ][ 'file' ] = $file; 
  1096.  
  1097. pods_transient_set( 'pods_field_type_' . $type, self::$field_types[ $type ] ); 
  1098. else 
  1099. self::$field_types[ $type ] = $field_type; 
  1100.  
  1101. return self::$field_types[ $type ]; 
  1102.  
  1103. /** 
  1104. * Get a list of all available field types and include 
  1105. * @return array Registered Field Types data 
  1106. * @since 2.3 
  1107. */ 
  1108. public static function field_types() { 
  1109. $field_types = array( 
  1110. 'text',  
  1111. 'website',  
  1112. 'phone',  
  1113. 'email',  
  1114. 'password',  
  1115. 'paragraph',  
  1116. 'wysiwyg',  
  1117. 'code',  
  1118. 'datetime',  
  1119. 'date',  
  1120. 'time',  
  1121. 'number',  
  1122. 'currency',  
  1123. 'file',  
  1124. 'avatar',  
  1125. 'pick',  
  1126. 'boolean',  
  1127. 'color',  
  1128. 'slug' 
  1129. ); 
  1130.  
  1131. $field_types = array_merge( $field_types, array_keys( self::$field_types ) ); 
  1132.  
  1133. $field_types = array_filter( array_unique( $field_types ) ); 
  1134.  
  1135. $types = apply_filters( 'pods_api_field_types', $field_types ); 
  1136.  
  1137. $field_types = pods_transient_get( 'pods_field_types' ); 
  1138.  
  1139. if ( empty( $field_types ) || count( $types ) != count( $field_types ) ) { 
  1140. $field_types = array(); 
  1141.  
  1142. foreach ( $types as $field_type ) { 
  1143. $file = null; 
  1144.  
  1145. if ( isset( self::$field_types[ $field_type ] ) ) 
  1146. $file = self::$field_types[ $field_type ][ 'file' ]; 
  1147.  
  1148. self::field_loader( $field_type, $file ); 
  1149.  
  1150. if ( !isset( self::$loaded[ $field_type ] ) || !is_object( self::$loaded[ $field_type ] ) ) 
  1151. continue; 
  1152.  
  1153. $class_vars = get_class_vars( get_class( self::$loaded[ $field_type ] ) ); // PHP 5.2.x workaround 
  1154.  
  1155. $field_types[ $field_type ] = $class_vars; 
  1156. $field_types[ $field_type ][ 'file' ] = $file; 
  1157.  
  1158. self::$field_types = $field_types; 
  1159.  
  1160. pods_transient_set( 'pods_field_types', self::$field_types ); 
  1161. else 
  1162. self::$field_types = array_merge( $field_types, self::$field_types ); 
  1163.  
  1164. return self::$field_types; 
  1165.  
  1166. /** 
  1167. * Get list of available tableless field types 
  1168. * @return array Tableless field types 
  1169. * @since 2.3 
  1170. */ 
  1171. public static function tableless_field_types() { 
  1172. static $field_types = null; 
  1173.  
  1174. if ( null === $field_types ) { 
  1175. $field_types = array( 'pick', 'file', 'avatar', 'taxonomy' ); 
  1176.  
  1177. $field_types = apply_filters( 'pods_tableless_field_types', $field_types ); 
  1178. return $field_types; 
  1179.  
  1180. /** 
  1181. * Get list of available file field types 
  1182. * @return array File field types 
  1183. * @since 2.3 
  1184. */ 
  1185. public static function file_field_types() { 
  1186. static $field_types = null; 
  1187.  
  1188. if ( null === $field_types ) { 
  1189. $field_types = array( 'file', 'avatar' ); 
  1190.  
  1191. $field_types = apply_filters( 'pods_file_field_types', $field_types ); 
  1192. return $field_types; 
  1193.  
  1194. /** 
  1195. * Get list of available repeatable field types 
  1196. * @return array Repeatable field types 
  1197. * @since 2.3 
  1198. */ 
  1199. public static function repeatable_field_types() { 
  1200. static $field_types = null; 
  1201.  
  1202. if ( null === $field_types ) { 
  1203. $field_types = array( 
  1204. 'code',  
  1205. 'color',  
  1206. 'currency',  
  1207. 'date',  
  1208. 'datetime',  
  1209. 'email',  
  1210. 'number',  
  1211. 'paragraph',  
  1212. 'phone',  
  1213. 'text',  
  1214. 'time',  
  1215. 'website',  
  1216. 'wysiwyg' 
  1217. ); 
  1218.  
  1219. $field_types = apply_filters( 'pods_repeatable_field_types', $field_types ); 
  1220. return $field_types; 
  1221.  
  1222. /** 
  1223. * Get list of available number field types 
  1224. * @return array Number field types 
  1225. * @since 2.3 
  1226. */ 
  1227. public static function number_field_types() { 
  1228. static $field_types = null; 
  1229.  
  1230. if ( null === $field_types ) { 
  1231. $field_types = array( 'currency', 'number' ); 
  1232.  
  1233. $field_types = apply_filters( 'pods_tableless_field_types', $field_types ); 
  1234. return $field_types; 
  1235.  
  1236. /** 
  1237. * Get list of available date field types 
  1238. * @return array Date field types 
  1239. * @since 2.3 
  1240. */ 
  1241. public static function date_field_types() { 
  1242. static $field_types = null; 
  1243.  
  1244. if ( null === $field_types ) { 
  1245. $field_types = array( 'date', 'datetime', 'time' ); 
  1246.  
  1247. $field_types = apply_filters( 'pods_tableless_field_types', $field_types ); 
  1248. return $field_types; 
  1249.  
  1250. /** 
  1251. * Get list of available text field types 
  1252. * @return array Text field types 
  1253. * @since 2.3 
  1254. */ 
  1255. public static function text_field_types() { 
  1256. static $field_types = null; 
  1257.  
  1258. if ( null === $field_types ) { 
  1259. $field_types = array( 'code', 'paragraph', 'slug', 'password', 'text', 'wysiwyg' ); 
  1260.  
  1261. $field_types = apply_filters( 'pods_text_field_types', $field_types ); 
  1262. return $field_types; 
  1263.  
  1264. /** 
  1265. * Get list of available text field types 
  1266. * @return array Text field types 
  1267. * @since 2.3 
  1268. */ 
  1269. public static function block_field_types() { 
  1270. static $field_types = null; 
  1271.  
  1272. if ( null === $field_types ) { 
  1273. $field_types = array( 'heading', 'html' ); 
  1274.  
  1275. /** 
  1276. * Returns the available text field types 
  1277. * @since unknown 
  1278. * @param object $field_types Outputs the field types 
  1279. */ 
  1280.  
  1281. $field_types = apply_filters( 'pods_block_field_types', $field_types ); 
  1282. return $field_types; 
  1283.  
  1284. /** 
  1285. * Get list of available text field types 
  1286. * @return array Text field types 
  1287. * @since 2.3 
  1288. */ 
  1289. public static function simple_tableless_objects() { 
  1290. static $object_types = null; 
  1291.  
  1292. if ( null === $object_types ) { 
  1293. $object_types = PodsForm::field_method( 'pick', 'simple_objects' ); 
  1294. return $object_types; 
  1295.