wp_trigger_error

函式
wp_trigger_error ( $function_name, $message, $error_level = E_USER_NOTICE )
引數
  • (string) $function_name The function that triggered the error.
    Required:
  • (string) $message The message explaining the error. The message can contain allowed HTML 'a' (with href), 'code', 'br', 'em', and 'strong' tags and http or https protocols. If it contains other HTML tags or protocols, the message should be escaped before passing to this function to avoid being stripped {@see}.
    Required:
  • (int) $error_level Optional. The designated error type for this error. Only works with E_USER family of constants. Default E_USER_NOTICE.
    Required:
    Default: E_USER_NOTICE
定義位置
相關方法
wp_get_theme_errorwp_image_editorwp_generatorwp_get_plugin_errorwp_trim_words
引入
6.4.0
棄用
-

生成使用者級錯誤/警告/提示/停用資訊。當 `WP_DEBUG` 為 true 時生成該資訊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
// Bail out if WP_DEBUG is not turned on.
if ( ! WP_DEBUG ) {
return;
}
/**
* Fires when the given function triggers a user-level error/warning/notice/deprecation message.
*
* Can be used for debug backtracking.
*
* @since 6.4.0
*
* @param string $function_name The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param int $error_level The designated error type for this error.
*/
do_action( 'wp_trigger_error_run', $function_name, $message, $error_level );
if ( ! empty( $function_name ) ) {
$message = sprintf( '%s(): %s', $function_name, $message );
}
$message = wp_kses(
$message,
array(
'a' => array( 'href' ),
'br',
'code',
'em',
'strong',
),
array( 'http', 'https' )
);
trigger_error( $message, $error_level );
}
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) { // Bail out if WP_DEBUG is not turned on. if ( ! WP_DEBUG ) { return; } /** * Fires when the given function triggers a user-level error/warning/notice/deprecation message. * * Can be used for debug backtracking. * * @since 6.4.0 * * @param string $function_name The function that was called. * @param string $message A message explaining what has been done incorrectly. * @param int $error_level The designated error type for this error. */ do_action( 'wp_trigger_error_run', $function_name, $message, $error_level ); if ( ! empty( $function_name ) ) { $message = sprintf( '%s(): %s', $function_name, $message ); } $message = wp_kses( $message, array( 'a' => array( 'href' ), 'br', 'code', 'em', 'strong', ), array( 'http', 'https' ) ); trigger_error( $message, $error_level ); }
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {

	// Bail out if WP_DEBUG is not turned on.
	if ( ! WP_DEBUG ) {
		return;
	}

	/**
	 * Fires when the given function triggers a user-level error/warning/notice/deprecation message.
	 *
	 * Can be used for debug backtracking.
	 *
	 * @since 6.4.0
	 *
	 * @param string $function_name The function that was called.
	 * @param string $message       A message explaining what has been done incorrectly.
	 * @param int    $error_level   The designated error type for this error.
	 */
	do_action( 'wp_trigger_error_run', $function_name, $message, $error_level );

	if ( ! empty( $function_name ) ) {
		$message = sprintf( '%s(): %s', $function_name, $message );
	}

	$message = wp_kses(
		$message,
		array(
			'a' => array( 'href' ),
			'br',
			'code',
			'em',
			'strong',
		),
		array( 'http', 'https' )
	);

	trigger_error( $message, $error_level );
}

常見問題

FAQs
檢視更多 >