nf_admin_save_builder

Save our admin fields page.

Description

nf_admin_save_builder(); 

Usage

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

Defined (1)

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

/deprecated/includes/admin/ajax.php  
  1. function nf_admin_save_builder() { 
  2. global $ninja_forms_fields, $wpdb; 
  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. $field_data = json_decode( stripslashes( $_REQUEST['field_data'] ), true ); 
  15. $form_id = esc_html( $_REQUEST['form_id'] ); 
  16. $form_title = stripslashes( $_REQUEST['form_title'] ); 
  17. $field_order = json_decode( strip_tags( stripslashes( $_REQUEST['field_order'] ) ), true ); 
  18.  
  19. if ( is_array ( $field_order ) ) { 
  20. $order_array = array(); 
  21. $x = 0; 
  22. foreach ( $field_order as $id ) { 
  23. $id = str_replace( 'ninja_forms_field_', '', $id ); 
  24. $order_array[ $id ] = $x; 
  25. $x++; 
  26.  
  27. $tmp_array = array(); 
  28. foreach ( $field_data as $field ) { 
  29. $field_id = $field['id']; 
  30. unset( $field['id'] ); 
  31. unset( $field['metabox_state'] ); 
  32. $tmp_array[ $field_id ] = $field; 
  33.  
  34. $field_data = $tmp_array; 
  35.  
  36. if ( isset ( $ninja_forms_fields ) && is_array( $ninja_forms_fields ) ) { 
  37. foreach ( $ninja_forms_fields as $slug => $field ) { 
  38. if ( $field['save_function'] != '') { 
  39. $save_function = $field['save_function']; 
  40. $arguments['form_id'] = $form_id; 
  41. $arguments['data'] = $field_data; 
  42. $field_data = call_user_func_array( $save_function, $arguments ); 
  43.  
  44. if( $form_id != '' && $form_id != 0 && $form_id != 'new' ) { 
  45. foreach ( $field_data as $field_id => $vals ) { 
  46. $field_order = isset( $order_array[$field_id] ) ? $order_array[$field_id] : ''; 
  47. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  48. $data = $field_row['data']; 
  49. foreach( $vals as $k => $v ) { 
  50. $data[$k] = $v; 
  51. $data_array = array('data' => serialize( $data ), 'order' => $field_order); 
  52. $wpdb->update( NINJA_FORMS_FIELDS_TABLE_NAME, $data_array, array( 'id' => $field_id )); 
  53.  
  54. $date_updated = date( 'Y-m-d H:i:s', strtotime ( 'now' ) ); 
  55. Ninja_Forms()->form( $form_id )->update_setting( 'form_title', $form_title ); 
  56. Ninja_Forms()->form( $form_id )->update_setting( 'date_updated', $date_updated ); 
  57. Ninja_Forms()->form( $form_id )->update_setting( 'status', '' ); 
  58.  
  59. // Dump our current form transient. 
  60. delete_transient( 'nf_form_' . $form_id ); 
  61.  
  62. die();