NF_ExceptionHandlerJS

Adds a global exception handler for reporting on form rendering issues.

Defined (1)

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

/lib/NF_ExceptionHandlerJS.php  
  1. final class NF_ExceptionHandlerJS 
  2. public function __construct() 
  3. add_action( 'wp_head', array( $this, 'wp_head' ), 6 ); 
  4.  
  5. public function wp_head() 
  6. if( ! current_user_can( 'manage_options' ) ) return; 
  7. ?> 
  8. <script type="text/javascript"> 
  9. window.addEventListener( 'error', function (e) { 
  10.  
  11. var source = e.filename.match( /plugins\/(...)/gi ) || e.filename; 
  12.  
  13. var message = '<pre>' + 
  14. '[ADMIN NOTICE] Form Rendering Error' + 
  15. '\r\rSource: ' + source + 
  16. '\r\r<span style="color:red;">' + e.error + '</span>' + 
  17. '</pre>'; 
  18.  
  19.  
  20. // Replace form loading animation. 
  21. var forms = document.getElementsByClassName( 'nf-form-cont' ); 
  22. for ( var i = 0; i < forms.length; i++ ) { 
  23. forms[i].innerHTML = message; 
  24. }); 
  25. </script> 
  26. <?php 
  27. } // END CLASS NF_ExceptionHandlerJS