<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[44624] trunk/src/wp-includes: Bootstrap/Load: Fix workaround to display admin link in PHP error template by introducing `$link_url` and `$link_text` arguments to `wp_die()`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/44624">44624</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/44624","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>flixos90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-01-16 15:20:04 +0000 (Wed, 16 Jan 2019)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Bootstrap/Load: Fix workaround to display admin link in PHP error template by introducing `$link_url` and `$link_text` arguments to `wp_die()`.
This changeset removes the hack that was used before to display more complex HTML markup than a simple message in the default PHP error template via `wp_die()`. By removing HTML markup from the arguments passed to `wp_die()` it furthermore paves the way for supporting other content types than the default.
The message and arguments can be modified with new `wp_php_error_message` and `wp_php_error_args` filters respectively.
Furthermore this changeset fixes a few issues of functions not existing which could potentially have caused fatal errors when executed early in the WordPress bootstrap process.
Props flixos90, spacedmonkey.
See <a href="https://core.trac.wordpress.org/ticket/45933">#45933</a>, <a href="https://core.trac.wordpress.org/ticket/44458">#44458</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpshutdownhandlerphp">trunk/src/wp-includes/class-wp-shutdown-handler.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpshutdownhandlerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-shutdown-handler.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-shutdown-handler.php 2019-01-16 14:03:35 UTC (rev 44623)
+++ trunk/src/wp-includes/class-wp-shutdown-handler.php 2019-01-16 15:20:04 UTC (rev 44624)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -122,12 +122,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Displays the PHP error template and sends the HTTP status code, typically 500.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * A drop-in 'php-error.php' can be used as a custom template. This drop-in should control the HTTP status code and
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * print the HTML markup indicating that a PHP error occurred. Alternatively, {@see wp_die()} can be used. Note
- * that this drop-in may potentially be executed very early in the WordPress bootstrap process, so any core
- * functions used that are not part of `wp-includes/load.php` should be checked for before being called.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * print the HTML markup indicating that a PHP error occurred. Note that this drop-in may potentially be executed
+ * very early in the WordPress bootstrap process, so any core functions used that are not part of
+ * `wp-includes/load.php` should be checked for before being called.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The default template also displays a link to the admin in order to fix the problem, however doing so is not
- * mandatory.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * If no such drop-in is available, this will call {@see WP_Shutdown_Handler::display_default_error_template()}.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.1.0
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -141,54 +140,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Otherwise, fail with a `wp_die()` message.
- $message = $this->get_error_message_markup();
-
- // `wp_die()` wraps the message in paragraph tags, so let's just try working around that.
- if ( substr( $message, 0, 3 ) === '<p>' && substr( $message, -4 ) === '</p>' ) {
- $message = substr( $message, 3, -4 );
- }
-
- wp_die( $message, '', 500 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Otherwise, display the default error template.
+ $this->display_default_error_template();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Returns the error message markup to display in the default error template.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Displays the default PHP error template.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This method is called conditionally if no 'php-error.php' drop-in is available.
+ *
+ * It calls {@see wp_die()} with a message indicating that the site is experiencing technical difficulties and a
+ * login link to the admin backend. The {@see 'wp_php_error_message'} and {@see 'wp_php_error_args'} filters can
+ * be used to modify these parameters.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 5.1.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
- * @return string Error message HTML output.
</del><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected function get_error_message_markup() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function display_default_error_template() {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! function_exists( '__' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_load_translations_early();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $message = sprintf(
- '<p>%s</p>',
- __( 'The site is experiencing technical difficulties.' )
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! function_exists( 'wp_die' ) ) {
+ require_once ABSPATH . WPINC . '/functions.php';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $message = __( 'The site is experiencing technical difficulties.' );
+
+ $args = array( 'response' => 500 );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( function_exists( 'admin_url' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $message .= sprintf(
- '<hr><p><em>%s <a href="%s">%s</a></em></p>',
- __( 'Are you the site owner?' ),
- admin_url(),
- __( 'Log into the admin backend to fix this.' )
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args['link_url'] = admin_url();
+ $args['link_text'] = __( 'Log into the admin backend to fix this.' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( function_exists( 'apply_filters' ) ) {
- /**
- * Filters the message that the default PHP error page displays.
- *
- * @since 5.1.0
- *
- * @param string $message HTML error message to display.
- */
- $message = apply_filters( 'wp_technical_issues_display', $message );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the message that the default PHP error template displays.
+ *
+ * @since 5.1.0
+ *
+ * @param string $message HTML error message to display.
+ */
+ $message = apply_filters( 'wp_php_error_message', $message );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $message;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the arguments passed to {@see wp_die()} for the default PHP error template.
+ *
+ * @since 5.1.0
+ *
+ * @param array $args Associative array of arguments passed to `wp_die()`. By default these contain a
+ * 'response' key, and optionally 'link_url' and 'link_text' keys.
+ */
+ $args = apply_filters( 'wp_php_error_args', $args );
+
+ wp_die( $message, '', $args );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php 2019-01-16 14:03:35 UTC (rev 44623)
+++ trunk/src/wp-includes/functions.php 2019-01-16 15:20:04 UTC (rev 44624)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2933,6 +2933,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.4
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
</span><span class="cx" style="display: block; padding: 0 10px"> * an integer to be used as the response code.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.1.0 The `$link_url` and `$link_text` arguments were added.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|WP_Error $message Optional. Error message. If this is a WP_Error object,
</span><span class="cx" style="display: block; padding: 0 10px"> * and not an Ajax or XML-RPC request, the error's messages are used.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2946,6 +2947,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * as the response code. Default empty array.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $response The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string $link_url A URL to include a link to. Only works in combination with $link_text.
+ * Default empty string.
+ * @type string $link_text A label for the link to include. Only works in combination with $link_url.
+ * Default empty string.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type bool $back_link Whether to include a link to go back. Default false.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $text_direction The text direction. This is only useful internally, when WordPress
</span><span class="cx" style="display: block; padding: 0 10px"> * is still loading and the site's locale is not set up yet. Accepts 'rtl'.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3035,6 +3040,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $message = "<p>$message</p>";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $r['link_url'] ) && ! empty( $r['link_text'] ) ) {
+ $link_url = $r['link_url'];
+ if ( function_exists( 'esc_url' ) ) {
+ $link_url = esc_url( $link_url );
+ }
+ $link_text = $r['link_text'];
+ $message .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>";
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $r['back_link'] ) && $r['back_link'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $back_text = $have_gettext ? __( '« Back' ) : '« Back';
</span><span class="cx" style="display: block; padding: 0 10px"> $message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";
</span></span></pre>
</div>
</div>
</body>
</html>