_ajax_wp_die_handler

函式
_ajax_wp_die_handler ( $message, $title = '', $args = array() )
Access
Private
引數
  • (string) $message Error message.
    Required:
  • (string) $title Optional. Error title (unused). Default empty.
    Required:
    Default: (empty)
  • (string|array) $args Optional. Arguments to control behavior. Default empty array.
    Required:
    Default: array()
定義位置
相關方法
_xml_wp_die_handler_scalar_wp_die_handler_json_wp_die_handler_jsonp_wp_die_handler_xmlrpc_wp_die_handler
引入
3.4.0
棄用
-

_ajax_wp_die_handler: 這個函式用來處理在WordPress的AJAX請求中出現的錯誤。它負責輸出一個錯誤資訊並終止AJAX請求。

殺死WordPress的執行,並以錯誤資訊顯示Ajax響應。

這是處理Ajax請求時wp_die()的處理程式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
// Set default 'response' to 200 for Ajax requests.
$args = wp_parse_args(
$args,
array( 'response' => 200 )
);
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
if ( ! headers_sent() ) {
// This is intentional. For backward-compatibility, support passing null here.
if ( null !== $args['response'] ) {
status_header( $parsed_args['response'] );
}
nocache_headers();
}
if ( is_scalar( $message ) ) {
$message = (string) $message;
} else {
$message = '0';
}
if ( $parsed_args['exit'] ) {
die( $message );
}
echo $message;
}
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) { // Set default 'response' to 200 for Ajax requests. $args = wp_parse_args( $args, array( 'response' => 200 ) ); list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args ); if ( ! headers_sent() ) { // This is intentional. For backward-compatibility, support passing null here. if ( null !== $args['response'] ) { status_header( $parsed_args['response'] ); } nocache_headers(); } if ( is_scalar( $message ) ) { $message = (string) $message; } else { $message = '0'; } if ( $parsed_args['exit'] ) { die( $message ); } echo $message; }
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
	// Set default 'response' to 200 for Ajax requests.
	$args = wp_parse_args(
		$args,
		array( 'response' => 200 )
	);

	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );

	if ( ! headers_sent() ) {
		// This is intentional. For backward-compatibility, support passing null here.
		if ( null !== $args['response'] ) {
			status_header( $parsed_args['response'] );
		}
		nocache_headers();
	}

	if ( is_scalar( $message ) ) {
		$message = (string) $message;
	} else {
		$message = '0';
	}

	if ( $parsed_args['exit'] ) {
		die( $message );
	}

	echo $message;
}

常見問題

FAQs
檢視更多 >