Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Get a list of Gravity Forms whose fields have a CSS class.
  5. *
  6. * @param string $css_class The CSS class to search for.
  7. *
  8. * @return array The list of forms in this format: [<form ID> - <form title>] => <array of fields that have CSS class>
  9. */
  10. function get_gravity_forms_with_css_class( $css_class ) {
  11. return array_reduce( GFAPI::get_forms(), function( $forms_with_css_class, $form ) use ( $css_class ) {
  12. $fields_with_class = get_gravity_form_fields_with_css_class( $form, $css_class );
  13.  
  14. if ( $fields_with_class ) {
  15. $forms_with_css_class[ "{$form['id']} - {$form['title']}" ] = $fields_with_class;
  16. }
  17.  
  18. return $forms_with_css_class;
  19. }, [] );
  20. }
  21.  
  22. /**
  23. * Get all fields in a Gravity Form that have a CSS class.
  24. *
  25. * @param array $form The Gravity Form data.
  26. * @param string $css_class The CSS class to search for.
  27. *
  28. * @return array Fields that have the CSS class or empty array if none.
  29. */
  30. function get_gravity_form_fields_with_css_class( $form, $css_class ) {
  31. return array_filter( $form['fields'], function( $field ) use ( $css_class ) {
  32. return in_array( $css_class, explode( ' ', $field->cssClass, true ) );
  33. } );
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement