is_protected_endpoint

函式
is_protected_endpoint ( No parameters )
返回值
  • (bool) True if the current endpoint should be protected.
定義位置
相關方法
is_protected_metaadd_rewrite_endpointis_protected_ajax_action_deprecated_argumentget_oembed_endpoint_url
引入
5.2.0
棄用
-

is_protected_endpoint – 這個函式檢查一個給定的REST API端點是否被保護。如果該端點是受保護的,該函式返回true。

確定我們當前是否在一個應該被保護的端點上,以防止WSOD。

function is_protected_endpoint() {
	// Protect login pages.
	if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
		return true;
	}

	// Protect the admin backend.
	if ( is_admin() && ! wp_doing_ajax() ) {
		return true;
	}

	// Protect Ajax actions that could help resolve a fatal error should be available.
	if ( is_protected_ajax_action() ) {
		return true;
	}

	/**
	 * Filters whether the current request is against a protected endpoint.
	 *
	 * This filter is only fired when an endpoint is requested which is not already protected by
	 * WordPress core. As such, it exclusively allows providing further protected endpoints in
	 * addition to the admin backend, login pages and protected Ajax actions.
	 *
	 * @since 5.2.0
	 *
	 * @param bool $is_protected_endpoint Whether the currently requested endpoint is protected.
	 *                                    Default false.
	 */
	return (bool) apply_filters( 'is_protected_endpoint', false );
}

常見問題

FAQs
檢視更多 >