_default_wp_die_handler

Kills WordPress execution and display HTML message with error message.

Description

_default_wp_die_handler( (string|WP_Error) $message, (string) $title = '', (array) $args = array() ); 

This is the default handler for wp_die if you want a custom one for your site then you can overload using the filter in wp_die().

Parameters (3)

0. $message (string|WP_Error)
Error message or WP_Error object.
1. $title — Optional. (string) => ''
Error title. Default empty.
2. $args — Optional. (array) => array()
Arguments to control behavior. Default empty array.

Usage

  1. if ( !function_exists( '_default_wp_die_handler' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Error message or WP_Error object. 
  5. $message = null; 
  6.  
  7. // Optional. Error title. Default empty. 
  8. $title = ''; 
  9.  
  10. // Optional. Arguments to control behavior. Default empty array. 
  11. $args = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _default_wp_die_handler($message, $title, $args); 
  15.  

Defined (1)

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

/wp-includes/functions.php  
  1. function _default_wp_die_handler( $message, $title = '', $args = array() ) { 
  2. $defaults = array( 'response' => 500 ); 
  3. $r = wp_parse_args($args, $defaults); 
  4.  
  5. $have_gettext = function_exists('__'); 
  6.  
  7. if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { 
  8. if ( empty( $title ) ) { 
  9. $error_data = $message->get_error_data(); 
  10. if ( is_array( $error_data ) && isset( $error_data['title'] ) ) 
  11. $title = $error_data['title']; 
  12. $errors = $message->get_error_messages(); 
  13. switch ( count( $errors ) ) { 
  14. case 0 : 
  15. $message = ''; 
  16. break; 
  17. case 1 : 
  18. $message = "<p>{$errors[0]}</p>"; 
  19. break; 
  20. default : 
  21. $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>"; 
  22. break; 
  23. } elseif ( is_string( $message ) ) { 
  24. $message = "<p>$message</p>"; 
  25.  
  26. if ( isset( $r['back_link'] ) && $r['back_link'] ) { 
  27. $back_text = $have_gettext? __('« Back') : '« Back'; 
  28. $message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>"; 
  29.  
  30. if ( ! did_action( 'admin_head' ) ) : 
  31. if ( !headers_sent() ) { 
  32. status_header( $r['response'] ); 
  33. header( 'Content-Type: text/html; charset=utf-8' ); 
  34.  
  35. if ( empty($title) ) 
  36. $title = $have_gettext ? __('WordPress › Error') : 'WordPress › Error'; 
  37.  
  38. $text_direction = 'ltr'; 
  39. if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] ) 
  40. $text_direction = 'rtl'; 
  41. elseif ( function_exists( 'is_rtl' ) && is_rtl() ) 
  42. $text_direction = 'rtl'; 
  43. ?> 
  44. <!DOCTYPE html> 
  45. <!-- Ticket #11289, IE bug fix: always pad theerrorpage with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono 
  46. --> 
  47. <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) language_attributes(); else echo "dir='$text_direction'"; ?>> 
  48. <head> 
  49. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  50. <meta name="viewport" content="width=device-width"> 
  51. <?php 
  52. if ( function_exists( 'wp_no_robots' ) ) { 
  53. ?> 
  54. <title><?php echo $title ?></title> 
  55. <style type="text/css"> 
  56. html { 
  57. background: #f1f1f1; 
  58. body { 
  59. background: #fff; 
  60. color: #444; 
  61. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; 
  62. margin: 2em auto; 
  63. padding: 1em 2em; 
  64. max-width: 700px; 
  65. -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13); 
  66. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13); 
  67. h1 { 
  68. border-bottom: 1px solid #dadada; 
  69. clear: both; 
  70. color: #666; 
  71. font-size: 24px; 
  72. margin: 30px 0 0 0; 
  73. padding: 0; 
  74. padding-bottom: 7px; 
  75. #error-page { 
  76. margin-top: 50px; 
  77. #error-page p { 
  78. font-size: 14px; 
  79. line-height: 1.5; 
  80. margin: 25px 0 20px; 
  81. #error-page code { 
  82. font-family: Consolas, Monaco, monospace; 
  83. ul li { 
  84. margin-bottom: 10px; 
  85. font-size: 14px ; 
  86. a { 
  87. color: #0073aa; 
  88. a:hover,  
  89. a:active { 
  90. color: #00a0d2; 
  91. a:focus { 
  92. color: #124964; 
  93. -webkit-box-shadow: 
  94. 0 0 0 1px #5b9dd9,  
  95. 0 0 2px 1px rgba(30, 140, 190, .8); 
  96. box-shadow: 
  97. 0 0 0 1px #5b9dd9,  
  98. 0 0 2px 1px rgba(30, 140, 190, .8); 
  99. outline: none; 
  100. .button { 
  101. background: #f7f7f7; 
  102. border: 1px solid #ccc; 
  103. color: #555; 
  104. display: inline-block; 
  105. text-decoration: none; 
  106. font-size: 13px; 
  107. line-height: 26px; 
  108. height: 28px; 
  109. margin: 0; 
  110. padding: 0 10px 1px; 
  111. cursor: pointer; 
  112. -webkit-border-radius: 3px; 
  113. -webkit-appearance: none; 
  114. border-radius: 3px; 
  115. white-space: nowrap; 
  116. -webkit-box-sizing: border-box; 
  117. -moz-box-sizing: border-box; 
  118. box-sizing: border-box; 
  119.  
  120. -webkit-box-shadow: 0 1px 0 #ccc; 
  121. box-shadow: 0 1px 0 #ccc; 
  122. vertical-align: top; 
  123.  
  124. .button.button-large { 
  125. height: 30px; 
  126. line-height: 28px; 
  127. padding: 0 12px 2px; 
  128.  
  129. .button:hover,  
  130. .button:focus { 
  131. background: #fafafa; 
  132. border-color: #999; 
  133. color: #23282d; 
  134.  
  135. .button:focus { 
  136. border-color: #5b9dd9; 
  137. -webkit-box-shadow: 0 0 3px rgba( 0, 115, 170, .8 ); 
  138. box-shadow: 0 0 3px rgba( 0, 115, 170, .8 ); 
  139. outline: none; 
  140.  
  141. .button:active { 
  142. background: #eee; 
  143. border-color: #999; 
  144. -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); 
  145. box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); 
  146. -webkit-transform: translateY(1px); 
  147. -ms-transform: translateY(1px); 
  148. transform: translateY(1px); 
  149.  
  150. <?php 
  151. if ( 'rtl' == $text_direction ) { 
  152. echo 'body { font-family: Tahoma, Arial; }'; 
  153. ?> 
  154. </style> 
  155. </head> 
  156. <body id="error-page"> 
  157. <?php endif; // ! did_action( 'admin_head' ) ?> 
  158. <?php echo $message; ?> 
  159. </body> 
  160. </html> 
  161. <?php 
  162. die();