ninja_forms_insert_field

The Ninja Forms ninja forms insert field function.

Description

ninja_forms_insert_field( $form_id, (array) $args = array() ); 

Parameters (2)

0. $form_id
The form id.
1. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'ninja_forms_insert_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/database.php'; 
  3.  
  4. // The form id. 
  5. $form_id = null; 
  6.  
  7. // The args. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ninja_forms_insert_field($form_id, $args); 
  12.  

Defined (1)

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

/deprecated/includes/database.php  
  1. function ninja_forms_insert_field( $form_id, $args = array() ) { 
  2. global $wpdb; 
  3. $insert_array = array(); 
  4.  
  5. $insert_array['type'] = $args['type']; 
  6. $insert_array['form_id'] = $form_id; 
  7.  
  8. if( isset( $args['data'] ) ) { 
  9. $insert_array['data'] = $args['data']; 
  10. }else{ 
  11. $insert_array['data'] = ''; 
  12.  
  13. if( isset( $args['order'] ) ) { 
  14. $insert_array['order'] = $args['order']; 
  15. }else{ 
  16. $insert_array['order'] = 999; 
  17.  
  18. if( isset( $args['fav_id'] ) ) { 
  19. $insert_array['fav_id'] = $args['fav_id']; 
  20.  
  21. if( isset( $args['def_id'] ) ) { 
  22. $insert_array['def_id'] = $args['def_id']; 
  23.  
  24. $new_field = $wpdb->insert( NINJA_FORMS_FIELDS_TABLE_NAME, $insert_array ); 
  25. $new_id = $wpdb->insert_id; 
  26. return $new_id;