NF_AJAX_Controllers_SavedFields

The Ninja Forms NF AJAX Controllers SavedFields class.

Defined (1)

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

/includes/AJAX/Controllers/SavedFields.php  
  1. class NF_AJAX_Controllers_SavedFields extends NF_Abstracts_Controller 
  2. public function __construct() 
  3. add_action( 'wp_ajax_nf_create_saved_field', array( $this, 'create' ) ); 
  4. add_action( 'wp_ajax_nf_update_saved_field', array( $this, 'update' ) ); 
  5. add_action( 'wp_ajax_nf_delete_saved_field', array( $this, 'delete' ) ); 
  6.  
  7. public function create() 
  8. check_ajax_referer( 'ninja_forms_builder_nonce', 'security' ); 
  9.  
  10. if( ! isset( $_POST[ 'field' ] ) ) { 
  11. $this->_errors[] = __( 'Field Not Found', 'ninja-forms' ); 
  12. $this->_respond(); 
  13.  
  14. $field_settings = json_decode( stripslashes( $_POST[ 'field' ] ), ARRAY_A ); 
  15.  
  16. $field = Ninja_Forms()->form()->field()->get(); 
  17. $field->update_settings( $field_settings ); 
  18. $field->update_setting( 'saved', 1 ); 
  19. $field->save(); 
  20.  
  21. $this->_data[ 'id' ] = $field->get_id(); 
  22.  
  23. $this->_respond(); 
  24.  
  25. public function update() 
  26. check_ajax_referer( 'ninja_forms_builder_nonce', 'security' ); 
  27.  
  28. if( ! isset( $_POST[ 'field' ] ) ) { 
  29. $this->_errors[] = __( 'Field Not Found', 'ninja-forms' ); 
  30. $this->_respond(); 
  31.  
  32. $this->_respond(); 
  33.  
  34. public function delete() 
  35. check_ajax_referer( 'ninja_forms_settings_nonce', 'security' ); 
  36.  
  37. if( ! isset( $_POST[ 'field' ] ) ) { 
  38. $this->_errors[] = __( 'Field Not Found', 'ninja-forms' ); 
  39. $this->_respond(); 
  40.  
  41. $id = absint( $_POST[ 'field' ][ 'id' ] ); 
  42.  
  43. $errors = Ninja_Forms()->form()->get_field( $id )->delete(); 
  44.  
  45. $this->_data[ 'id' ] = $id; 
  46. $this->_data[ 'errors' ] = $errors; 
  47.  
  48. $this->_respond(); 
  49.  
  50.