wp_is_xml_request

函式
wp_is_xml_request ( No parameters )
返回值
  • (bool) True if `Accepts` or `Content-Type` headers contain `text/xml` or one of the related MIME types. False otherwise.
定義位置
相關方法
wp_is_json_requestwp_is_jsonp_requestwp_safe_remote_requestwp_remote_requestwp_send_user_request
引入
5.2.0
棄用
-

wp_is_xml_request: 這個函式用來檢查當前的請求是否是一個XML請求。如果該請求是一個XML請求,則返回true,否則返回false。

檢查當前請求是否是一個XML請求,或者是否在期待一個XML響應。

function wp_is_xml_request() {
	$accepted = array(
		'text/xml',
		'application/rss+xml',
		'application/atom+xml',
		'application/rdf+xml',
		'text/xml+oembed',
		'application/xml+oembed',
	);

	if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
		foreach ( $accepted as $type ) {
			if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) {
				return true;
			}
		}
	}

	if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) {
		return true;
	}

	return false;
}

常見問題

FAQs
檢視更多 >