PodsField_Pick

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

Defined (1)

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

/classes/fields/pick.php  
  1. class PodsField_Pick extends PodsField { 
  2.  
  3. /** 
  4. * Field Type Group 
  5. * @var string 
  6. * @since 2.0 
  7. */ 
  8. public static $group = 'Relationships / Media'; 
  9.  
  10. /** 
  11. * Field Type Identifier 
  12. * @var string 
  13. * @since 2.0 
  14. */ 
  15. public static $type = 'pick'; 
  16.  
  17. /** 
  18. * Field Type Label 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $label = 'Relationship'; 
  23.  
  24. /** 
  25. * Available Related Objects 
  26. * @var array 
  27. * @since 2.3 
  28. */ 
  29. public static $related_objects = array(); 
  30.  
  31. /** 
  32. * Custom Related Objects 
  33. * @var array 
  34. * @since 2.3 
  35. */ 
  36. public static $custom_related_objects = array(); 
  37.  
  38. /** 
  39. * Data used during validate / save to avoid extra queries 
  40. * @var array 
  41. * @since 2.3 
  42. */ 
  43. public static $related_data = array(); 
  44.  
  45. /** 
  46. * Data used during input method (mainly for autocomplete) 
  47. * @var array 
  48. * @since 2.3 
  49. */ 
  50. public static $field_data = array(); 
  51.  
  52. /** 
  53. * API caching for fields that need it during validate/save 
  54. * @var \PodsAPI 
  55. * @since 2.3 
  56. */ 
  57. protected static $api = false; 
  58.  
  59. /** 
  60. * Saved array of simple relationship names 
  61. * @var array 
  62. * @since 2.5 
  63. */ 
  64. private static $names_simple = null; 
  65.  
  66. /** 
  67. * Saved array of relationship names 
  68. * @var array 
  69. * @since 2.5 
  70. */ 
  71. private static $names_related = null; 
  72.  
  73. /** 
  74. * Saved array of bidirectional relationship names 
  75. * @var array 
  76. * @since 2.5 
  77. */ 
  78. private static $names_bidirectional = null; 
  79.  
  80. /** 
  81. * Setup related objects list 
  82. * @since 2.0 
  83. */ 
  84. public function __construct () { 
  85.  
  86.  
  87. /** 
  88. * Add admin_init actions 
  89. * @since 2.3 
  90. */ 
  91. public function admin_init () { 
  92. // AJAX for Relationship lookups 
  93. add_action( 'wp_ajax_pods_relationship', array( $this, 'admin_ajax_relationship' ) ); 
  94. add_action( 'wp_ajax_nopriv_pods_relationship', array( $this, 'admin_ajax_relationship' ) ); 
  95.  
  96. /** 
  97. * Add options and set defaults to 
  98. * @return array 
  99. * @since 2.0 
  100. */ 
  101. public function options () { 
  102. $options = array( 
  103. self::$type . '_format_type' => array( 
  104. 'label' => __( 'Selection Type', 'pods' ),  
  105. 'help' => __( 'help', 'pods' ),  
  106. 'default' => 'single',  
  107. 'type' => 'pick',  
  108. 'data' => array( 
  109. 'single' => __( 'Single Select', 'pods' ),  
  110. 'multi' => __( 'Multiple Select', 'pods' ) 
  111. ),  
  112. 'dependency' => true 
  113. ),  
  114. self::$type . '_format_single' => array( 
  115. 'label' => __( 'Format', 'pods' ),  
  116. 'help' => __( 'help', 'pods' ),  
  117. 'depends-on' => array( self::$type . '_format_type' => 'single' ),  
  118. 'default' => 'dropdown',  
  119. 'type' => 'pick',  
  120. 'data' => apply_filters( 
  121. 'pods_form_ui_field_pick_format_single_options',  
  122. array( 
  123. 'dropdown' => __( 'Drop Down', 'pods' ),  
  124. 'radio' => __( 'Radio Buttons', 'pods' ),  
  125. 'autocomplete' => __( 'Autocomplete', 'pods' ) 
  126. ) + ( ( pods_developer() && 1 == 0 ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() ) // Disable for now 
  127. ),  
  128. 'dependency' => true 
  129. ),  
  130. self::$type . '_format_multi' => array( 
  131. 'label' => __( 'Format', 'pods' ),  
  132. 'help' => __( 'help', 'pods' ),  
  133. 'depends-on' => array( self::$type . '_format_type' => 'multi' ),  
  134. 'default' => 'checkbox',  
  135. 'type' => 'pick',  
  136. 'data' => apply_filters( 
  137. 'pods_form_ui_field_pick_format_multi_options',  
  138. array( 
  139. 'checkbox' => __( 'Checkboxes', 'pods' ),  
  140. 'multiselect' => __( 'Multi Select', 'pods' ),  
  141. 'autocomplete' => __( 'Autocomplete', 'pods' ) 
  142. ) + ( ( pods_developer() && 1 == 0 ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() ) // Disable for now 
  143. ),  
  144. 'dependency' => true 
  145. ),  
  146. self::$type . '_taggable' => array( 
  147. 'label' => __( 'Taggable', 'pods' ),  
  148. 'help' => __( 'Allow new values to be inserted when using an Autocomplete field', 'pods' ),  
  149. 'excludes-on' => array( 
  150. self::$type . '_format_single' => array( 'dropdown', 'radio' ),  
  151. self::$type . '_format_multi' => array( 'checkbox', 'multiselect' ),  
  152. self::$type . '_object' => array_merge( 
  153. array( 'site', 'network' ),  
  154. self::simple_objects() 
  155. ),  
  156. 'type' => 'boolean',  
  157. 'default' => 0 
  158. ),  
  159. self::$type . '_select_text' => array( 
  160. 'label' => __( 'Default Select Text', 'pods' ),  
  161. 'help' => __( 'This is the text use for the default "no selection" dropdown item, if empty, it will default to "-- Select One --"', 'pods' ),  
  162. 'depends-on' => array( 
  163. self::$type . '_format_type' => 'single',  
  164. self::$type . '_format_single' => 'dropdown' 
  165. ),  
  166. 'default' => '',  
  167. 'type' => 'text' 
  168. ),  
  169. self::$type . '_limit' => array( 
  170. 'label' => __( 'Selection Limit', 'pods' ),  
  171. 'help' => __( 'help', 'pods' ),  
  172. 'depends-on' => array( self::$type . '_format_type' => 'multi' ),  
  173. 'default' => 0,  
  174. 'type' => 'number' 
  175. ),  
  176. self::$type . '_allow_html' => array( 
  177. 'label' => __('Allow HTML', 'pods'),  
  178. 'type' => 'boolean',  
  179. 'default' => 0 
  180. ),  
  181. self::$type . '_table_id' => array( 
  182. 'label' => __( 'Table ID Column', 'pods' ),  
  183. 'help' => __( 'You must provide the ID column name for the table, this will be used to keep track of the relationship', 'pods' ),  
  184. 'depends-on' => array( self::$type . '_object' => 'table' ),  
  185. 'required' => 1,  
  186. 'default' => '',  
  187. 'type' => 'text' 
  188. ),  
  189. self::$type . '_table_index' => array( 
  190. 'label' => __( 'Table Index Column', 'pods' ),  
  191. 'help' => __( 'You must provide the index column name for the table, this may optionally also be the ID column name', 'pods' ),  
  192. 'depends-on' => array( self::$type . '_object' => 'table' ),  
  193. 'required' => 1,  
  194. 'default' => '',  
  195. 'type' => 'text' 
  196. ),  
  197. self::$type . '_display' => array( 
  198. 'label' => __( 'Display Field in Selection List', 'pods' ),  
  199. 'help' => __( 'Provide the name of a field on the related object to reference, example: {@post_title}', 'pods' ),  
  200. 'excludes-on' => array( 
  201. self::$type . '_object' => array_merge( 
  202. array( 'site', 'network' ),  
  203. self::simple_objects() 
  204. ),  
  205. 'default' => '',  
  206. 'type' => 'text' 
  207. ),  
  208. self::$type . '_user_role' => array( 
  209. 'label' => __( 'Limit list to Role(s)', 'pods' ),  
  210. 'help' => __( 'help', 'pods' ),  
  211. 'depends-on' => array( self::$type . '_object' => 'user' ),  
  212. 'default' => '',  
  213. 'type' => 'pick',  
  214. 'pick_object' => 'role',  
  215. 'pick_format_type' => 'multi' 
  216. ), /** 
  217. self::$type . '_user_site' => array( 
  218. 'label' => __( 'Limit list to Site(s)', 'pods' ),  
  219. 'help' => __( 'help', 'pods' ),  
  220. 'depends-on' => array( self::$type . '_object' => 'user' ),  
  221. 'default' => '',  
  222. 'type' => 'pick',  
  223. 'pick_object' => 'site',  
  224. 'pick_format_type' => 'multi' 
  225. ), */ 
  226. self::$type . '_where' => array( 
  227. 'label' => __( 'Customized <em>WHERE</em>', 'pods' ),  
  228. 'help' => __( 'help', 'pods' ),  
  229. 'excludes-on' => array( 
  230. self::$type . '_object' => array_merge( 
  231. array( 'site', 'network' ),  
  232. self::simple_objects() 
  233. ),  
  234. 'default' => '',  
  235. 'type' => 'text' 
  236. ),  
  237. self::$type . '_orderby' => array( 
  238. 'label' => __( 'Customized <em>ORDER BY</em>', 'pods' ),  
  239. 'help' => __( 'help', 'pods' ),  
  240. 'excludes-on' => array( 
  241. self::$type . '_object' => array_merge( 
  242. array( 'site', 'network' ),  
  243. self::simple_objects() 
  244. ),  
  245. 'default' => '',  
  246. 'type' => 'text' 
  247. ),  
  248. self::$type . '_groupby' => array( 
  249. 'label' => __( 'Customized <em>GROUP BY</em>', 'pods' ),  
  250. 'help' => __( 'help', 'pods' ),  
  251. 'excludes-on' => array( 
  252. self::$type . '_object' => array_merge( 
  253. array( 'site', 'network' ),  
  254. self::simple_objects() 
  255. ),  
  256. 'default' => '',  
  257. 'type' => 'text' 
  258. /**,  
  259. self::$type . '_size' => array( 
  260. 'label' => __( 'Field Size', 'pods' ),  
  261. 'default' => 'medium',  
  262. 'type' => 'pick',  
  263. 'data' => array( 
  264. 'small' => __( 'Small', 'pods' ),  
  265. 'medium' => __( 'Medium', 'pods' ),  
  266. 'large' => __( 'Large', 'pods' ) 
  267. )*/ 
  268. ); 
  269.  
  270. /**if ( !is_multisite() ) 
  271. unset( $options[ self::$type . '_user_site' ] );*/ 
  272.  
  273. return $options; 
  274.  
  275. /** 
  276. * Register a related object 
  277. * @param string $name Object name 
  278. * @param string $label Object label 
  279. * @param array $options Object options 
  280. * @return array|boolean Object array or false if unsuccessful 
  281. * @since 2.3 
  282. */ 
  283. public function register_related_object ( $name, $label, $options = null ) { 
  284. if ( empty( $name ) || empty( $label ) ) 
  285. return false; 
  286.  
  287. $related_object = array( 
  288. 'label' => $label,  
  289. 'group' => 'Custom Relationships',  
  290. 'simple' => true,  
  291. 'bidirectional' => false,  
  292. 'data' => array(),  
  293. 'data_callback' => null 
  294. ); 
  295.  
  296. $related_object = array_merge( $related_object, $options ); 
  297.  
  298. self::$custom_related_objects[ $name ] = $related_object; 
  299.  
  300. return true; 
  301.  
  302. /** 
  303. * Setup related objects 
  304. * @param boolean $force Whether to force refresh of related objects 
  305. * @return bool True when data has been loaded 
  306. * @since 2.3 
  307. */ 
  308. public function setup_related_objects ( $force = false ) { 
  309. $new_data_loaded = false; 
  310.  
  311. if ( ! $force && empty( self::$related_objects ) ) { 
  312. // Only load transient if we aren't forcing a refresh 
  313. self::$related_objects = pods_transient_get( 'pods_related_objects' ); 
  314. if ( false !== self::$related_objects ) { 
  315. $new_data_loaded = true; 
  316. } elseif ( $force ) { 
  317. // If we are rebuilding, make sure we start with a clean slate 
  318. self::$related_objects = array(); 
  319.  
  320. if ( empty( self::$related_objects ) ) { 
  321. // Do a complete build of related_objects 
  322. $new_data_loaded = true; 
  323.  
  324. // Custom 
  325. self::$related_objects[ 'custom-simple' ] = array( 
  326. 'label' => __( 'Simple (custom defined list)', 'pods' ),  
  327. 'group' => __( 'Custom', 'pods' ),  
  328. 'simple' => true 
  329. ); 
  330.  
  331. // Pods 
  332. $pod_options = array(); 
  333.  
  334. // Include PodsMeta if not already included 
  335. pods_meta(); 
  336.  
  337. // Advanced Content Types 
  338. $_pods = PodsMeta::$advanced_content_types; 
  339.  
  340. foreach ( $_pods as $pod ) { 
  341. $pod_options[ $pod[ 'name' ] ] = $pod[ 'label' ] . ' (' . $pod[ 'name' ] . ')'; 
  342.  
  343. // Settings 
  344. $_pods = PodsMeta::$settings; 
  345.  
  346. foreach ( $_pods as $pod ) { 
  347. $pod_options[ $pod[ 'name' ] ] = $pod[ 'label' ] . ' (' . $pod[ 'name' ] . ')'; 
  348.  
  349. asort( $pod_options ); 
  350.  
  351. foreach ( $pod_options as $pod => $label ) { 
  352. self::$related_objects[ 'pod-' . $pod ] = array( 
  353. 'label' => $label,  
  354. 'group' => __( 'Pods', 'pods' ),  
  355. 'bidirectional' => true 
  356. ); 
  357.  
  358. // Post Types 
  359. $post_types = get_post_types(); 
  360. asort( $post_types ); 
  361.  
  362. $ignore = array( 'attachment', 'revision', 'nav_menu_item' ); 
  363.  
  364. foreach ( $post_types as $post_type => $label ) { 
  365. if ( in_array( $post_type, $ignore ) || empty( $post_type ) ) { 
  366. unset( $post_types[ $post_type ] ); 
  367.  
  368. continue; 
  369. elseif ( 0 === strpos( $post_type, '_pods_' ) && apply_filters( 'pods_pick_ignore_internal', true ) ) { 
  370. unset( $post_types[ $post_type ] ); 
  371.  
  372. continue; 
  373.  
  374. $post_type = get_post_type_object( $post_type ); 
  375.  
  376. self::$related_objects[ 'post_type-' . $post_type->name ] = array( 
  377. 'label' => $post_type->label . ' (' . $post_type->name . ')',  
  378. 'group' => __( 'Post Types', 'pods' ),  
  379. 'bidirectional' => true 
  380. ); 
  381.  
  382. // Taxonomies 
  383. $taxonomies = get_taxonomies(); 
  384. asort( $taxonomies ); 
  385.  
  386. $ignore = array( 'nav_menu', 'post_format' ); 
  387.  
  388. foreach ( $taxonomies as $taxonomy => $label ) { 
  389. if ( in_array( $taxonomy, $ignore ) || empty( $taxonomy ) ) { 
  390. unset( $taxonomies[ $taxonomy ] ); 
  391.  
  392. continue; 
  393.  
  394. /** 
  395. * Prevent ability to extend core Pods content types. 
  396. * @param bool. Default is true, when set to false Pods internal content types can not be extended. 
  397. * @since 2.3.19 
  398. */ 
  399. elseif ( 0 === strpos( $taxonomy, '_pods_' ) && apply_filters( 'pods_pick_ignore_internal', true ) ) { 
  400. unset( $taxonomies[ $taxonomy ] ); 
  401.  
  402. continue; 
  403.  
  404. $taxonomy = get_taxonomy( $taxonomy ); 
  405.  
  406. self::$related_objects[ 'taxonomy-' . $taxonomy->name ] = array( 
  407. 'label' => $taxonomy->label . ' (' . $taxonomy->name . ')',  
  408. 'group' => __( 'Taxonomies', 'pods' ),  
  409. 'bidirectional' => true 
  410. ); 
  411.  
  412. // Other WP Objects 
  413. self::$related_objects[ 'user' ] = array( 
  414. 'label' => __( 'Users', 'pods' ),  
  415. 'group' => __( 'Other WP Objects', 'pods' ),  
  416. 'bidirectional' => true 
  417. ); 
  418.  
  419. self::$related_objects[ 'role' ] = array( 
  420. 'label' => __( 'User Roles', 'pods' ),  
  421. 'group' => __( 'Other WP Objects', 'pods' ),  
  422. 'simple' => true,  
  423. 'data_callback' => array( $this, 'data_roles' ) 
  424. ); 
  425.  
  426. self::$related_objects[ 'capability' ] = array( 
  427. 'label' => __( 'User Capabilities', 'pods' ),  
  428. 'group' => __( 'Other WP Objects', 'pods' ),  
  429. 'simple' => true,  
  430. 'data_callback' => array( $this, 'data_capabilities' ) 
  431. ); 
  432.  
  433. self::$related_objects[ 'media' ] = array( 
  434. 'label' => __( 'Media', 'pods' ),  
  435. 'group' => __( 'Other WP Objects', 'pods' ),  
  436. 'bidirectional' => true 
  437. ); 
  438.  
  439. self::$related_objects[ 'comment' ] = array( 
  440. 'label' => __( 'Comments', 'pods' ),  
  441. 'group' => __( 'Other WP Objects', 'pods' ),  
  442. 'bidirectional' => true 
  443. ); 
  444.  
  445. self::$related_objects[ 'image-size' ] = array( 
  446. 'label' => __( 'Image Sizes', 'pods' ),  
  447. 'group' => __( 'Other WP Objects', 'pods' ),  
  448. 'simple' => true,  
  449. 'data_callback' => array( $this, 'data_image_sizes' ) 
  450. ); 
  451.  
  452. self::$related_objects[ 'nav_menu' ] = array( 
  453. 'label' => __( 'Navigation Menus', 'pods' ),  
  454. 'group' => __( 'Other WP Objects', 'pods' ) 
  455. ); 
  456.  
  457. self::$related_objects[ 'post_format' ] = array( 
  458. 'label' => __( 'Post Formats', 'pods' ),  
  459. 'group' => __( 'Other WP Objects', 'pods' ) 
  460. ); 
  461.  
  462. self::$related_objects[ 'post-status' ] = array( 
  463. 'label' => __( 'Post Status', 'pods' ),  
  464. 'group' => __( 'Other WP Objects', 'pods' ),  
  465. 'simple' => true,  
  466. 'data_callback' => array( $this, 'data_post_stati' ) 
  467. ); 
  468.  
  469. do_action( 'pods_form_ui_field_pick_related_objects_other' ); 
  470.  
  471. self::$related_objects[ 'country' ] = array( 
  472. 'label' => __( 'Countries', 'pods' ),  
  473. 'group' => __( 'Predefined Lists', 'pods' ),  
  474. 'simple' => true,  
  475. 'data_callback' => array( $this, 'data_countries' ) 
  476. ); 
  477.  
  478. self::$related_objects[ 'us_state' ] = array( 
  479. 'label' => __( 'US States', 'pods' ),  
  480. 'group' => __( 'Predefined Lists', 'pods' ),  
  481. 'simple' => true,  
  482. 'data_callback' => array( $this, 'data_us_states' ) 
  483. ); 
  484.  
  485. self::$related_objects[ 'days_of_week' ] = array( 
  486. 'label' => __( 'Calendar - Days of Week', 'pods' ),  
  487. 'group' => __( 'Predefined Lists', 'pods' ),  
  488. 'simple' => true,  
  489. 'data_callback' => array( $this, 'data_days_of_week' ) 
  490. ); 
  491.  
  492. self::$related_objects[ 'months_of_year' ] = array( 
  493. 'label' => __( 'Calendar - Months of Year', 'pods' ),  
  494. 'group' => __( 'Predefined Lists', 'pods' ),  
  495. 'simple' => true,  
  496. 'data_callback' => array( $this, 'data_months_of_year' ) 
  497. ); 
  498.  
  499. do_action( 'pods_form_ui_field_pick_related_objects_predefined' ); 
  500.  
  501. if ( did_action( 'init' ) ) 
  502. pods_transient_set( 'pods_related_objects', self::$related_objects ); 
  503.  
  504. foreach ( self::$custom_related_objects as $object => $related_object ) { 
  505. if ( ! isset( self::$related_objects[ $object ] ) ) { 
  506. $new_data_loaded = true; 
  507. self::$related_objects[ $object ] = $related_object; 
  508. return $new_data_loaded; 
  509.  
  510. /** 
  511. * Return available related objects 
  512. * @param boolean $force Whether to force refresh of related objects 
  513. * @return array Field selection array 
  514. * @since 2.3 
  515. */ 
  516. public function related_objects ( $force = false ) { 
  517. if ( $this->setup_related_objects( $force ) || null === self::$names_related ) { 
  518. $related_objects = array(); 
  519.  
  520. foreach ( self::$related_objects as $related_object_name => $related_object ) { 
  521. if ( ! isset( $related_objects[ $related_object[ 'group' ] ] ) ) { 
  522. $related_objects[ $related_object[ 'group' ] ] = array(); 
  523.  
  524. $related_objects[ $related_object[ 'group' ] ][ $related_object_name ] = $related_object[ 'label' ]; 
  525.  
  526. self::$names_related = (array) apply_filters( 'pods_form_ui_field_pick_related_objects', $related_objects ); 
  527.  
  528. return self::$names_related; 
  529.  
  530. /** 
  531. * Return available simple object names 
  532. * @return array Simple object names 
  533. * @since 2.3 
  534. */ 
  535. public function simple_objects () { 
  536. if ( $this->setup_related_objects() || null === self::$names_simple ) { 
  537. $simple_objects = array(); 
  538.  
  539. foreach ( self::$related_objects as $object => $related_object ) { 
  540. if ( !isset( $related_object[ 'simple' ] ) || !$related_object[ 'simple' ] ) 
  541. continue; 
  542.  
  543. $simple_objects[] = $object; 
  544.  
  545. self::$names_simple = (array) apply_filters( 'pods_form_ui_field_pick_simple_objects', $simple_objects ); 
  546.  
  547. return self::$names_simple; 
  548.  
  549. /** 
  550. * Return available bidirectional object names 
  551. * @return array Bidirectional object names 
  552. * @since 2.3.4 
  553. */ 
  554. public function bidirectional_objects () { 
  555. if ( $this->setup_related_objects() || null === self::$names_bidirectional ) { 
  556. $bidirectional_objects = array(); 
  557.  
  558. foreach ( self::$related_objects as $object => $related_object ) { 
  559. if ( !isset( $related_object[ 'bidirectional' ] ) || !$related_object[ 'bidirectional' ] ) 
  560. continue; 
  561.  
  562. $bidirectional_objects[] = $object; 
  563.  
  564. self::$names_bidirectional = (array) apply_filters( 'pods_form_ui_field_pick_bidirectional_objects', $bidirectional_objects ); 
  565.  
  566. return self::$names_bidirectional; 
  567.  
  568. /** 
  569. * Define the current field's schema for DB table storage 
  570. * @param array $options 
  571. * @return array 
  572. * @since 2.0 
  573. */ 
  574. public function schema ( $options = null ) { 
  575. $schema = false; 
  576.  
  577. $simple_tableless_objects = $this->simple_objects(); 
  578.  
  579. if ( in_array( pods_var( self::$type . '_object', $options ), $simple_tableless_objects ) ) 
  580. $schema = 'LONGTEXT'; 
  581.  
  582. return $schema; 
  583.  
  584. /** 
  585. * Change the way the value of the field is displayed with Pods::get 
  586. * @param mixed $value 
  587. * @param string $name 
  588. * @param array $options 
  589. * @param array $fields 
  590. * @param array $pod 
  591. * @param int $id 
  592. * @since 2.0 
  593. */ 
  594. public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  595. $fields = null; 
  596.  
  597. if ( is_object( $pod ) && isset( $pod->fields ) ) { 
  598. $fields = $pod->fields; 
  599.  
  600. if ( ! empty( $pod->pod_data[ 'object_fields' ] ) ) { 
  601. $fields = array_merge( $fields, $pod->pod_data[ 'object_fields' ] ); 
  602. } elseif ( is_array( $pod ) && isset( $pod[ 'fields' ] ) ) { 
  603. $fields = $pod[ 'fields' ]; 
  604.  
  605. if ( ! empty( $pod[ 'object_fields' ] ) ) { 
  606. $fields = array_merge( $fields, $pod[ 'object_fields' ] ); 
  607.  
  608. return pods_serial_comma( $value, array( 'field' => $name, 'fields' => $fields ) ); 
  609.  
  610. /** 
  611. * Customize output of the form field 
  612. * @param string $name 
  613. * @param mixed $value 
  614. * @param array $options 
  615. * @param array $pod 
  616. * @param int $id 
  617. * @since 2.0 
  618. */ 
  619. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  620. global $wpdb; 
  621.  
  622. $options = (array) $options; 
  623. $form_field_type = PodsForm::$field_type; 
  624.  
  625. $options[ 'grouped' ] = 1; 
  626.  
  627. $options[ 'table_info' ] = array(); 
  628.  
  629. $custom = pods_var_raw( self::$type . '_custom', $options, false ); 
  630.  
  631. $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id ); 
  632.  
  633. $ajax = false; 
  634.  
  635. if ( ( 'custom-simple' != pods_var( self::$type . '_object', $options ) || empty( $custom ) ) && '' != pods_var( self::$type . '_object', $options, '', null, true ) ) 
  636. $ajax = true; 
  637.  
  638. if ( !empty( self::$field_data ) && self::$field_data[ 'id' ] == $options[ 'id' ] ) { 
  639. $ajax = (boolean) self::$field_data[ 'autocomplete' ]; 
  640.  
  641. $ajax = apply_filters( 'pods_form_ui_field_pick_ajax', $ajax, $name, $value, $options, $pod, $id ); 
  642.  
  643. if ( 0 == pods_var( self::$type . '_ajax', $options, 1 ) ) 
  644. $ajax = false; 
  645.  
  646. if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) ) { 
  647. if ( 'dropdown' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) 
  648. $field_type = 'select'; 
  649. elseif ( 'radio' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) 
  650. $field_type = 'radio'; 
  651. elseif ( 'autocomplete' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) 
  652. $field_type = 'select2'; 
  653. else { 
  654. // Support custom integration 
  655. do_action( 'pods_form_ui_field_pick_input_' . pods_var( self::$type . '_format_type', $options, 'single' ) . '_' . pods_var( self::$type . '_format_single', $options, 'dropdown' ), $name, $value, $options, $pod, $id ); 
  656. do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id ); 
  657. return; 
  658. elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) ) { 
  659. if ( !empty( $value ) && !is_array( $value ) ) 
  660. $value = explode( ', ', $value ); 
  661.  
  662. if ( 'checkbox' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) 
  663. $field_type = 'checkbox'; 
  664. elseif ( 'multiselect' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) 
  665. $field_type = 'select'; 
  666. elseif ( 'autocomplete' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) 
  667. $field_type = 'select2'; 
  668. else { 
  669. // Support custom integration 
  670. do_action( 'pods_form_ui_field_pick_input_' . pods_var( self::$type . '_format_type', $options, 'single' ) . '_' . pods_var( self::$type . '_format_multi', $options, 'checkbox' ), $name, $value, $options, $pod, $id ); 
  671. do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id ); 
  672. return; 
  673. else { 
  674. // Support custom integration 
  675. do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id ); 
  676. return; 
  677.  
  678. pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) ); 
  679.  
  680. /** 
  681. * Validate a value before it's saved 
  682. * @param mixed $value 
  683. * @param string $name 
  684. * @param array $options 
  685. * @param array $fields 
  686. * @param array $pod 
  687. * @param int $id 
  688. * @param null $params 
  689. * @return array|bool 
  690. * @since 2.0 
  691. */ 
  692. public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { 
  693. if ( empty( self::$api ) ) 
  694. self::$api = pods_api(); 
  695.  
  696. $simple_tableless_objects = $this->simple_objects(); 
  697.  
  698. $related_pick_limit = 0; 
  699. $related_field = $related_pod = $current_related_ids = false; 
  700.  
  701. // Bidirectional relationship requirement checks 
  702. $related_object = pods_var( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc.. 
  703. $related_val = pods_var( self::$type . '_val', $options, $related_object, null, true ); // pod name, post type name, taxonomy name, etc.. 
  704. if ( empty( $related_val ) ) { 
  705. $related_val = $related_object; 
  706.  
  707. $related_sister_id = (int) pods_var( 'sister_id', $options, 0 ); 
  708.  
  709. $options[ 'id' ] = (int) $options[ 'id' ]; 
  710.  
  711. if ( !isset( self::$related_data[ $options[ 'id' ] ] ) || empty( self::$related_data[ $options[ 'id' ] ] ) ) 
  712. self::$related_data[ $options[ 'id' ] ] = array(); 
  713.  
  714. if ( !empty( $related_sister_id ) && !in_array( $related_object, $simple_tableless_objects ) ) { 
  715. $related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false ); 
  716.  
  717. if ( false !== $related_pod && ( 'pod' == $related_object || $related_object == $related_pod[ 'type' ] ) ) { 
  718. $related_field = false; 
  719.  
  720. // Ensure sister_id exists on related Pod 
  721. foreach ( $related_pod[ 'fields' ] as $related_pod_field ) { 
  722. if ( 'pick' == $related_pod_field[ 'type' ] && $related_sister_id == $related_pod_field[ 'id' ] ) { 
  723. $related_field = $related_pod_field; 
  724.  
  725. break; 
  726.  
  727. if ( !empty( $related_field ) ) { 
  728. $current_ids = self::$api->lookup_related_items( $fields[ $name ][ 'id' ], $pod[ 'id' ], $id, $fields[ $name ], $pod ); 
  729.  
  730. self::$related_data[ $options[ 'id' ] ][ 'current_ids' ] = $current_ids; 
  731.  
  732. $value_ids = $value; 
  733.  
  734. // Convert values from a comma-separated string into an array 
  735. if ( !is_array( $value_ids ) ) 
  736. $value_ids = explode( ', ', $value_ids ); 
  737.  
  738. $value_ids = array_unique( array_filter( $value_ids ) ); 
  739.  
  740. // Get ids to remove 
  741. $remove_ids = array_diff( $current_ids, $value_ids ); 
  742.  
  743. $related_required = (boolean) pods_var( 'required', $related_field[ 'options' ], 0 ); 
  744. $related_pick_limit = (int) pods_var( self::$type . '_limit', $related_field[ 'options' ], 0 ); 
  745.  
  746. if ( 'single' == pods_var_raw( self::$type . '_format_type', $related_field[ 'options' ] ) ) 
  747. $related_pick_limit = 1; 
  748.  
  749. // Validate Required 
  750. if ( $related_required && !empty( $remove_ids ) ) { 
  751. foreach ( $remove_ids as $related_id ) { 
  752. $bidirectional_ids = self::$api->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod ); 
  753.  
  754. self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] = $bidirectional_ids; 
  755.  
  756. if ( empty( $bidirectional_ids ) || ( in_array( $id, $bidirectional_ids ) && 1 == count( $bidirectional_ids ) ) ) 
  757. return sprintf( __( 'The %s field is required and cannot be removed by the %s field', 'pods' ), $related_field[ 'label' ], $options[ 'label' ] ); 
  758. else 
  759. $related_pod = false; 
  760. else 
  761. $related_pod = false; 
  762.  
  763. if ( empty( self::$related_data[ $options[ 'id' ] ] ) ) 
  764. unset( self::$related_data[ $options[ 'id' ] ] ); 
  765. else { 
  766. self::$related_data[ $options[ 'id' ] ][ 'related_pod' ] = $related_pod; 
  767. self::$related_data[ $options[ 'id' ] ][ 'related_field' ] = $related_field; 
  768. self::$related_data[ $options[ 'id' ] ][ 'related_pick_limit' ] = $related_pick_limit; 
  769.  
  770. $pick_limit = (int) pods_var( self::$type . '_limit', $options[ 'options' ], 0 ); 
  771.  
  772. if ( 'single' == pods_var_raw( self::$type . '_format_type', $options[ 'options' ] ) ) 
  773. $pick_limit = 1; 
  774.  
  775. $related_field[ 'id' ] = (int) $related_field[ 'id' ]; 
  776.  
  777. if ( !isset( self::$related_data[ $related_field[ 'id' ] ] ) || empty( self::$related_data[ $related_field[ 'id' ] ] ) ) { 
  778. self::$related_data[ $related_field[ 'id' ] ] = array( 
  779. 'related_pod' => $pod,  
  780. 'related_field' => $options,  
  781. 'related_pick_limit' => $pick_limit 
  782. ); 
  783.  
  784. return true; 
  785.  
  786. /** 
  787. * Save the value to the DB 
  788. * @param mixed $value 
  789. * @param int $id 
  790. * @param string $name 
  791. * @param array $options 
  792. * @param array $fields 
  793. * @param array $pod 
  794. * @param object $params 
  795. * @since 2.3 
  796. */ 
  797. public function save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  798. if ( empty( self::$api ) ) 
  799. self::$api = pods_api(); 
  800.  
  801. $options[ 'id' ] = (int) $options[ 'id' ]; 
  802.  
  803. if ( !isset( self::$related_data[ $options[ 'id' ] ] ) ) 
  804. return; 
  805.  
  806. $related_pod = self::$related_data[ $options[ 'id' ] ][ 'related_pod' ]; 
  807. $related_field = self::$related_data[ $options[ 'id' ] ][ 'related_field' ]; 
  808. $related_pick_limit = self::$related_data[ $options[ 'id' ] ][ 'related_pick_limit' ]; 
  809.  
  810. // Bidirectional relationship updates 
  811. if ( !empty( $related_field ) ) { 
  812. // Don't use no conflict mode unless this isn't the current pod type 
  813. $no_conflict = true; 
  814.  
  815. if ( $related_pod[ 'type' ] != $pod[ 'type' ] ) 
  816. $no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] ); 
  817.  
  818. if ( !$no_conflict ) 
  819. pods_no_conflict_on( $related_pod[ 'type' ] ); 
  820.  
  821. $value = array_filter( $value ); 
  822.  
  823. foreach ( $value as $related_id ) { 
  824. if ( isset( self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] ) && !empty( self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] ) ) 
  825. $bidirectional_ids = self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ]; 
  826. else 
  827. $bidirectional_ids = self::$api->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod ); 
  828.  
  829. $bidirectional_ids = array_filter( $bidirectional_ids ); 
  830.  
  831. if ( empty( $bidirectional_ids ) ) 
  832. $bidirectional_ids = array(); 
  833.  
  834. $remove_ids = array(); 
  835.  
  836. if ( 0 < $related_pick_limit && !empty( $bidirectional_ids ) && !in_array( $id, $bidirectional_ids ) ) { 
  837. while ( $related_pick_limit <= count( $bidirectional_ids ) ) { 
  838. $remove_ids[] = (int) array_pop( $bidirectional_ids ); 
  839.  
  840. // Remove this item from related items no longer related to 
  841. $remove_ids = array_unique( array_filter( $remove_ids ) ); 
  842.  
  843. // Add to related items 
  844. if ( !in_array( $id, $bidirectional_ids ) ) 
  845. $bidirectional_ids[] = $id; 
  846. // Nothing to change 
  847. elseif ( empty( $remove_ids ) ) 
  848. continue; 
  849.  
  850. self::$api->save_relationships( $related_id, $bidirectional_ids, $related_pod, $related_field ); 
  851.  
  852. if ( !empty( $remove_ids ) ) 
  853. self::$api->delete_relationships( $remove_ids, $related_id, $pod, $options ); 
  854.  
  855. if ( !$no_conflict ) 
  856. pods_no_conflict_off( $related_pod[ 'type' ] ); 
  857.  
  858. /** 
  859. * Delete the value from the DB 
  860. * @param int $id 
  861. * @param string $name 
  862. * @param array $options 
  863. * @param array $pod 
  864. * @since 2.3 
  865. */ 
  866. public function delete ( $id = null, $name = null, $options = null, $pod = null ) { 
  867. if ( empty( self::$api ) ) 
  868. self::$api = pods_api(); 
  869.  
  870. $simple_tableless_objects = $this->simple_objects(); 
  871.  
  872. // Bidirectional relationship requirement checks 
  873. $related_object = pods_var( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc.. 
  874. $related_val = pods_var( self::$type . '_val', $options, $related_object, null, true ); // pod name, post type name, taxonomy name, etc.. 
  875. $related_sister_id = (int) pods_var( 'sister_id', $options, 0 ); 
  876.  
  877. if ( !empty( $related_sister_id ) && !in_array( $related_object, $simple_tableless_objects ) ) { 
  878. $related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false ); 
  879.  
  880. if ( false !== $related_pod && ( 'pod' == $related_object || $related_object == $related_pod[ 'type' ] ) ) { 
  881. $related_field = false; 
  882.  
  883. // Ensure sister_id exists on related Pod 
  884. foreach ( $related_pod[ 'fields' ] as $related_pod_field ) { 
  885. if ( 'pick' == $related_pod_field[ 'type' ] && $related_sister_id == $related_pod_field[ 'id' ] ) { 
  886. $related_field = $related_pod_field; 
  887.  
  888. break; 
  889.  
  890. if ( !empty( $related_field ) ) { 
  891. $values = self::$api->lookup_related_items( $options[ 'id' ], $pod[ 'id' ], $id, $options, $pod ); 
  892.  
  893. if ( !empty( $values ) ) { 
  894. $no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] ); 
  895.  
  896. if ( !$no_conflict ) 
  897. pods_no_conflict_on( $related_pod[ 'type' ] ); 
  898.  
  899. self::$api->delete_relationships( $values, $id, $related_pod, $related_field ); 
  900.  
  901. if ( !$no_conflict ) 
  902. pods_no_conflict_off( $related_pod[ 'type' ] ); 
  903.  
  904. /** 
  905. * Customize the Pods UI manage table column output 
  906. * @param int $id 
  907. * @param mixed $value 
  908. * @param string $name 
  909. * @param array $options 
  910. * @param array $fields 
  911. * @param array $pod 
  912. * @since 2.0 
  913. */ 
  914. public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { 
  915. $value = $this->simple_value( $name, $value, $options, $pod, $id ); 
  916.  
  917. return $this->display( $value, $name, $options, $pod, $id ); 
  918.  
  919. /** 
  920. * Get the data from the field 
  921. * @param string $name The name of the field 
  922. * @param string|array $value The value of the field 
  923. * @param array $options Field options 
  924. * @param array $pod Pod data 
  925. * @param int $id Item ID 
  926. * @param boolean $in_form 
  927. * @return array Array of possible field data 
  928. * @since 2.0 
  929. */ 
  930. public function data ( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) { 
  931. if ( isset( $options[ 'options' ] ) ) { 
  932. $options = array_merge( $options, $options[ 'options' ] ); 
  933.  
  934. unset( $options[ 'options' ] ); 
  935.  
  936. $data = pods_var_raw( 'data', $options, null, null, true ); 
  937.  
  938. $object_params = array( 
  939. 'name' => $name, // The name of the field 
  940. 'value' => $value, // The value of the field 
  941. 'options' => $options, // Field options 
  942. 'pod' => $pod, // Pod data 
  943. 'id' => $id, // Item ID 
  944. 'context' => 'data', // Data context 
  945. ); 
  946.  
  947. if ( null !== $data ) 
  948. $data = (array) $data; 
  949. else 
  950. $data = $this->get_object_data( $object_params ); 
  951.  
  952. if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'dropdown' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) 
  953. $data = array( '' => pods_var_raw( self::$type . '_select_text', $options, __( '-- Select One --', 'pods' ), null, true ) ) + $data; 
  954.  
  955. $data = apply_filters( 'pods_field_pick_data', $data, $name, $value, $options, $pod, $id ); 
  956.  
  957. return $data; 
  958.  
  959. /** 
  960. * Convert a simple value to the correct value 
  961. * @param string $name The name of the field 
  962. * @param string|array $value The value of the field 
  963. * @param array $options Field options 
  964. * @param array $pod Pod data 
  965. * @param int $id Item ID 
  966. * @param boolean $raw Whether to return the raw list of keys (true) or convert to key=>value (false) 
  967. * @return mixed Corrected value 
  968. */ 
  969. public function simple_value ( $name, $value = null, $options = null, $pod = null, $id = null, $raw = false ) { 
  970. if ( in_array( pods_var( self::$type . '_object', $options ), self::simple_objects() ) ) { 
  971. if ( isset( $options[ 'options' ] ) ) { 
  972. $options = array_merge( $options, $options[ 'options' ] ); 
  973.  
  974. unset( $options[ 'options' ] ); 
  975.  
  976. if ( !is_array( $value ) && 0 < strlen( $value ) ) { 
  977. $simple = @json_decode( $value, true ); 
  978.  
  979. if ( is_array( $simple ) ) 
  980. $value = $simple; 
  981.  
  982. $data = pods_var_raw( 'data', $options, null, null, true ); 
  983.  
  984. $object_params = array( 
  985. 'name' => $name, // The name of the field 
  986. 'value' => $value, // The value of the field 
  987. 'options' => $options, // Field options 
  988. 'pod' => $pod, // Pod data 
  989. 'id' => $id, // Item ID 
  990. 'context' => 'simple_value', // Data context 
  991. ); 
  992.  
  993. if ( null === $data ) 
  994. $data = $this->get_object_data( $object_params ); 
  995.  
  996. $data = (array) $data; 
  997.  
  998. $key = 0; 
  999.  
  1000. if ( is_array( $value ) ) { 
  1001. if ( !empty( $data ) ) { 
  1002. $val = array(); 
  1003.  
  1004. foreach ( $value as $k => $v ) { 
  1005. if ( isset( $data[ $v ] ) ) { 
  1006. if ( false === $raw ) { 
  1007. $k = $v; 
  1008. $v = $data[ $v ]; 
  1009.  
  1010. $val[ $k ] = $v; 
  1011.  
  1012. $value = $val; 
  1013. elseif ( isset( $data[ $value ] ) && false === $raw ) { 
  1014. $key = $value; 
  1015. $value = $data[ $value ]; 
  1016.  
  1017. $single_multi = pods_var( self::$type . '_format_type', $options, 'single' ); 
  1018.  
  1019. if ( 'multi' == $single_multi ) 
  1020. $limit = (int) pods_var( self::$type . '_limit', $options, 0 ); 
  1021. else 
  1022. $limit = 1; 
  1023.  
  1024. if ( is_array( $value ) && 0 < $limit ) { 
  1025. if ( 1 == $limit ) 
  1026. $value = current( $value ); 
  1027. else 
  1028. $value = array_slice( $value, 0, $limit, true ); 
  1029. elseif ( !is_array( $value ) && null !== $value && 0 < strlen( $value ) ) { 
  1030. if ( 1 != $limit || ( true === $raw && 'multi' == $single_multi ) ) { 
  1031. $value = array( 
  1032. $key => $value 
  1033. ); 
  1034.  
  1035. return $value; 
  1036.  
  1037. /** 
  1038. * Get the label from a pick value 
  1039. * @param string $name The name of the field 
  1040. * @param string|array $value The value of the field 
  1041. * @param array $options Field options 
  1042. * @param array $pod Pod data 
  1043. * @param int $id Item ID 
  1044. * @return string 
  1045. * @since 2.2 
  1046. */ 
  1047. public function value_to_label ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  1048. if ( isset( $options[ 'options' ] ) ) { 
  1049. $options = array_merge( $options, $options[ 'options' ] ); 
  1050.  
  1051. unset( $options[ 'options' ] ); 
  1052.  
  1053. $data = pods_var_raw( 'data', $options, null, null, true ); 
  1054.  
  1055. $object_params = array( 
  1056. 'name' => $name, // The name of the field 
  1057. 'value' => $value, // The value of the field 
  1058. 'options' => $options, // Field options 
  1059. 'pod' => $pod, // Pod data 
  1060. 'id' => $id, // Item ID 
  1061. 'context' => 'value_to_label', // Data context 
  1062. ); 
  1063.  
  1064. if ( null !== $data ) 
  1065. $data = (array) $data; 
  1066. else 
  1067. $data = $this->get_object_data( $object_params ); 
  1068.  
  1069. $labels = array(); 
  1070.  
  1071. foreach ( $data as $v => $l ) { 
  1072. if ( !in_array( $l, $labels ) && ( $value == $v || ( is_array( $value ) && in_array( $v, $value ) ) ) ) 
  1073. $labels[] = $l; 
  1074.  
  1075. $labels = apply_filters( 'pods_field_pick_value_to_label', $labels, $name, $value, $options, $pod, $id ); 
  1076.  
  1077. $labels = pods_serial_comma( $labels ); 
  1078.  
  1079. return $labels; 
  1080.  
  1081. /** 
  1082. * Get available items from a relationship field 
  1083. * @param array|string $field Field array or field name 
  1084. * @param array $options [optional] Field options array overrides 
  1085. * @param array $object_params [optional] Additional get_object_data options 
  1086. * @return array An array of available items from a relationship field 
  1087. */ 
  1088. public function get_field_data( $field, $options = array(), $object_params = array() ) { 
  1089.  
  1090. // Handle field array overrides 
  1091. if ( is_array( $field ) ) { 
  1092. $options = array_merge( $field, $options ); 
  1093.  
  1094. // Get field name from array 
  1095. $field = pods_var_raw( 'name', $options, $field, null, true ); 
  1096.  
  1097. // Field name or options not set 
  1098. if ( empty( $field ) || empty( $options ) ) { 
  1099. return array(); 
  1100.  
  1101. // Options normalization 
  1102. $options = array_merge( $options, pods_var_raw( 'options', $options, array(), null, true ) ); 
  1103.  
  1104. // Setup object params 
  1105. $object_params = array_merge( 
  1106. array( 
  1107. 'name' => $field, // The name of the field 
  1108. 'options' => $options, // Field options 
  1109. ),  
  1110. $object_params 
  1111. ); 
  1112.  
  1113. // Get data override 
  1114. $data = pods_var_raw( 'data', $options, null, null, true ); 
  1115.  
  1116. // Return data override 
  1117. if ( null !== $data ) { 
  1118. $data = (array) $data; 
  1119. // Get object data 
  1120. else { 
  1121. $data = $this->get_object_data( $object_params ); 
  1122.  
  1123. return $data; 
  1124.  
  1125.  
  1126. /** 
  1127. * Get data from relationship objects 
  1128. * @param array $object_params Object data parameters 
  1129. * @return array|bool Object data 
  1130. */ 
  1131. public function get_object_data ( $object_params = null ) { 
  1132. global $wpdb, $polylang, $sitepress, $icl_adjust_id_url_filter_off; 
  1133.  
  1134. $current_language = false; 
  1135.  
  1136. // WPML support 
  1137. if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off ) 
  1138. $current_language = pods_sanitize( ICL_LANGUAGE_CODE ); 
  1139. // Polylang support 
  1140. elseif ( function_exists( 'pll_current_language' ) ) 
  1141. $current_language = pll_current_language( 'slug' ); 
  1142.  
  1143. $object_params = array_merge( 
  1144. array( 
  1145. 'name' => '', // The name of the field 
  1146. 'value' => '', // The value of the field 
  1147. 'options' => array(), // Field options 
  1148. 'pod' => '', // Pod data 
  1149. 'id' => '', // Item ID 
  1150. 'context' => '', // Data context 
  1151. 'data_params' => array( 
  1152. 'query' => '' // Query being searched 
  1153. ),  
  1154. 'page' => 1, // Page number of results to get 
  1155. 'limit' => 0 // How many data items to limit to (autocomplete defaults to 30, set to -1 or 1+ to override) 
  1156. ),  
  1157. $object_params 
  1158. ); 
  1159.  
  1160. $name = $object_params[ 'name' ]; 
  1161. $value = $object_params[ 'value' ]; 
  1162. $options = $object_params[ 'options' ] = (array) $object_params[ 'options' ]; 
  1163. $pod = $object_params[ 'pod' ]; 
  1164. $id = $object_params[ 'id' ]; 
  1165. $context = $object_params[ 'context' ]; 
  1166. $data_params = $object_params[ 'data_params' ] = (array) $object_params[ 'data_params' ]; 
  1167. $page = min( 1, (int) $object_params[ 'page' ] ); 
  1168. $limit = (int) $object_params[ 'limit' ]; 
  1169.  
  1170. if ( isset( $options[ 'options' ] ) ) { 
  1171. $options = array_merge( $options, $options[ 'options' ] ); 
  1172.  
  1173. unset( $options[ 'options' ] ); 
  1174.  
  1175. $data = apply_filters( 'pods_field_pick_object_data', null, $name, $value, $options, $pod, $id, $object_params ); 
  1176. $items = array(); 
  1177.  
  1178. if ( !isset( $options[ self::$type . '_object' ] ) ) 
  1179. $data = pods_var_raw( 'data', $options, array(), null, true ); 
  1180.  
  1181. $simple = false; 
  1182.  
  1183. if ( null === $data ) { 
  1184. $data = array(); 
  1185.  
  1186. if ( 'custom-simple' == $options[ self::$type . '_object' ] ) { 
  1187. $custom = pods_var_raw( self::$type . '_custom', $options, '' ); 
  1188.  
  1189. $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id, $object_params ); 
  1190.  
  1191. if ( !empty( $custom ) ) { 
  1192. if ( !is_array( $custom ) ) { 
  1193. $data = array(); 
  1194.  
  1195. $custom = explode( "\n", trim( $custom ) ); 
  1196.  
  1197. foreach ( $custom as $custom_value ) { 
  1198. $custom_label = explode( '|', $custom_value ); 
  1199.  
  1200. if ( empty( $custom_label ) ) 
  1201. continue; 
  1202.  
  1203. if ( 1 == count( $custom_label ) ) 
  1204. $custom_label = $custom_value; 
  1205. else { 
  1206. $custom_value = $custom_label[ 0 ]; 
  1207. $custom_label = $custom_label[ 1 ]; 
  1208.  
  1209. $custom_value = trim( (string) $custom_value ); 
  1210. $custom_label = trim( (string) $custom_label ); 
  1211.  
  1212. $data[ $custom_value ] = $custom_label; 
  1213. else 
  1214. $data = $custom; 
  1215.  
  1216. $simple = true; 
  1217. elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] ) && !empty( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] ) ) { 
  1218. $data = self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ]; 
  1219.  
  1220. $simple = true; 
  1221. elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ] ) && is_callable( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ] ) ) { 
  1222. $data = call_user_func_array( 
  1223. self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ],  
  1224. array( $name, $value, $options, $pod, $id ) 
  1225. ); 
  1226.  
  1227. $simple = true; 
  1228.  
  1229. // Cache data from callback 
  1230. if ( !empty( $data ) ) 
  1231. self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] = $data; 
  1232. elseif ( 'simple_value' != $context ) { 
  1233. $pick_val = pods_var( self::$type . '_val', $options ); 
  1234.  
  1235. if ( 'table' == pods_var( self::$type . '_object', $options ) ) 
  1236. $pick_val = pods_var( self::$type . '_table', $options, $pick_val, null, true ); 
  1237.  
  1238. if ( '__current__' == $pick_val ) { 
  1239. if ( is_object( $pod ) ) 
  1240. $pick_val = $pod->pod; 
  1241. elseif ( is_array( $pod ) ) 
  1242. $pick_val = $pod[ 'name' ]; 
  1243. elseif ( 0 < strlen( $pod ) ) 
  1244. $pick_val = $pod; 
  1245.  
  1246. $options[ 'table_info' ] = pods_api()->get_table_info( pods_var( self::$type . '_object', $options ), $pick_val, null, null, $options ); 
  1247.  
  1248. $search_data = pods_data(); 
  1249. $search_data->table( $options[ 'table_info' ] ); 
  1250.  
  1251. if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'name' ] ) ) { 
  1252. $search_data->pod = $options[ 'table_info' ][ 'pod' ][ 'name' ]; 
  1253. $search_data->fields = $options[ 'table_info' ][ 'pod' ][ 'fields' ]; 
  1254.  
  1255. $params = array( 
  1256. 'select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`",  
  1257. 'table' => $search_data->table,  
  1258. 'where' => pods_var_raw( self::$type . '_where', $options, (array) $options[ 'table_info' ][ 'where_default' ], null, true ),  
  1259. 'orderby' => pods_var_raw( self::$type . '_orderby', $options, null, null, true ),  
  1260. 'groupby' => pods_var_raw( self::$type . '_groupby', $options, null, null, true ),  
  1261. //'having' => pods_var_raw( self::$type . '_having', $options, null, null, true ),  
  1262. 'pagination' => false,  
  1263. 'search' => false 
  1264. ); 
  1265.  
  1266. if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ) ) ) 
  1267. $params[ 'select' ] .= ', `t`.`path`'; 
  1268.  
  1269. if ( !empty( $params[ 'where' ] ) && (array) $options[ 'table_info' ][ 'where_default' ] != $params[ 'where' ] ) 
  1270. $params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ], true ); 
  1271.  
  1272. if ( empty( $params[ 'where' ] ) || ( !is_array( $params[ 'where' ] ) && strlen( trim( $params[ 'where' ] ) ) < 1 ) ) 
  1273. $params[ 'where' ] = array(); 
  1274. elseif ( !is_array( $params[ 'where' ] ) ) 
  1275. $params[ 'where' ] = (array) $params[ 'where' ]; 
  1276.  
  1277. if ( 'value_to_label' == $context ) 
  1278. $params[ 'where' ][] = "`t`.`{$search_data->field_id}` = " . number_format( $value, 0, '', '' ); 
  1279.  
  1280. /** not needed yet 
  1281. if ( !empty( $params[ 'orderby' ] ) ) 
  1282. $params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true ); 
  1283.   
  1284. if ( !empty( $params[ 'groupby' ] ) ) 
  1285. $params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/ 
  1286.  
  1287. $display = trim( pods_var( self::$type . '_display', $options ), ' {@}' ); 
  1288.  
  1289. if ( 0 < strlen( $display ) ) { 
  1290. if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) ) { 
  1291. if ( isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ][ $display ] ) ) { 
  1292. $search_data->field_index = $display; 
  1293.  
  1294. $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; 
  1295. elseif ( isset( $options[ 'table_info' ][ 'pod' ][ 'fields' ][ $display ] ) ) { 
  1296. $search_data->field_index = $display; 
  1297.  
  1298. if ( 'table' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] && !in_array( $options[ 'table_info' ][ 'pod' ][ 'type' ], array( 'pod', 'table' ) ) ) 
  1299. $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`"; 
  1300. elseif ( 'meta' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] ) 
  1301. $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `{$search_data->field_index}`.`meta_value` AS {$search_data->field_index}"; 
  1302. else 
  1303. $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; 
  1304. elseif ( isset( $options[ 'table_info' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'object_fields' ][ $display ] ) ) { 
  1305. $search_data->field_index = $display; 
  1306.  
  1307. $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; 
  1308.  
  1309. $autocomplete = false; 
  1310.  
  1311. if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'autocomplete' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) 
  1312. $autocomplete = true; 
  1313. elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'autocomplete' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) 
  1314. $autocomplete = true; 
  1315.  
  1316. $hierarchy = false; 
  1317.  
  1318. if ( 'data' == $context && !$autocomplete ) { 
  1319. if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && in_array( pods_var( self::$type . '_format_single', $options, 'dropdown' ), array( 'dropdown', 'radio' ) ) ) 
  1320. $hierarchy = true; 
  1321. elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) && in_array( pods_var( self::$type . '_format_multi', $options, 'checkbox' ), array( 'multiselect', 'checkbox' ) ) ) 
  1322. $hierarchy = true; 
  1323.  
  1324. if ( $hierarchy && $options[ 'table_info' ][ 'object_hierarchical' ] && !empty( $options[ 'table_info' ][ 'field_parent' ] ) ) 
  1325. $params[ 'select' ] .= ', ' . $options[ 'table_info' ][ 'field_parent_select' ]; 
  1326.  
  1327. if ( $autocomplete ) { 
  1328. if ( 0 == $limit ) { 
  1329. $limit = 30; 
  1330.  
  1331. $params[ 'limit' ] = apply_filters( 'pods_form_ui_field_pick_autocomplete_limit', $limit, $name, $value, $options, $pod, $id, $object_params ); 
  1332.  
  1333. if ( is_array( $value ) && $params[ 'limit' ] < count( $value ) ) { 
  1334. $params[ 'limit' ] = count( $value ); 
  1335.  
  1336. $params[ 'page' ] = $page; 
  1337.  
  1338. if ( 'admin_ajax_relationship' == $context ) { 
  1339. $lookup_where = array( 
  1340. $search_data->field_index => "`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'" 
  1341. ); 
  1342.  
  1343. // @todo Hook into WPML for each table 
  1344. if ( $wpdb->users == $search_data->table ) { 
  1345. $lookup_where[ 'display_name' ] = "`t`.`display_name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1346. $lookup_where[ 'user_login' ] = "`t`.`user_login` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1347. $lookup_where[ 'user_email' ] = "`t`.`user_email` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1348. elseif ( $wpdb->posts == $search_data->table ) { 
  1349. $lookup_where[ 'post_title' ] = "`t`.`post_title` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1350. $lookup_where[ 'post_name' ] = "`t`.`post_name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1351. $lookup_where[ 'post_content' ] = "`t`.`post_content` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1352. $lookup_where[ 'post_excerpt' ] = "`t`.`post_excerpt` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1353. elseif ( $wpdb->terms == $search_data->table ) { 
  1354. $lookup_where[ 'name' ] = "`t`.`name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1355. $lookup_where[ 'slug' ] = "`t`.`slug` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1356. elseif ( $wpdb->comments == $search_data->table ) { 
  1357. $lookup_where[ 'comment_content' ] = "`t`.`comment_content` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1358. $lookup_where[ 'comment_author' ] = "`t`.`comment_author` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1359. $lookup_where[ 'comment_author_email' ] = "`t`.`comment_author_email` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; 
  1360.  
  1361. $lookup_where = apply_filters( 'pods_form_ui_field_pick_autocomplete_lookup', $lookup_where, $data_params[ 'query' ], $name, $value, $options, $pod, $id, $object_params, $search_data ); 
  1362.  
  1363. if ( !empty( $lookup_where ) ) 
  1364. $params[ 'where' ][] = implode( ' OR ', $lookup_where ); 
  1365.  
  1366. $orderby = array(); 
  1367. $orderby[] = "(`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%' ) DESC"; 
  1368.  
  1369. $pick_orderby = pods_var_raw( self::$type . '_orderby', $options, null, null, true ); 
  1370.  
  1371. if ( 0 < strlen( $pick_orderby ) ) 
  1372. $orderby[] = $pick_orderby; 
  1373.  
  1374. $orderby[] = "`t`.`{$search_data->field_index}`"; 
  1375. $orderby[] = "`t`.`{$search_data->field_id}`"; 
  1376.  
  1377. $params[ 'orderby' ] = $orderby; 
  1378. elseif ( 0 < $limit ) { 
  1379. $params[ 'limit' ] = $limit; 
  1380. $params[ 'page' ] = $page; 
  1381.  
  1382. $extra = ''; 
  1383.  
  1384. if ( $wpdb->posts == $search_data->table ) 
  1385. $extra = ', `t`.`post_type`'; 
  1386. elseif ( $wpdb->terms == $search_data->table ) 
  1387. $extra = ', `tt`.`taxonomy`'; 
  1388. elseif ( $wpdb->comments == $search_data->table ) 
  1389. $extra = ', `t`.`comment_type`'; 
  1390.  
  1391. $params[ 'select' ] .= $extra; 
  1392.  
  1393. if ( 'user' == pods_var( self::$type . '_object', $options ) ) { 
  1394. $roles = pods_var( self::$type . '_user_role', $options ); 
  1395.  
  1396. if ( !empty( $roles ) ) { 
  1397. $where = array(); 
  1398.  
  1399. foreach ( (array) $roles as $role ) { 
  1400. if ( empty( $role ) || ( pods_clean_name( $role ) != $role && sanitize_title( $role ) != $role ) ) 
  1401. continue; 
  1402.  
  1403. $where[] = $wpdb->base_prefix . ( ( is_multisite() && !is_main_site() ) ? get_current_blog_id() . '_' : '' ) . 'capabilities.meta_value LIKE "%\"' . pods_sanitize_like( $role ) . '\"%"'; 
  1404.  
  1405. if ( !empty( $where ) ) { 
  1406. $params[ 'where' ][] = implode( ' OR ', $where ); 
  1407.  
  1408. $results = $search_data->select( $params ); 
  1409.  
  1410. if ( $autocomplete && $params[ 'limit' ] < $search_data->total_found() ) { 
  1411. if ( !empty( $value ) ) { 
  1412. $ids = $value; 
  1413.  
  1414. if ( is_array( $ids ) && isset( $ids[ 0 ] ) && is_array( $ids[ 0 ] ) ) { 
  1415. $ids = wp_list_pluck( $ids, $search_data->field_id ); 
  1416.  
  1417. if ( is_array( $ids ) ) 
  1418. $ids = implode( ', ', $ids ); 
  1419.  
  1420. if ( is_array( $params[ 'where' ] ) ) 
  1421. $params[ 'where' ] = implode( ' AND ', $params[ 'where' ] ); 
  1422. if ( !empty( $params[ 'where' ] ) ) 
  1423. $params[ 'where' ] .= ' AND '; 
  1424.  
  1425. $params[ 'where' ] .= "`t`.`{$search_data->field_id}` IN ( " . $ids . " )"; 
  1426.  
  1427. $results = $search_data->select( $params ); 
  1428. else 
  1429. $autocomplete = false; 
  1430.  
  1431. if ( 'data' == $context ) { 
  1432. self::$field_data = array( 
  1433. 'field' => $name,  
  1434. 'id' => $options[ 'id' ],  
  1435. 'autocomplete' => $autocomplete 
  1436. ); 
  1437.  
  1438. if ( $hierarchy && !$autocomplete && !empty( $results ) && $options[ 'table_info' ][ 'object_hierarchical' ] && !empty( $options[ 'table_info' ][ 'field_parent' ] ) ) { 
  1439. $args = array( 
  1440. 'id' => $options[ 'table_info' ][ 'field_id' ],  
  1441. 'index' => $options[ 'table_info' ][ 'field_index' ],  
  1442. 'parent' => $options[ 'table_info' ][ 'field_parent' ],  
  1443. ); 
  1444.  
  1445. $results = pods_hierarchical_select( $results, $args ); 
  1446.  
  1447. $ids = array(); 
  1448.  
  1449. if ( !empty( $results ) ) { 
  1450. $display_filter = pods_var( 'display_filter', pods_var_raw( 'options', pods_var_raw( $search_data->field_index, $search_data->pod_data[ 'object_fields' ] ) ) ); 
  1451.  
  1452. foreach ( $results as $result ) { 
  1453. $result = get_object_vars( $result ); 
  1454.  
  1455. if ( !isset( $result[ $search_data->field_id ] ) || !isset( $result[ $search_data->field_index ] ) ) 
  1456. continue; 
  1457.  
  1458. $result[ $search_data->field_index ] = trim( $result[ $search_data->field_index ] ); 
  1459.  
  1460. $object = $object_type = ''; 
  1461.  
  1462. if ( $wpdb->posts == $search_data->table && isset( $result[ 'post_type' ] ) ) { 
  1463. $object = $result[ 'post_type' ]; 
  1464. $object_type = 'post_type'; 
  1465. elseif ( $wpdb->terms == $search_data->table && isset( $result[ 'taxonomy' ] ) ) { 
  1466. $object = $result[ 'taxonomy' ]; 
  1467. $object_type = 'taxonomy'; 
  1468.  
  1469. // WPML integration for Post Types and Taxonomies 
  1470. if ( is_object( $sitepress ) && in_array( $object_type, array( 'post_type', 'taxonomy' ) ) ) { 
  1471. $translated = false; 
  1472.  
  1473. if ( 'post_type' == $object_type && $sitepress->is_translated_post_type( $object ) ) 
  1474. $translated = true; 
  1475. elseif ( 'taxonomy' == $object_type && $sitepress->is_translated_taxonomy( $object ) ) 
  1476. $translated = true; 
  1477.  
  1478. if ( $translated ) { 
  1479. $object_id = icl_object_id( $result[ $search_data->field_id ], $object, false, $current_language ); 
  1480.  
  1481. if ( 0 < $object_id && !in_array( $object_id, $ids ) ) { 
  1482. $text = $result[ $search_data->field_index ]; 
  1483.  
  1484. if ( $result[ $search_data->field_id ] != $object_id ) { 
  1485. if ( $wpdb->posts == $search_data->table ) 
  1486. $text = trim( get_the_title( $object_id ) ); 
  1487. elseif ( $wpdb->terms == $search_data->table ) 
  1488. $text = trim( get_term( $object_id, $object )->name ); 
  1489.  
  1490. $result[ $search_data->field_id ] = $object_id; 
  1491. $result[ $search_data->field_index ] = $text; 
  1492. else 
  1493. continue; 
  1494. // Polylang integration for Post Types and Taxonomies 
  1495. elseif ( is_object( $polylang ) && in_array( $object_type, array( 'post_type', 'taxonomy' ) ) && method_exists( $polylang, 'get_translation' ) ) { 
  1496. $translated = false; 
  1497.  
  1498. if ( 'post_type' == $object_type && pll_is_translated_post_type( $object ) ) 
  1499. $translated = true; 
  1500. elseif ( 'taxonomy' == $object_type && pll_is_translated_taxonomy( $object ) ) 
  1501. $translated = true; 
  1502.  
  1503. if ( $translated ) { 
  1504. $object_id = $polylang->get_translation( $object, $result[ $search_data->field_id ], $current_language ); 
  1505.  
  1506. if ( 0 < $object_id && !in_array( $object_id, $ids ) ) { 
  1507. $text = $result[ $search_data->field_index ]; 
  1508.  
  1509. if ( $result[ $search_data->field_id ] != $object_id ) { 
  1510. if ( $wpdb->posts == $search_data->table ) 
  1511. $text = trim( get_the_title( $object_id ) ); 
  1512. elseif ( $wpdb->terms == $search_data->table ) 
  1513. $text = trim( get_term( $object_id, $object )->name ); 
  1514.  
  1515. $result[ $search_data->field_id ] = $object_id; 
  1516. $result[ $search_data->field_index ] = $text; 
  1517. else 
  1518. continue; 
  1519.  
  1520. if ( 0 < strlen( $display_filter ) ) { 
  1521. $display_filter_args = pods_var( 'display_filter_args', pods_var_raw( 'options', pods_var_raw( $search_data->field_index, $search_data->pod_data[ 'object_fields' ] ) ) ); 
  1522.  
  1523. $args = array( 
  1524. $display_filter,  
  1525. $result[ $search_data->field_index ] 
  1526. ); 
  1527.  
  1528. if ( !empty( $display_filter_args ) ) { 
  1529. foreach ( (array) $display_filter_args as $display_filter_arg ) { 
  1530. if ( isset( $result[ $display_filter_arg ] ) ) 
  1531. $args[] = $result[ $display_filter_arg ]; 
  1532.  
  1533. $result[ $search_data->field_index ] = call_user_func_array( 'apply_filters', $args ); 
  1534.  
  1535. if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ) ) ) 
  1536. $result[ $search_data->field_index ] = $result[ $search_data->field_index ] . $result[ 'path' ]; 
  1537. elseif ( strlen( $result[ $search_data->field_index ] ) < 1 ) 
  1538. $result[ $search_data->field_index ] = '(No Title)'; 
  1539.  
  1540. if ( 'admin_ajax_relationship' == $context ) { 
  1541. $items[] = array( 
  1542. 'id' => $result[ $search_data->field_id ],  
  1543. 'text' => $result[ $search_data->field_index ],  
  1544. 'image' => '' 
  1545. ); 
  1546. else 
  1547. $data[ $result[ $search_data->field_id ] ] = $result[ $search_data->field_index ]; 
  1548.  
  1549. $ids[] = $result[ $search_data->field_id ]; 
  1550.  
  1551. if ( $simple && 'admin_ajax_relationship' == $context ) { 
  1552. $found_data = array(); 
  1553.  
  1554. foreach ( $data as $k => $v ) { 
  1555. if ( false !== stripos( $v, $data_params[ 'query' ] ) || false !== stripos( $k, $data_params[ 'query' ] ) ) { 
  1556. $found_data[ $k ] = $v; 
  1557.  
  1558. $data = $found_data; 
  1559.  
  1560. if ( 'admin_ajax_relationship' == $context ) { 
  1561. if ( empty( $items ) && !empty( $data ) ) { 
  1562. foreach ( $data as $k => $v ) { 
  1563. $items[] = array( 
  1564. 'id' => $k,  
  1565. 'text' => $v,  
  1566. 'image' => '' 
  1567. ); 
  1568.  
  1569. return $items; 
  1570.  
  1571. return $data; 
  1572.  
  1573. /** 
  1574. * Handle autocomplete AJAX 
  1575. * @since 2.3 
  1576. */ 
  1577. public function admin_ajax_relationship () { 
  1578. pods_session_start(); 
  1579.  
  1580. // Sanitize input 
  1581. $params = pods_unslash( (array) $_POST ); 
  1582.  
  1583. foreach ( $params as $key => $value ) { 
  1584. if ( 'action' == $key ) 
  1585. continue; 
  1586.  
  1587. unset( $params[ $key ] ); 
  1588.  
  1589. $params[ str_replace( '_podsfix_', '', $key ) ] = $value; 
  1590.  
  1591. $params = (object) $params; 
  1592.  
  1593. $uid = @session_id(); 
  1594.  
  1595. if ( is_user_logged_in() ) 
  1596. $uid = 'user_' . get_current_user_id(); 
  1597.  
  1598. $nonce_check = 'pods_relationship_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field; 
  1599.  
  1600. if ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, $nonce_check ) ) 
  1601. pods_error( __( 'Unauthorized request', 'pods' ), PodsInit::$admin ); 
  1602.  
  1603. $api = pods_api(); 
  1604.  
  1605. $pod = $api->load_pod( array( 'id' => (int) $params->pod ) ); 
  1606. $field = $api->load_field( array( 'id' => (int) $params->field, 'table_info' => true ) ); 
  1607. $id = (int) $params->id; 
  1608.  
  1609. $limit = 15; 
  1610.  
  1611. if ( isset( $params->limit ) ) 
  1612. $limit = (int) $params->limit; 
  1613.  
  1614. $page = 1; 
  1615.  
  1616. if ( isset( $params->page ) ) 
  1617. $page = (int) $params->page; 
  1618.  
  1619. if ( !isset( $params->query ) || strlen( trim( $params->query ) ) < 1 ) 
  1620. pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin ); 
  1621. elseif ( empty( $pod ) || empty( $field ) || $pod[ 'id' ] != $field[ 'pod_id' ] || !isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) ) 
  1622. pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin ); 
  1623. elseif ( 'pick' != $field[ 'type' ] || empty( $field[ 'table_info' ] ) ) 
  1624. pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin ); 
  1625. elseif ( 'single' == pods_var( self::$type . '_format_type', $field ) && 'autocomplete' == pods_var( self::$type . '_format_single', $field ) ) 
  1626. pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin ); 
  1627. elseif ( 'multi' == pods_var( self::$type . '_format_type', $field ) && 'autocomplete' == pods_var( self::$type . '_format_multi', $field ) ) 
  1628. pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin ); 
  1629.  
  1630. $object_params = array( 
  1631. 'name' => $field[ 'name' ], // The name of the field 
  1632. 'value' => null, // The value of the field 
  1633. 'options' => array_merge( $field, $field[ 'options' ] ), // Field options 
  1634. 'pod' => $pod, // Pod data 
  1635. 'id' => $id, // Item ID 
  1636. 'context' => 'admin_ajax_relationship', // Data context 
  1637. 'data_params' => $params,  
  1638. 'page' => $page,  
  1639. 'limit' => $limit 
  1640. ); 
  1641.  
  1642. $pick_data = apply_filters( 'pods_field_pick_data_ajax', null, $field[ 'name' ], null, $field, $pod, $id ); 
  1643.  
  1644. if ( null !== $pick_data ) 
  1645. $items = $pick_data; 
  1646. else 
  1647. $items = $this->get_object_data( $object_params ); 
  1648.  
  1649. if ( !empty( $items ) && isset( $items[ 0 ] ) && !is_array( $items[ 0 ] ) ) { 
  1650. $new_items = array(); 
  1651.  
  1652. foreach ( $items as $id => $text ) { 
  1653. $new_items[] = array( 
  1654. 'id' => $id,  
  1655. 'text' => $text,  
  1656. 'image' => '' 
  1657. ); 
  1658.  
  1659. $items = $new_items; 
  1660.  
  1661. $items = apply_filters( 'pods_field_pick_data_ajax_items', $items, $field[ 'name' ], null, $field, $pod, $id ); 
  1662.  
  1663. $items = array( 
  1664. 'results' => $items 
  1665. ); 
  1666.  
  1667. wp_send_json( $items ); 
  1668.  
  1669. die(); // KBAI! 
  1670.  
  1671. /** 
  1672. * Data callback for Post Stati 
  1673. * @param string $name The name of the field 
  1674. * @param string|array $value The value of the field 
  1675. * @param array $options Field options 
  1676. * @param array $pod Pod data 
  1677. * @param int $id Item ID 
  1678. * @return array 
  1679. * @since 2.3 
  1680. */ 
  1681. public function data_post_stati ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  1682. $data = array(); 
  1683.  
  1684. $post_stati = get_post_stati( array(), 'objects' ); 
  1685.  
  1686. foreach ( $post_stati as $post_status ) { 
  1687. $data[ $post_status->name ] = $post_status->label; 
  1688.  
  1689. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  1690.  
  1691. /** 
  1692. * Data callback for User Roles 
  1693. * @param string $name The name of the field 
  1694. * @param string|array $value The value of the field 
  1695. * @param array $options Field options 
  1696. * @param array $pod Pod data 
  1697. * @param int $id Item ID 
  1698. * @return array 
  1699. * @since 2.3 
  1700. */ 
  1701. public function data_roles ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  1702. $data = array(); 
  1703.  
  1704. global $wp_roles; 
  1705.  
  1706. foreach ( $wp_roles->role_objects as $key => $role ) { 
  1707. $data[ $key ] = $wp_roles->role_names[ $key ]; 
  1708.  
  1709. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  1710.  
  1711. /** 
  1712. * Data callback for User Capabilities 
  1713. * @param string $name The name of the field 
  1714. * @param string|array $value The value of the field 
  1715. * @param array $options Field options 
  1716. * @param array $pod Pod data 
  1717. * @param int $id Item ID 
  1718. * @return array 
  1719. * @since 2.3 
  1720. */ 
  1721. public function data_capabilities ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  1722. $data = array(); 
  1723.  
  1724. global $wp_roles; 
  1725.  
  1726. $default_caps = array( 
  1727. 'activate_plugins',  
  1728. 'add_users',  
  1729. 'create_users',  
  1730. 'delete_others_pages',  
  1731. 'delete_others_posts',  
  1732. 'delete_pages',  
  1733. 'delete_plugins',  
  1734. 'delete_posts',  
  1735. 'delete_private_pages',  
  1736. 'delete_private_posts',  
  1737. 'delete_published_pages',  
  1738. 'delete_published_posts',  
  1739. 'delete_users',  
  1740. 'edit_dashboard',  
  1741. 'edit_files',  
  1742. 'edit_others_pages',  
  1743. 'edit_others_posts',  
  1744. 'edit_pages',  
  1745. 'edit_plugins',  
  1746. 'edit_posts',  
  1747. 'edit_private_pages',  
  1748. 'edit_private_posts',  
  1749. 'edit_published_pages',  
  1750. 'edit_published_posts',  
  1751. 'edit_theme_options',  
  1752. 'edit_themes',  
  1753. 'edit_users',  
  1754. 'import',  
  1755. 'install_plugins',  
  1756. 'install_themes',  
  1757. 'list_users',  
  1758. 'manage_categories',  
  1759. 'manage_links',  
  1760. 'manage_options',  
  1761. 'moderate_comments',  
  1762. 'promote_users',  
  1763. 'publish_pages',  
  1764. 'publish_posts',  
  1765. 'read',  
  1766. 'read_private_pages',  
  1767. 'read_private_posts',  
  1768. 'remove_users',  
  1769. 'switch_themes',  
  1770. 'unfiltered_html',  
  1771. 'unfiltered_upload',  
  1772. 'update_core',  
  1773. 'update_plugins',  
  1774. 'update_themes',  
  1775. 'upload_files' 
  1776. ); 
  1777.  
  1778. $role_caps = array(); 
  1779.  
  1780. foreach ( $wp_roles->role_objects as $key => $role ) { 
  1781. if ( is_array( $role->capabilities ) ) { 
  1782. foreach ( $role->capabilities as $cap => $grant ) { 
  1783. $role_caps[ $cap ] = $cap; 
  1784.  
  1785. $role_caps = array_unique( $role_caps ); 
  1786.  
  1787. $capabilities = array_merge( $default_caps, $role_caps ); 
  1788.  
  1789. // To support Members filters 
  1790. $capabilities = apply_filters( 'members_get_capabilities', $capabilities ); 
  1791.  
  1792. $capabilities = apply_filters( 'pods_roles_get_capabilities', $capabilities ); 
  1793.  
  1794. sort( $capabilities ); 
  1795.  
  1796. $capabilities = array_unique( $capabilities ); 
  1797.  
  1798. global $wp_roles; 
  1799.  
  1800. foreach ( $capabilities as $capability ) { 
  1801. $data[ $capability ] = $capability; 
  1802.  
  1803. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  1804.  
  1805. /** 
  1806. * Data callback for Image Sizes 
  1807. * @param string $name The name of the field 
  1808. * @param string|array $value The value of the field 
  1809. * @param array $options Field options 
  1810. * @param array $pod Pod data 
  1811. * @param int $id Item ID 
  1812. * @return array 
  1813. * @since 2.3 
  1814. */ 
  1815. public function data_image_sizes ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  1816. $data = array(); 
  1817.  
  1818. $image_sizes = get_intermediate_image_sizes(); 
  1819.  
  1820. foreach ( $image_sizes as $image_size ) { 
  1821. $data[ $image_size ] = ucwords( str_replace( '-', ' ', $image_size ) ); 
  1822.  
  1823. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  1824.  
  1825. /** 
  1826. * Data callback for Countries 
  1827. * @param string $name The name of the field 
  1828. * @param string|array $value The value of the field 
  1829. * @param array $options Field options 
  1830. * @param array $pod Pod data 
  1831. * @param int $id Item ID 
  1832. * @return array 
  1833. * @since 2.3 
  1834. */ 
  1835. public function data_countries ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  1836. $data = array( 
  1837. 'AF' => __( 'Afghanistan' ),  
  1838. 'AL' => __( 'Albania' ),  
  1839. 'DZ' => __( 'Algeria' ),  
  1840. 'AS' => __( 'American Samoa' ),  
  1841. 'AD' => __( 'Andorra' ),  
  1842. 'AO' => __( 'Angola' ),  
  1843. 'AI' => __( 'Anguilla' ),  
  1844. 'AQ' => __( 'Antarctica' ),  
  1845. 'AG' => __( 'Antigua and Barbuda' ),  
  1846. 'AR' => __( 'Argentina' ),  
  1847. 'AM' => __( 'Armenia' ),  
  1848. 'AW' => __( 'Aruba' ),  
  1849. 'AU' => __( 'Australia' ),  
  1850. 'AT' => __( 'Austria' ),  
  1851. 'AZ' => __( 'Azerbaijan' ),  
  1852. 'BS' => __( 'Bahamas' ),  
  1853. 'BH' => __( 'Bahrain' ),  
  1854. 'BD' => __( 'Bangladesh' ),  
  1855. 'BB' => __( 'Barbados' ),  
  1856. 'BY' => __( 'Belarus' ),  
  1857. 'BE' => __( 'Belgium' ),  
  1858. 'BZ' => __( 'Belize' ),  
  1859. 'BJ' => __( 'Benin' ),  
  1860. 'BM' => __( 'Bermuda' ),  
  1861. 'BT' => __( 'Bhutan' ),  
  1862. 'BO' => __( 'Bolivia' ),  
  1863. 'BA' => __( 'Bosnia and Herzegovina' ),  
  1864. 'BW' => __( 'Botswana' ),  
  1865. 'BV' => __( 'Bouvet Island' ),  
  1866. 'BR' => __( 'Brazil' ),  
  1867. 'BQ' => __( 'British Antarctic Territory' ),  
  1868. 'IO' => __( 'British Indian Ocean Territory' ),  
  1869. 'VG' => __( 'British Virgin Islands' ),  
  1870. 'BN' => __( 'Brunei' ),  
  1871. 'BG' => __( 'Bulgaria' ),  
  1872. 'BF' => __( 'Burkina Faso' ),  
  1873. 'BI' => __( 'Burundi' ),  
  1874. 'KH' => __( 'Cambodia' ),  
  1875. 'CM' => __( 'Cameroon' ),  
  1876. 'CA' => __( 'Canada' ),  
  1877. 'CT' => __( 'Canton and Enderbury Islands' ),  
  1878. 'CV' => __( 'Cape Verde' ),  
  1879. 'KY' => __( 'Cayman Islands' ),  
  1880. 'CF' => __( 'Central African Republic' ),  
  1881. 'TD' => __( 'Chad' ),  
  1882. 'CL' => __( 'Chile' ),  
  1883. 'CN' => __( 'China' ),  
  1884. 'CX' => __( 'Christmas Island' ),  
  1885. 'CC' => __( 'Cocos [Keeling] Islands' ),  
  1886. 'CO' => __( 'Colombia' ),  
  1887. 'KM' => __( 'Comoros' ),  
  1888. 'CG' => __( 'Congo - Brazzaville' ),  
  1889. 'CD' => __( 'Congo - Kinshasa' ),  
  1890. 'CK' => __( 'Cook Islands' ),  
  1891. 'CR' => __( 'Costa Rica' ),  
  1892. 'HR' => __( 'Croatia' ),  
  1893. 'CU' => __( 'Cuba' ),  
  1894. 'CY' => __( 'Cyprus' ),  
  1895. 'CZ' => __( 'Czech Republic' ),  
  1896. 'CI' => __( 'Cte d*Ivoire' ),  
  1897. 'DK' => __( 'Denmark' ),  
  1898. 'DJ' => __( 'Djibouti' ),  
  1899. 'DM' => __( 'Dominica' ),  
  1900. 'DO' => __( 'Dominican Republic' ),  
  1901. 'NQ' => __( 'Dronning Maud Land' ),  
  1902. 'DD' => __( 'East Germany' ),  
  1903. 'EC' => __( 'Ecuador' ),  
  1904. 'EG' => __( 'Egypt' ),  
  1905. 'SV' => __( 'El Salvador' ),  
  1906. 'GQ' => __( 'Equatorial Guinea' ),  
  1907. 'ER' => __( 'Eritrea' ),  
  1908. 'EE' => __( 'Estonia' ),  
  1909. 'ET' => __( 'Ethiopia' ),  
  1910. 'FK' => __( 'Falkland Islands' ),  
  1911. 'FO' => __( 'Faroe Islands' ),  
  1912. 'FJ' => __( 'Fiji' ),  
  1913. 'FI' => __( 'Finland' ),  
  1914. 'FR' => __( 'France' ),  
  1915. 'GF' => __( 'French Guiana' ),  
  1916. 'PF' => __( 'French Polynesia' ),  
  1917. 'TF' => __( 'French Southern Territories' ),  
  1918. 'FQ' => __( 'French Southern and Antarctic Territories' ),  
  1919. 'GA' => __( 'Gabon' ),  
  1920. 'GM' => __( 'Gambia' ),  
  1921. 'GE' => __( 'Georgia' ),  
  1922. 'DE' => __( 'Germany' ),  
  1923. 'GH' => __( 'Ghana' ),  
  1924. 'GI' => __( 'Gibraltar' ),  
  1925. 'GR' => __( 'Greece' ),  
  1926. 'GL' => __( 'Greenland' ),  
  1927. 'GD' => __( 'Grenada' ),  
  1928. 'GP' => __( 'Guadeloupe' ),  
  1929. 'GU' => __( 'Guam' ),  
  1930. 'GT' => __( 'Guatemala' ),  
  1931. 'GG' => __( 'Guernsey' ),  
  1932. 'GN' => __( 'Guinea' ),  
  1933. 'GW' => __( 'Guinea-Bissau' ),  
  1934. 'GY' => __( 'Guyana' ),  
  1935. 'HT' => __( 'Haiti' ),  
  1936. 'HM' => __( 'Heard Island and McDonald Islands' ),  
  1937. 'HN' => __( 'Honduras' ),  
  1938. 'HK' => __( 'Hong Kong SAR China' ),  
  1939. 'HU' => __( 'Hungary' ),  
  1940. 'IS' => __( 'Iceland' ),  
  1941. 'IN' => __( 'India' ),  
  1942. 'ID' => __( 'Indonesia' ),  
  1943. 'IR' => __( 'Iran' ),  
  1944. 'IQ' => __( 'Iraq' ),  
  1945. 'IE' => __( 'Ireland' ),  
  1946. 'IM' => __( 'Isle of Man' ),  
  1947. 'IL' => __( 'Israel' ),  
  1948. 'IT' => __( 'Italy' ),  
  1949. 'JM' => __( 'Jamaica' ),  
  1950. 'JP' => __( 'Japan' ),  
  1951. 'JE' => __( 'Jersey' ),  
  1952. 'JT' => __( 'Johnston Island' ),  
  1953. 'JO' => __( 'Jordan' ),  
  1954. 'KZ' => __( 'Kazakhstan' ),  
  1955. 'KE' => __( 'Kenya' ),  
  1956. 'KI' => __( 'Kiribati' ),  
  1957. 'KW' => __( 'Kuwait' ),  
  1958. 'KG' => __( 'Kyrgyzstan' ),  
  1959. 'LA' => __( 'Laos' ),  
  1960. 'LV' => __( 'Latvia' ),  
  1961. 'LB' => __( 'Lebanon' ),  
  1962. 'LS' => __( 'Lesotho' ),  
  1963. 'LR' => __( 'Liberia' ),  
  1964. 'LY' => __( 'Libya' ),  
  1965. 'LI' => __( 'Liechtenstein' ),  
  1966. 'LT' => __( 'Lithuania' ),  
  1967. 'LU' => __( 'Luxembourg' ),  
  1968. 'MO' => __( 'Macau SAR China' ),  
  1969. 'MK' => __( 'Macedonia' ),  
  1970. 'MG' => __( 'Madagascar' ),  
  1971. 'MW' => __( 'Malawi' ),  
  1972. 'MY' => __( 'Malaysia' ),  
  1973. 'MV' => __( 'Maldives' ),  
  1974. 'ML' => __( 'Mali' ),  
  1975. 'MT' => __( 'Malta' ),  
  1976. 'MH' => __( 'Marshall Islands' ),  
  1977. 'MQ' => __( 'Martinique' ),  
  1978. 'MR' => __( 'Mauritania' ),  
  1979. 'MU' => __( 'Mauritius' ),  
  1980. 'YT' => __( 'Mayotte' ),  
  1981. 'FX' => __( 'Metropolitan France' ),  
  1982. 'MX' => __( 'Mexico' ),  
  1983. 'FM' => __( 'Micronesia' ),  
  1984. 'MI' => __( 'Midway Islands' ),  
  1985. 'MD' => __( 'Moldova' ),  
  1986. 'MC' => __( 'Monaco' ),  
  1987. 'MN' => __( 'Mongolia' ),  
  1988. 'ME' => __( 'Montenegro' ),  
  1989. 'MS' => __( 'Montserrat' ),  
  1990. 'MA' => __( 'Morocco' ),  
  1991. 'MZ' => __( 'Mozambique' ),  
  1992. 'MM' => __( 'Myanmar [Burma]' ),  
  1993. 'NA' => __( 'Namibia' ),  
  1994. 'NR' => __( 'Nauru' ),  
  1995. 'NP' => __( 'Nepal' ),  
  1996. 'NL' => __( 'Netherlands' ),  
  1997. 'AN' => __( 'Netherlands Antilles' ),  
  1998. 'NT' => __( 'Neutral Zone' ),  
  1999. 'NC' => __( 'New Caledonia' ),  
  2000. 'NZ' => __( 'New Zealand' ),  
  2001. 'NI' => __( 'Nicaragua' ),  
  2002. 'NE' => __( 'Niger' ),  
  2003. 'NG' => __( 'Nigeria' ),  
  2004. 'NU' => __( 'Niue' ),  
  2005. 'NF' => __( 'Norfolk Island' ),  
  2006. 'KP' => __( 'North Korea' ),  
  2007. 'VD' => __( 'North Vietnam' ),  
  2008. 'MP' => __( 'Northern Mariana Islands' ),  
  2009. 'NO' => __( 'Norway' ),  
  2010. 'OM' => __( 'Oman' ),  
  2011. 'PC' => __( 'Pacific Islands Trust Territory' ),  
  2012. 'PK' => __( 'Pakistan' ),  
  2013. 'PW' => __( 'Palau' ),  
  2014. 'PS' => __( 'Palestinian Territories' ),  
  2015. 'PA' => __( 'Panama' ),  
  2016. 'PZ' => __( 'Panama Canal Zone' ),  
  2017. 'PG' => __( 'Papua New Guinea' ),  
  2018. 'PY' => __( 'Paraguay' ),  
  2019. 'YD' => __( "People's Democratic Republic of Yemen" ),  
  2020. 'PE' => __( 'Peru' ),  
  2021. 'PH' => __( 'Philippines' ),  
  2022. 'PN' => __( 'Pitcairn Islands' ),  
  2023. 'PL' => __( 'Poland' ),  
  2024. 'PT' => __( 'Portugal' ),  
  2025. 'PR' => __( 'Puerto Rico' ),  
  2026. 'QA' => __( 'Qatar' ),  
  2027. 'RO' => __( 'Romania' ),  
  2028. 'RU' => __( 'Russia' ),  
  2029. 'RW' => __( 'Rwanda' ),  
  2030. 'RE' => __( 'Runion' ),  
  2031. 'BL' => __( 'Saint Barthlemy' ),  
  2032. 'SH' => __( 'Saint Helena' ),  
  2033. 'KN' => __( 'Saint Kitts and Nevis' ),  
  2034. 'LC' => __( 'Saint Lucia' ),  
  2035. 'MF' => __( 'Saint Martin' ),  
  2036. 'PM' => __( 'Saint Pierre and Miquelon' ),  
  2037. 'VC' => __( 'Saint Vincent and the Grenadines' ),  
  2038. 'WS' => __( 'Samoa' ),  
  2039. 'SM' => __( 'San Marino' ),  
  2040. 'SA' => __( 'Saudi Arabia' ),  
  2041. 'SN' => __( 'Senegal' ),  
  2042. 'RS' => __( 'Serbia' ),  
  2043. 'CS' => __( 'Serbia and Montenegro' ),  
  2044. 'SC' => __( 'Seychelles' ),  
  2045. 'SL' => __( 'Sierra Leone' ),  
  2046. 'SG' => __( 'Singapore' ),  
  2047. 'SK' => __( 'Slovakia' ),  
  2048. 'SI' => __( 'Slovenia' ),  
  2049. 'SB' => __( 'Solomon Islands' ),  
  2050. 'SO' => __( 'Somalia' ),  
  2051. 'ZA' => __( 'South Africa' ),  
  2052. 'GS' => __( 'South Georgia and the South Sandwich Islands' ),  
  2053. 'KR' => __( 'South Korea' ),  
  2054. 'ES' => __( 'Spain' ),  
  2055. 'LK' => __( 'Sri Lanka' ),  
  2056. 'SD' => __( 'Sudan' ),  
  2057. 'SR' => __( 'Suriname' ),  
  2058. 'SJ' => __( 'Svalbard and Jan Mayen' ),  
  2059. 'SZ' => __( 'Swaziland' ),  
  2060. 'SE' => __( 'Sweden' ),  
  2061. 'CH' => __( 'Switzerland' ),  
  2062. 'SY' => __( 'Syria' ),  
  2063. 'ST' => __( 'So Tom and Prncipe' ),  
  2064. 'TW' => __( 'Taiwan' ),  
  2065. 'TJ' => __( 'Tajikistan' ),  
  2066. 'TZ' => __( 'Tanzania' ),  
  2067. 'TH' => __( 'Thailand' ),  
  2068. 'TL' => __( 'Timor-Leste' ),  
  2069. 'TG' => __( 'Togo' ),  
  2070. 'TK' => __( 'Tokelau' ),  
  2071. 'TO' => __( 'Tonga' ),  
  2072. 'TT' => __( 'Trinidad and Tobago' ),  
  2073. 'TN' => __( 'Tunisia' ),  
  2074. 'TR' => __( 'Turkey' ),  
  2075. 'TM' => __( 'Turkmenistan' ),  
  2076. 'TC' => __( 'Turks and Caicos Islands' ),  
  2077. 'TV' => __( 'Tuvalu' ),  
  2078. 'UM' => __( 'U.S. Minor Outlying Islands' ),  
  2079. 'PU' => __( 'U.S. Miscellaneous Pacific Islands' ),  
  2080. 'VI' => __( 'U.S. Virgin Islands' ),  
  2081. 'UG' => __( 'Uganda' ),  
  2082. 'UA' => __( 'Ukraine' ),  
  2083. 'SU' => __( 'Union of Soviet Socialist Republics' ),  
  2084. 'AE' => __( 'United Arab Emirates' ),  
  2085. 'GB' => __( 'United Kingdom' ),  
  2086. 'US' => __( 'United States' ),  
  2087. 'ZZ' => __( 'Unknown or Invalid Region' ),  
  2088. 'UY' => __( 'Uruguay' ),  
  2089. 'UZ' => __( 'Uzbekistan' ),  
  2090. 'VU' => __( 'Vanuatu' ),  
  2091. 'VA' => __( 'Vatican City' ),  
  2092. 'VE' => __( 'Venezuela' ),  
  2093. 'VN' => __( 'Vietnam' ),  
  2094. 'WK' => __( 'Wake Island' ),  
  2095. 'WF' => __( 'Wallis and Futuna' ),  
  2096. 'EH' => __( 'Western Sahara' ),  
  2097. 'YE' => __( 'Yemen' ),  
  2098. 'ZM' => __( 'Zambia' ),  
  2099. 'ZW' => __( 'Zimbabwe' ),  
  2100. 'AX' => __( 'land Islands' ) 
  2101. ); 
  2102.  
  2103. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  2104.  
  2105. /** 
  2106. * Data callback for US States 
  2107. * @param string $name The name of the field 
  2108. * @param string|array $value The value of the field 
  2109. * @param array $options Field options 
  2110. * @param array $pod Pod data 
  2111. * @param int $id Item ID 
  2112. * @return array 
  2113. * @since 2.3 
  2114. */ 
  2115. public function data_us_states ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  2116. $data = array( 
  2117. 'AL' => __( 'Alabama' ),  
  2118. 'AK' => __( 'Alaska' ),  
  2119. 'AZ' => __( 'Arizona' ),  
  2120. 'AR' => __( 'Arkansas' ),  
  2121. 'CA' => __( 'California' ),  
  2122. 'CO' => __( 'Colorado' ),  
  2123. 'CT' => __( 'Connecticut' ),  
  2124. 'DE' => __( 'Delaware' ),  
  2125. 'DC' => __( 'District Of Columbia' ),  
  2126. 'FL' => __( 'Florida' ),  
  2127. 'GA' => __( 'Georgia' ),  
  2128. 'HI' => __( 'Hawaii' ),  
  2129. 'ID' => __( 'Idaho' ),  
  2130. 'IL' => __( 'Illinois' ),  
  2131. 'IN' => __( 'Indiana' ),  
  2132. 'IA' => __( 'Iowa' ),  
  2133. 'KS' => __( 'Kansas' ),  
  2134. 'KY' => __( 'Kentucky' ),  
  2135. 'LA' => __( 'Louisiana' ),  
  2136. 'ME' => __( 'Maine' ),  
  2137. 'MD' => __( 'Maryland' ),  
  2138. 'MA' => __( 'Massachusetts' ),  
  2139. 'MI' => __( 'Michigan' ),  
  2140. 'MN' => __( 'Minnesota' ),  
  2141. 'MS' => __( 'Mississippi' ),  
  2142. 'MO' => __( 'Missouri' ),  
  2143. 'MT' => __( 'Montana' ),  
  2144. 'NE' => __( 'Nebraska' ),  
  2145. 'NV' => __( 'Nevada' ),  
  2146. 'NH' => __( 'New Hampshire' ),  
  2147. 'NJ' => __( 'New Jersey' ),  
  2148. 'NM' => __( 'New Mexico' ),  
  2149. 'NY' => __( 'New York' ),  
  2150. 'NC' => __( 'North Carolina' ),  
  2151. 'ND' => __( 'North Dakota' ),  
  2152. 'OH' => __( 'Ohio' ),  
  2153. 'OK' => __( 'Oklahoma' ),  
  2154. 'OR' => __( 'Oregon' ),  
  2155. 'PA' => __( 'Pennsylvania' ),  
  2156. 'RI' => __( 'Rhode Island' ),  
  2157. 'SC' => __( 'South Carolina' ),  
  2158. 'SD' => __( 'South Dakota' ),  
  2159. 'TN' => __( 'Tennessee' ),  
  2160. 'TX' => __( 'Texas' ),  
  2161. 'UT' => __( 'Utah' ),  
  2162. 'VT' => __( 'Vermont' ),  
  2163. 'VA' => __( 'Virginia' ),  
  2164. 'WA' => __( 'Washington' ),  
  2165. 'WV' => __( 'West Virginia' ),  
  2166. 'WI' => __( 'Wisconsin' ),  
  2167. 'WY' => __( 'Wyoming' ) 
  2168. ); 
  2169.  
  2170. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  2171.  
  2172. /** 
  2173. * Data callback for US States 
  2174. * @param string $name The name of the field 
  2175. * @param string|array $value The value of the field 
  2176. * @param array $options Field options 
  2177. * @param array $pod Pod data 
  2178. * @param int $id Item ID 
  2179. * @return array 
  2180. * @since 2.3 
  2181. */ 
  2182. public function data_days_of_week ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  2183.  
  2184. /** 
  2185. * @var WP_Locale 
  2186. */ 
  2187. global $wp_locale; 
  2188.  
  2189. return $wp_locale->weekday; 
  2190.  
  2191.  
  2192. /** 
  2193. * Data callback for US States 
  2194. * @param string $name The name of the field 
  2195. * @param string|array $value The value of the field 
  2196. * @param array $options Field options 
  2197. * @param array $pod Pod data 
  2198. * @param int $id Item ID 
  2199. * @return array 
  2200. * @since 2.3 
  2201. */ 
  2202. public function data_months_of_year ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  2203.  
  2204. /** 
  2205. * @var WP_Locale 
  2206. */ 
  2207. global $wp_locale; 
  2208.  
  2209. return $wp_locale->month; 
  2210.