ninja_forms_new_field

The Ninja Forms ninja forms new field function.

Description

ninja_forms_new_field(); 

Usage

  1. if ( !function_exists( 'ninja_forms_new_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/admin/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = ninja_forms_new_field(); 
  7.  

Defined (1)

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

/deprecated/includes/admin/ajax.php  
  1. function ninja_forms_new_field() { 
  2. global $wpdb, $ninja_forms_fields; 
  3.  
  4. // Bail if we aren't in the admin 
  5. if ( ! is_admin() ) 
  6. return false; 
  7.  
  8. // Bail if we don't have proper permissions 
  9. if ( ! current_user_can( apply_filters( 'nf_new_field_capabilities', 'manage_options' ) ) ) 
  10. return false; 
  11.  
  12. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  13.  
  14. $type = esc_html( $_REQUEST['type'] ); 
  15. $form_id = absint( $_REQUEST['form_id'] ); 
  16.  
  17. if( isset( $ninja_forms_fields[$type]['name'] ) ) { 
  18. $type_name = $ninja_forms_fields[$type]['name']; 
  19. }else{ 
  20. $type_name = ''; 
  21.  
  22. if( isset( $ninja_forms_fields[$type]['default_label'] ) ) { 
  23. $default_label = $ninja_forms_fields[$type]['default_label']; 
  24. }else{ 
  25. $default_label = ''; 
  26.  
  27. if( isset( $ninja_forms_fields[$type]['edit_options'] ) ) { 
  28. $edit_options = $ninja_forms_fields[$type]['edit_options']; 
  29. }else{ 
  30. $edit_options = ''; 
  31.  
  32. if ( $default_label != '' ) { 
  33. $label = $default_label; 
  34. } else { 
  35. $label = $type_name; 
  36.  
  37. $input_limit_msg = __( 'character(s) left', 'ninja-forms' ); 
  38.  
  39. $data = serialize( array( 'label' => $label, 'input_limit_msg' => $input_limit_msg ) ); 
  40.  
  41. $order = 999; 
  42.  
  43. if($form_id != 0 && $form_id != '') { 
  44. $args = array( 
  45. 'type' => $type,  
  46. 'data' => $data,  
  47. ); 
  48.  
  49. $new_id = ninja_forms_insert_field( $form_id, $args ); 
  50. $new_html = ninja_forms_return_echo('ninja_forms_edit_field', $new_id, true ); 
  51. header("Content-type: application/json"); 
  52. $array = array ('new_id' => $new_id, 'new_type' => $type_name, 'new_html' => $new_html, 'edit_options' => $edit_options, 'new_type_slug' => $type ); 
  53. echo json_encode($array); 
  54. die();