Guest User

Untitled

a guest
Jul 16th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: PDB Volunteer Dropdown
  4. * Description: load the registered volunteers into a Participants Database form
  5. * dropdown
  6. */
  7. /*
  8. * sets our function to be called when the pdb-form_element_build_dropdown action
  9. * is triggered by the form
  10. */
  11. add_action( 'pdb-form_element_build_dropdown', 'xnau_set_volunteer_dropdown_options');
  12. /**
  13. * sets the options for the volunteer dropdown
  14. *
  15. * @param PDb_FormElement object $field the current field
  16. */
  17. function xnau_set_volunteer_dropdown_options ( $field )
  18. {
  19. if ( $field->name === 'volunteers' ) : // check for our dropdown field
  20.  
  21. global $wpdb; // grab the db helper object
  22.  
  23. /*
  24. * define the query for getting the list of volunteer names
  25. *
  26. * note that the $wpdb->prefix method is used to get the table
  27. * prefix; this is so it will work on all WP installs
  28. */
  29. $query = '
  30. SELECT first_name,last_name
  31. FROM `' . $wpdb->prefix . 'participants_database`
  32. WHERE form_type LIKE "%volunteer%" AND form_type NOT LIKE "%coordinator%"
  33. ';
  34.  
  35. // now execute the query and get the results
  36. $raw_names = $wpdb->get_results( $query );
  37.  
  38. /*
  39. * now expand the result array into an array for the options property of the
  40. * dropdown
  41. */
  42. $options = array();
  43. foreach ( $raw_names as $record ) {
  44. $options[] = $record->first_name . ' ' . $record->last_name;
  45. }
  46.  
  47. // now set the field object with the new options list
  48. $field->options = $options;
  49.  
  50. endif;
  51. }
Add Comment
Please, Sign In to add comment