NF_Abstracts_Controller

The Ninja Forms NF Abstracts Controller class.

Defined (1)

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

/includes/Abstracts/Controller.php  
  1. abstract class NF_Abstracts_Controller 
  2. /** 
  3. * Data (Misc.) passed back to the client in the Response. 
  4. * @var array 
  5. */ 
  6. protected $_data = array(); 
  7.  
  8. /** 
  9. * Errors passed back to the client in the Response. 
  10. * @var array 
  11. */ 
  12. protected $_errors = array(); 
  13.  
  14. /** 
  15. * Debug Messages passed back to the client in the Response. 
  16. * @var array 
  17. */ 
  18. protected $_debug = array(); 
  19.  
  20. /** 
  21. * PUBLIC METHODS 
  22. */ 
  23.  
  24. /** 
  25. * NF_Abstracts_Controller constructor. 
  26. */ 
  27. public function __construct() 
  28. //This section intentionally left blank. 
  29.  
  30.  
  31. /** 
  32. * PROTECTED METHODS 
  33. */ 
  34.  
  35. /** 
  36. * Respond 
  37. * A wrapper for the WordPress AJAX response pattern. 
  38. */ 
  39. protected function _respond( $data = array() ) 
  40. if( empty( $data ) ) { 
  41. $data = $this->_data; 
  42.  
  43. if( isset( $this->_data['debug'] ) ) { 
  44. $this->_debug = array_merge( $this->_debug, $this->_data[ 'debug' ] ); 
  45.  
  46. if( isset( $this->_data['errors'] ) && $this->_data[ 'errors' ] ) { 
  47. $this->_errors = array_merge( $this->_errors, $this->_data[ 'errors' ] ); 
  48.  
  49. $response = array( 'data' => $data, 'errors' => $this->_errors, 'debug' => $this->_debug ); 
  50.  
  51. echo wp_json_encode( $response ); 
  52.  
  53. wp_die(); // this is required to terminate immediately and return a proper response