pods_error

Error Handling which throws / displays errors.

Description

(mixed|void) pods_error( (string) $error, (null) $obj = null ); 

Returns (mixed|void)

Parameters (2)

0. $error (string)
The error message to be thrown / displayed
1. $obj — Optional. (null) => null
/ boolean $obj If object, if $obj->display_errors is set, and is set to true: display errors; If boolean, and is set to true: display errors

Usage

  1. if ( !function_exists( 'pods_error' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/general.php'; 
  3.  
  4. // The error message to be thrown / displayed 
  5. $error = ''; 
  6.  
  7. // / boolean $obj If object, if $obj->display_errors is set, and is set to true: display errors; 
  8. // If boolean, and is set to true: display errors 
  9. $obj = null; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = pods_error($error, $obj); 
  13.  

Defined (1)

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

/includes/general.php  
  1. function pods_error ( $error, $obj = null ) { 
  2.  
  3. global $pods_errors; 
  4.  
  5. $display_errors = false; 
  6.  
  7. if ( is_object( $obj ) && isset( $obj->display_errors ) && true === $obj->display_errors ) 
  8. $display_errors = true; 
  9. elseif ( is_bool( $obj ) && true === $obj ) 
  10. $display_errors = true; 
  11.  
  12. if ( is_object( $error ) && 'Exception' == get_class( $error ) ) { 
  13. $error = $error->getMessage(); 
  14. $display_errors = false; 
  15.  
  16. if ( is_array( $error ) ) { 
  17. if ( 1 == count( $error ) ) 
  18. $error = current( $error ); 
  19. elseif ( defined( 'DOING_AJAX' ) && DOING_AJAX ) 
  20. $error = __( 'The following issue occurred:', pods ) . "\n\n- " . implode( "\n- ", $error ); 
  21. else 
  22. $error = __( 'The following issues occurred:', pods ) . "\n<ul><li>" . implode( "</li>\n<li>", $error ) . "</li></ul>"; 
  23.  
  24. if ( is_object( $error ) ) 
  25. $error = __( 'An unknownerrorhas occurred', pods ); 
  26.  
  27. // logerrorin WP 
  28. $log_error = new WP_Error( 'pods-error-' . md5( $error ), $error ); 
  29.  
  30. // throwerroras Exception and return false if silent 
  31. if ( $pods_errors !== $error && false === $display_errors && !empty( $error ) ) { 
  32. $exception_bypass = apply_filters( 'pods_error_exception', null, $error ); 
  33.  
  34. if ( null !== $exception_bypass ) 
  35. return $exception_bypass; 
  36.  
  37. $pods_errors = $error; 
  38.  
  39. set_exception_handler( 'pods_error' ); 
  40.  
  41. throw new Exception( $error ); 
  42.  
  43. $pods_errors = array(); 
  44.  
  45. $die_bypass = apply_filters( 'pods_error_die', null, $error ); 
  46.  
  47. if ( null !== $die_bypass ) 
  48. return $die_bypass; 
  49.  
  50. // die with error 
  51. if ( !defined( 'DOING_AJAX' ) && !headers_sent() && ( is_admin() || false !== strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) ) 
  52. wp_die( $error ); 
  53. else 
  54. die( "<e>$error</e>" );