calderawpcfeddfieldsfieldspopulatequery

The Caldera Forms EDD calderawp cfeddfields fields populate query class.

Defined (1)

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

/vendor/calderawp/cf-edd-fields/src/fields/populate/query.php  
  1. class query { 
  2.  
  3. /** 
  4. * Add Hooks 
  5. * @since 0.0.2 
  6. */ 
  7. public function add_hooks() { 
  8. add_filter( 'caldera_forms_render_get_field', [ $this, 'populate_field' ], 11, 2 ); 
  9.  
  10. /** 
  11. * Remove Hooks 
  12. * @since 0.0.2 
  13. */ 
  14. public function remove_hooks() { 
  15. remove_filter( 'caldera_forms_render_get_field', [ $this, 'populate_field' ], 11 ); 
  16.  
  17.  
  18. /** 
  19. * Auto-populate fields 
  20. * @since 0.0.2 
  21. * @uses "caldera_forms_render_get_field" filter 
  22. * @param $field 
  23. * @param $form 
  24. * @return array 
  25. */ 
  26. public function populate_field( $field, $form ) { 
  27. if ( $this->is_field( $field ) ) { 
  28. $posts = $this->get_posts( $field, $form ); 
  29. if( ! empty( $posts ) ) { 
  30. foreach($posts as $post ) { 
  31. $field['config']['option'][$post->ID] = array( 
  32. 'value' => $post->ID,  
  33. 'label' => $post->post_title 
  34. ); 
  35.  
  36. $this->add_price( $field[ 'ID' ], $post->ID, $form[ 'ID' ] ); 
  37.  
  38.  
  39.  
  40.  
  41.  
  42. return $field; 
  43.  
  44.  
  45. /** 
  46. * Track a price 
  47. * @param string $field_id 
  48. * @param string|int $download_id 
  49. * @param string $form_id 
  50. */ 
  51. protected function add_price( $field_id, $download_id, $form_id ) {} 
  52.  
  53. /** 
  54. * Query for download posts 
  55. * @since 0.0.2 
  56. * @param $field 
  57. * @param $form 
  58. * @return array 
  59. */ 
  60. protected function get_posts( $field, $form ) { 
  61. /** 
  62. * Set arguments for EDD auto-populate field 
  63. * @since 0.0.2 
  64. * @param array $args WP_Query args to use 
  65. * @param array $field Config for the field. 
  66. * @param array $form Config for the form. 
  67. */ 
  68. $args = apply_filters( 'cf_edd_pro_autopopulate_options', [ 
  69. 'post_type' => 'download' 
  70. ], $field, $form ); 
  71. return get_posts( $args ); 
  72.  
  73.  
  74. /** 
  75. * Check if this class should affect a field 
  76. * @since 0.0.2 
  77. * @param array $field 
  78. * @return bool 
  79. */ 
  80. protected function is_field( $field ) { 
  81. return ( ! empty( $field[ 'config' ][ 'auto' ] ) && 'edd' == $field[ 'config' ][ 'auto_type' ] ); 
  82.  
  83.  
  84.