ninja_forms_add_fav

The Ninja Forms ninja forms add fav function.

Description

ninja_forms_add_fav(); 

Usage

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

Defined (1)

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

/deprecated/includes/admin/ajax.php  
  1. function ninja_forms_add_fav() { 
  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. $form_id = 1; 
  17.  
  18. $data = array(); 
  19.  
  20. foreach($field_data as $key => $val) { 
  21. $key = stripslashes( $key ); 
  22. $key = str_replace('"', '', $key); 
  23. if(strpos($key, '[')) { 
  24. $key = str_replace(']', '', $key); 
  25. $key = explode('[', $key); 
  26. $multi = array(); 
  27. $temp =& $multi; 
  28. $x = 0; 
  29. $count = count($key) - 1; 
  30. foreach ($key as $item) { 
  31. $temp[$item] = array(); 
  32. if($x < $count) { 
  33. $temp =& $temp[$item]; 
  34. }else{ 
  35. $temp[$item] = $val; 
  36. $x++; 
  37. $data = ninja_forms_array_merge_recursive($data, $multi); 
  38. }else{ 
  39. $data[$key] = $val; 
  40.  
  41. $name = stripslashes( esc_html( $_REQUEST['fav_name'] ) ); 
  42. if ( !isset ( $data['label'] ) or empty ( $data['label'] ) ) { 
  43. $data['label'] = $name;  
  44.  
  45. $data = ninja_forms_stripslashes_deep( $data ); 
  46.  
  47. $data = serialize($data); 
  48. $wpdb->insert(NINJA_FORMS_FAV_FIELDS_TABLE_NAME, array('row_type' => 1, 'type' => $field_type, 'order' => 0, 'data' => $data, 'name' => $name)); 
  49. $fav_id = $wpdb->insert_id; 
  50. $update_array = array('fav_id' => $fav_id); 
  51. $wpdb->update( NINJA_FORMS_FIELDS_TABLE_NAME, $update_array, array( 'id' => $field_id )); 
  52.  
  53. $new_html = '<p class="button-controls" id="ninja_forms_insert_fav_field_'.$fav_id.'_p"> 
  54. <a class="button add-new-h2 ninja-forms-insert-fav-field" id="ninja_forms_insert_fav_field_'.$fav_id.'" data-field="' . $fav_id . '" data-type="fav" href="#">'.__($name, 'ninja-forms').'</a> 
  55. </p>'; 
  56.  
  57. header("Content-type: application/json"); 
  58. $array = array ('fav_id' => $fav_id, 'fav_name' => $name, 'link_html' => $new_html); 
  59. echo json_encode($array); 
  60.  
  61. die();