backpress_die

Kill BackPress execution and display HTML message with error message.

Description

backpress_die( (string) $message, (string) $title = '', (array) $args = array() ); 

This function calls the die() PHP function. The difference is that a message in HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further. It is not recommended to call this function very often and normally you should try to handle as many errors as possible silently.

Parameters (3)

0. $message (string)
Error message.
1. $title — Optional. (string) => ''
Error title.
2. $args — Optional. (array) => array()
Arguments to control behaviour.

Usage

  1. if ( !function_exists( 'backpress_die' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/backpress/functions.core.php'; 
  3.  
  4. // Error message. 
  5. $message = ''; 
  6.  
  7. // Error title. 
  8. $title = ''; 
  9.  
  10. // Optional arguments to control behaviour. 
  11. $args = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = backpress_die($message, $title, $args); 
  15.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/backpress/functions.core.php  
  1. function backpress_die( $message, $title = '', $args = array() ) 
  2. $defaults = array( 'response' => 500, 'language' => 'en-US', 'text_direction' => 'ltr' ); 
  3. $r = wp_parse_args( $args, $defaults ); 
  4.  
  5. if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { 
  6. if ( empty( $title ) ) { 
  7. $error_data = $message->get_error_data(); 
  8. if ( is_array( $error_data ) && isset( $error_data['title'] ) ) { 
  9. $title = $error_data['title']; 
  10. $errors = $message->get_error_messages(); 
  11. switch ( count( $errors ) ) { 
  12. case 0: 
  13. $message = ''; 
  14. break; 
  15. case 1: 
  16. $message = '<p>' . $errors[0] . '</p>'; 
  17. break; 
  18. default: 
  19. $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>"; 
  20. break; 
  21. } elseif ( is_string( $message ) ) { 
  22. $message = '<p>' . $message . '</p>'; 
  23.  
  24. if ( !headers_sent() ) { 
  25. status_header( $r['response'] ); 
  26. header( 'Content-Type: text/html; charset=utf-8' ); 
  27.  
  28. if ( empty( $title ) ) { 
  29. if ( function_exists( '__' ) ) { 
  30. $title = __( 'BackPress › Error' ); 
  31. } else { 
  32. $title = 'BackPress › Error'; 
  33.  
  34. if ( $r['text_direction'] ) { 
  35. $language_attributes = ' dir="' . $r['text_direction'] . '"'; 
  36.  
  37. if ( $r['language'] ) { 
  38. // Always XHTML 1.1 style 
  39. $language_attributes .= ' lang="' . $r['language'] . '"'; 
  40. ?> 
  41. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
  42. <html xmlns="http://www.w3.org/1999/xhtml"<?php echo $language_attributes; ?>> 
  43. <head> 
  44. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  45. <title><?php echo $title ?></title> 
  46. <style type="text/css" media="screen"> 
  47. html { background: #f7f7f7; } 
  48.  
  49. body { 
  50. background: #fff; 
  51. color: #333; 
  52. font-family: "Lucida Grande", Verdana, Arial, "Bitstream Vera Sans", sans-serif; 
  53. margin: 2em auto 0 auto; 
  54. width: 700px; 
  55. padding: 1em 2em; 
  56. -moz-border-radius: 11px; 
  57. -khtml-border-radius: 11px; 
  58. -webkit-border-radius: 11px; 
  59. border-radius: 11px; 
  60. border: 1px solid #dfdfdf; 
  61.  
  62. a { color: #2583ad; text-decoration: none; } 
  63.  
  64. a:hover { color: #d54e21; } 
  65.  
  66. h1 { 
  67. border-bottom: 1px solid #dadada; 
  68. clear: both; 
  69. color: #666; 
  70. font: 24px Georgia, "Times New Roman", Times, serif; 
  71. margin: 5px 0 0 -4px; 
  72. padding: 0; 
  73. padding-bottom: 7px; 
  74.  
  75. h2 { font-size: 16px; } 
  76.  
  77. p, li { 
  78. padding-bottom: 2px; 
  79. font-size: 12px; 
  80. line-height: 18px; 
  81.  
  82. code { font-size: 13px; } 
  83.  
  84. ul, ol { padding: 5px 5px 5px 22px; } 
  85.  
  86. #error-page { margin-top: 50px; } 
  87.  
  88. #error-page p { 
  89. font-size: 12px; 
  90. line-height: 18px; 
  91. margin: 25px 0 20px; 
  92.  
  93. #error-page code { font-family: Consolas, Monaco, Courier, monospace; } 
  94. <?php 
  95. if ( $r['text_direction'] === 'rtl') { 
  96. ?> 
  97. body { 
  98. font-family: Tahoma, "Times New Roman"; 
  99.  
  100. h1 { 
  101. font-family: Tahoma, "Times New Roman"; 
  102. margin: 5px -4px 0 0; 
  103.  
  104. ul, ol { padding: 5px 22px 5px 5px; } 
  105. <?php 
  106. ?> 
  107. </style> 
  108. </head> 
  109. <body id="error-page"> 
  110. <?php echo $message; ?> 
  111. </body> 
  112. </html> 
  113. <?php 
  114. die();