update-terms.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /*
  3. *
  4. * Function to hook into the post creation/update that will change the term based upon the selected term(s)
  5. *
  6. * @since 2.2.51
  7. * @return void
  8. */
  9. // Make sure that this function isn't already defined.
  10. if ( !function_exists ( 'ninja_forms_pre_process_populate_term' ) ) {
  11. function ninja_forms_pre_process_populate_term( $form_id ){
  12. global $ninja_forms_processing;
  13. $add_field = apply_filters( 'ninja_forms_use_post_fields', false );
  14. if ( !$add_field )
  15. return false;
  16. // Loop through our fields and see if we have a list field. If we do, check for the 'populate_term' setting.
  17. $field_values = $ninja_forms_processing->get_all_fields();
  18. if( is_array( $field_values ) ){
  19. foreach( $field_values as $field_id => $user_value ){
  20. $field_row = $ninja_forms_processing->get_field_settings( $field_id );
  21. $field_type = $field_row['type'];
  22. $field_data = $field_row['data'];
  23. if( $field_type == '_list' AND isset( $field_data['populate_term'] ) AND $field_data['populate_term'] != '' ){
  24. if( !is_array( $user_value ) ){
  25. $user_value = array( $user_value );
  26. }
  27. $ninja_forms_processing->update_form_setting( $field_data['populate_term'].'_terms', $user_value );
  28. }
  29. }
  30. }
  31. }
  32. add_action( 'ninja_forms_pre_process', 'ninja_forms_pre_process_populate_term' );
  33. }