GFPDFHelperHelper_Form

Class to set up the settings api fields.

Defined (1)

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

/src/helper/Helper_Form.php  
  1. class Helper_Form extends Helper_Abstract_Form { 
  2.  
  3. /** 
  4. * Get the form plugins current version 
  5. * @return string 
  6. * @since 4.0 
  7. */ 
  8. public function get_version() { 
  9. return GFCommon::$version; 
  10.  
  11. /** 
  12. * Get form plugin's path 
  13. * @return string 
  14. * @since 4.0 
  15. */ 
  16. public function get_plugin_path() { 
  17. return GFCommon::get_base_path(); 
  18.  
  19. /** 
  20. * Get form plugin's URL 
  21. * @return string 
  22. * @since 4.0 
  23. */ 
  24. public function get_plugin_url() { 
  25. return GFCommon::get_base_url(); 
  26.  
  27. /** 
  28. * Add's a new form and returns the newly-added form ID 
  29. * @param array $form The form object to add 
  30. * @since 4.0 
  31. * @return integer|object The ID if successful, or a WP_Error 
  32. */ 
  33. public function add_form( $form ) { 
  34. return GFAPI::add_form( $form ); 
  35.  
  36. /** 
  37. * Delete's a form by ID 
  38. * @param integer $form_id The form ID to remove 
  39. * @since 4.0 
  40. * @return boolean|\WP_Error 
  41. */ 
  42. public function delete_form( $form_id ) { 
  43. return GFAPI::delete_form( $form_id ); 
  44.  
  45. /** 
  46. * Get form plugin's form array 
  47. * The GFAPI has a performance problem when using GFAPI::get_form() and makes a database call each time to get the `is_active`, `date_created`, or `is_trash` data. 
  48. * We're bypassing the API to prevent that problem but the array doesn't include the aforementioned fields. Once the issue is resolved we'll look at switching back. 
  49. * @param integer $form_id 
  50. * @return mixed 
  51. * @since 4.0 
  52. */ 
  53. public function get_form( $form_id ) { 
  54. return GFFormsModel::get_form_meta( $form_id ); 
  55.  
  56. /** 
  57. * Get form plugin's current forms array 
  58. * @return mixed 
  59. * @since 4.0 
  60. */ 
  61. public function get_forms() { 
  62.  
  63. $form_ids = GFFormsModel::get_form_ids( true, false ); 
  64. if ( empty( $form_ids ) ) { 
  65. return []; 
  66.  
  67. $forms = []; 
  68. foreach ( $form_ids as $form_id ) { 
  69. $forms[] = GFFormsModel::get_form_meta( $form_id ); 
  70.  
  71. return $forms; 
  72.  
  73. /** 
  74. * Get form plugin's form array 
  75. * @param array|object $form The form object to be updated 
  76. * @return mixed 
  77. * @since 4.0 
  78. */ 
  79. public function update_form( $form ) { 
  80.  
  81. /** 
  82. * Because of the performance issues mentioned in the `get_form` method the `is_active`, `date_created` and `is_trash` keys are missing from `$form` 
  83. * We'll add them back in right before the update to prevent any issues with the form status 
  84. */ 
  85. $form_info = GFFormsModel::get_form( $form['id'], true ); 
  86. $form['is_active'] = $form_info->is_active; 
  87. $form['date_created'] = $form_info->date_created; 
  88. $form['is_trash'] = $form_info->is_trash; 
  89.  
  90. return GFAPI::update_form( $form ); 
  91.  
  92. /** 
  93. * Get the entry based on the ID 
  94. * @param integer $entry_id 
  95. * @return mixed 
  96. * @since 4.0 
  97. */ 
  98. public function get_entry( $entry_id ) { 
  99. return GFAPI::get_entry( $entry_id ); 
  100.  
  101. /** 
  102. * Get multiple entries from multiple forms based on search criteria 
  103. * @param integer|array $form_ids The ID's of the form or an array of ideas. 
  104. * @param array $search_criteria An array containing the search criteria 
  105. * @param array $sorting An array containing the sort criteria 
  106. * @param array $paging Use to limit the number of entries returned 
  107. * @return mixed 
  108. * @since 4.0 
  109. */ 
  110. public function get_entries( $form_ids, $search_criteria = [], $sorting = null, $paging = null ) { 
  111. return GFAPI::get_entries( $form_ids, $search_criteria, $sorting, $paging ); 
  112.  
  113. /** 
  114. * Update the current entry object 
  115. * @param array|object $entry The entry to be updated 
  116. * @return mixed 
  117. * @since 4.0 
  118. */ 
  119. public function update_entry( $entry ) { 
  120. return GFAPI::update_entry( $entry ); 
  121.  
  122. /** 
  123. * Get all custom form plugin capabilities added to WordPress, if any 
  124. * @return array 
  125. * @since 4.0 
  126. */ 
  127. public function get_capabilities() { 
  128. return GFCommon::all_caps(); 
  129.  
  130. /** 
  131. * Check if the user has the capability passed 
  132. * @param string|array $capability 
  133. * @param integer $user_id 
  134. * @return boolean True if successful, false if failed 
  135. * @since 4.0 
  136. */ 
  137. public function has_capability( $capability, $user_id = null ) { 
  138.  
  139. /** Override current user */ 
  140. if ( $user_id !== null ) { 
  141. $current_user = wp_get_current_user(); 
  142. wp_set_current_user( $user_id ); 
  143.  
  144. $has_capability = GFCommon::current_user_can_any( $capability ); 
  145.  
  146. /** Restore current user */ 
  147. if ( $user_id !== null ) { 
  148. wp_set_current_user( $current_user->ID ); 
  149.  
  150. return $has_capability; 
  151.  
  152. /** 
  153. * Replace all the Merge Tag data in the string 
  154. * @param string $string The string to process 
  155. * @param array $form The Gravity Form array 
  156. * @param array $entry The Gravity Form Entry Array 
  157. * @return string 
  158. * @since 4.0 
  159. */ 
  160. public function process_tags( $string, $form, $entry ) { 
  161.  
  162. $string = str_replace( '{all_fields}', '', $string ); 
  163.  
  164. return trim( GFCommon::replace_variables( $string, $form, $entry, false, false, false ) );