Index: src/wp-includes/class-wp-shutdown-handler.php
===================================================================
--- src/wp-includes/class-wp-shutdown-handler.php	(revision 44623)
+++ src/wp-includes/class-wp-shutdown-handler.php	(working copy)
@@ -122,12 +122,11 @@
 	 * Displays the PHP error template and sends the HTTP status code, typically 500.
 	 *
 	 * A drop-in 'php-error.php' can be used as a custom template. This drop-in should control the HTTP status code and
-	 * 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.
+	 * 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.
 	 *
-	 * The default template also displays a link to the admin in order to fix the problem, however doing so is not
-	 * mandatory.
+	 * If no such drop-in is available, this will call {@see WP_Shutdown_Handler::display_default_error_template()}.
 	 *
 	 * @since 5.1.0
 	 */
@@ -141,54 +140,57 @@
 			}
 		}
 
-		// 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 );
+		// Otherwise, display the default error template.
+		$this->display_default_error_template();
 	}
 
 	/**
-	 * Returns the error message markup to display in the default error template.
+	 * Displays the default PHP error template.
 	 *
+	 * 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.
+	 *
 	 * @since 5.1.0
-	 *
-	 * @return string Error message HTML output.
 	 */
-	protected function get_error_message_markup() {
+	protected function display_default_error_template() {
 		if ( ! function_exists( '__' ) ) {
 			wp_load_translations_early();
 		}
 
-		$message = sprintf(
-			'<p>%s</p>',
-			__( 'The site is experiencing technical difficulties.' )
-		);
+		if ( ! function_exists( 'wp_die' ) ) {
+			require_once ABSPATH . WPINC . '/functions.php';
+		}
 
+		$message = __( 'The site is experiencing technical difficulties.' );
+
+		$args = array( 'response' => 500 );
 		if ( function_exists( 'admin_url' ) ) {
-			$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.' )
-			);
+			$args['link_url']  = admin_url();
+			$args['link_text'] = __( 'Log into the admin backend to fix this.' );
 		}
 
-		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 );
-		}
+		/**
+		 * 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 );
 
-		return $message;
+		/**
+		 * 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 );
 	}
 }
Index: src/wp-includes/functions.php
===================================================================
--- src/wp-includes/functions.php	(revision 44623)
+++ src/wp-includes/functions.php	(working copy)
@@ -2933,6 +2933,7 @@
  * @since 2.0.4
  * @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
  *              an integer to be used as the response code.
+ * @since 5.1.0 The `$link_url` and `$link_text` arguments were added.
  *
  * @param string|WP_Error  $message Optional. Error message. If this is a WP_Error object,
  *                                  and not an Ajax or XML-RPC request, the error's messages are used.
@@ -2946,6 +2947,10 @@
  *     as the response code. Default empty array.
  *
  *     @type int    $response       The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
+ *     @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.
  *     @type bool   $back_link      Whether to include a link to go back. Default false.
  *     @type string $text_direction The text direction. This is only useful internally, when WordPress
  *                                  is still loading and the site's locale is not set up yet. Accepts 'rtl'.
@@ -2970,6 +2975,15 @@
 		 * @param callable $function Callback function name.
 		 */
 		$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
+	} elseif ( wp_is_json_request() ) {
+		/**
+		 * Filters the callback for killing WordPress execution for JSON requests.
+		 *
+		 * @since 5.1.0
+		 *
+		 * @param callable $function Callback function name.
+		 */
+		$function = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' );
 	} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
 		/**
 		 * Filters the callback for killing WordPress execution for XML-RPC requests.
@@ -3035,6 +3049,15 @@
 		$message = "<p>$message</p>";
 	}
 
+	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>";
+	}
+
 	if ( isset( $r['back_link'] ) && $r['back_link'] ) {
 		$back_text = $have_gettext ? __( '&laquo; Back' ) : '&laquo; Back';
 		$message  .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";
@@ -3202,6 +3225,40 @@
 }
 
 /**
+ * Kill WordPress execution and display JSON message with error message.
+ *
+ * This is the handler for wp_die when processing JSON requests.
+ *
+ * @since 5.1.0
+ * @access private
+ *
+ * @param string       $message Error message.
+ * @param string       $title   Optional. Error title. Default empty.
+ * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
+ */
+function _json_wp_die_handler( $message, $title = '', $args = array() ) {
+	$defaults = array( 'response' => 500 );
+
+	$r = wp_parse_args( $args, $defaults );
+
+	$data = array(
+		'code'    => 'wp_die',
+		'message' => $message,
+		'status'  => $r['response'],
+	);
+
+	if ( ! headers_sent() ) {
+		header( 'Content-Type: application/json; charset=utf-8' );
+		if ( null !== $r['response'] ) {
+			status_header( $r['response'] );
+		}
+	}
+
+	echo wp_json_encode( $data );
+	die();
+}
+
+/**
  * Kill WordPress execution and display XML message with error message.
  *
  * This is the handler for wp_die when processing XMLRPC requests.
