ninja_forms_add_def

The Ninja Forms ninja forms add def function.

Description

ninja_forms_add_def(); 

Usage

  1. if ( !function_exists( 'ninja_forms_add_def' ) ) { 
  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_add_def(); 
  7.  

Defined (1)

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

/deprecated/includes/admin/ajax.php  
  1. function ninja_forms_add_def() { 
  2. global $wpdb; 
  3.  
  4. // Bail if we aren't in the admin 
  5. if ( ! is_admin() ) 
  6. return false; 
  7.  
  8. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  9.  
  10. $field_data = $_REQUEST['field_data']; 
  11. $field_id = absint( $_REQUEST['field_id'] ); 
  12.  
  13. $field_row = ninja_forms_get_field_by_id($field_id); 
  14.  
  15. $field_type = $field_row['type']; 
  16. $row_type = 0; 
  17.  
  18. $data = array(); 
  19.  
  20. foreach($field_data as $key => $val) { 
  21. $key = str_replace('"', '', $key); 
  22. if(strpos($key, '[')) { 
  23. $key = str_replace(']', '', $key); 
  24. $key = explode('[', $key); 
  25. $multi = array(); 
  26. $temp =& $multi; 
  27. $x = 0; 
  28. $count = count($key) - 1; 
  29. foreach ($key as $item) { 
  30. $temp[$item] = array(); 
  31. if($x < $count) { 
  32. $temp =& $temp[$item]; 
  33. }else{ 
  34. $temp[$item] = $val; 
  35. $x++; 
  36. $data = ninja_forms_array_merge_recursive($data, $multi); 
  37. }else{ 
  38. $data[$key] = $val; 
  39.  
  40. $name = stripslashes( esc_html( $_REQUEST['def_name'] ) ); 
  41. $data['label'] = $name; 
  42. $data = serialize($data); 
  43. $wpdb->insert(NINJA_FORMS_FAV_FIELDS_TABLE_NAME, array('row_type' => $row_type, 'type' => $field_type, 'data' => $data, 'name' => $name)); 
  44. $def_id = $wpdb->insert_id; 
  45. $update_array = array('def_id' => $def_id); 
  46. $wpdb->update( NINJA_FORMS_FIELDS_TABLE_NAME, $update_array, array( 'id' => $field_id )); 
  47.  
  48. $new_html = '<p class="button-controls" id="ninja_forms_insert_def_field_'.$def_id.'_p"> 
  49. <a class="button add-new-h2 ninja-forms-insert-def-field" id="ninja_forms_insert_def_field_'.$def_id.'" name="" href="#">'.__($name, 'ninja-forms').'</a> 
  50. </p>'; 
  51. header("Content-type: application/json"); 
  52. $array = array ('def_id' => $def_id, 'def_name' => $name, 'link_html' => $new_html); 
  53. echo json_encode($array); 
  54.  
  55. die();