user-info-fields.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /*
  3. *
  4. * Function that adds the address group dropdown to the user information field items.
  5. *
  6. * @since 2.2.37
  7. * @returns void
  8. */
  9. function ninja_forms_user_info_fields_groups( $field_id, $field_data ){
  10. global $ninja_forms_fields;
  11. $field = ninja_forms_get_field_by_id( $field_id );
  12. $field_type = $field['type'];
  13. $default_user_info = 0;
  14. if ( isset ( $ninja_forms_fields[$field_type]['edit_options'] ) and is_array( $ninja_forms_fields[$field_type]['edit_options'] ) ) {
  15. foreach ( $ninja_forms_fields[$field_type]['edit_options'] as $option ) {
  16. if ( isset ( $option['name'] ) and $option['name'] == 'user_info_field_group' and isset ( $option['default'] ) ) {
  17. $default_user_info = $option['default'];
  18. break;
  19. }
  20. }
  21. }
  22. if ( ( isset ( $field_data['user_info_field_group'] ) AND $field_data['user_info_field_group'] == 1 ) or ( ( !isset ( $field_data['user_info_field_group'] ) or $field_data['user_info_field_group'] !== 0 ) and $default_user_info == 1 ) ) {
  23. $options = array(
  24. array( 'name' => '- '.__( 'None', 'ninja-forms' ), 'value' => '' ),
  25. array( 'name' => __( 'Billing', 'ninja-forms' ), 'value' => 'billing' ),
  26. array( 'name' => __( 'Shipping', 'ninja-forms' ), 'value' => 'shipping' ),
  27. array( 'name' => __( 'Custom', 'ninja-forms' ).' ->', 'value' => 'custom' ),
  28. );
  29. if ( isset ( $field_data['user_info_field_group_name'] ) ) {
  30. $group_name = $field_data['user_info_field_group_name'];
  31. } else {
  32. $group_name = '';
  33. }
  34. if ( isset ( $field_data['user_info_field_group_custom'] ) ) {
  35. $group_custom = $field_data['user_info_field_group_custom'];
  36. } else {
  37. $group_custom = '';
  38. }
  39. if ( $group_name == 'custom' ) {
  40. $custom_class = '';
  41. } else {
  42. $custom_class = 'hidden';
  43. }
  44. ninja_forms_edit_field_el_output( $field_id, 'select', __( 'User Info Field Group', 'ninja-forms' ), 'user_info_field_group_name', $group_name, 'thin', $options, 'user-info-group-name widefat' );
  45. ninja_forms_edit_field_el_output( $field_id, 'text', __( 'Custom Field Group', 'ninja-forms' ), 'user_info_field_group_custom', $group_custom, 'thin', '', 'user-info-custom-group widefat '.$custom_class, '', $custom_class );
  46. }
  47. }
  48. add_action( 'ninja_forms_edit_field_after_registered', 'ninja_forms_user_info_fields_groups', 10, 2 );