返回介绍

_default_wp_die_handler()

发布于 2017-09-11 13:19:18 字数 3765 浏览 996 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

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

Kills WordPress execution and display HTML message with error message.


description

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


参数

$message

(string|WP_Error) (Required) Error message or WP_Error object.

$title

(string) (Optional) Error title.

Default value: ''

$args

(string|array) (Optional) Arguments to control behavior.

Default value: array()


源代码

File: wp-includes/functions.php

function _default_wp_die_handler( $message, $title = '', $args = array() ) {
	$defaults = array( 'response' => 500 );
	$r = wp_parse_args($args, $defaults);

	$have_gettext = function_exists('__');

	if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
		if ( empty( $title ) ) {
			$error_data = $message->get_error_data();
			if ( is_array( $error_data ) && isset( $error_data['title'] ) )
				$title = $error_data['title'];
		}
		$errors = $message->get_error_messages();
		switch ( count( $errors ) ) {
		case 0 :
			$message = '';
			break;
		case 1 :
			$message = "<p>{$errors[0]}</p>";
			break;
		default :
			$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>";
			break;
		}
	} elseif ( is_string( $message ) ) {
		$message = "<p>$message</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>";
	}

	if ( ! did_action( 'admin_head' ) ) :
		if ( !headers_sent() ) {
			status_header( $r['response'] );
			nocache_headers();
			header( 'Content-Type: text/html; charset=utf-8' );
		}

		if ( empty($title) )
			$title = $have_gettext ? __('WordPress &rsaquo; Error') : 'WordPress &rsaquo; Error';

		$text_direction = 'ltr';
		if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] )
			$text_direction = 'rtl';
		elseif ( function_exists( 'is_rtl' ) && is_rtl() )
			$text_direction = 'rtl';
?>
<!DOCTYPE html>
<!-- Ticket

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: __()
  • wp-includes/general-template.php: language_attributes()
  • wp-includes/general-template.php: wp_no_robots()
  • wp-includes/functions.php: wp_parse_args()
  • wp-includes/functions.php: status_header()
  • wp-includes/functions.php: nocache_headers()
  • wp-includes/l10n.php: is_rtl()
  • wp-includes/plugin.php: did_action()
  • wp-includes/load.php: is_wp_error()
  • Show 4 more uses Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文