wp_get_extension_error_description

函数
wp_get_extension_error_description ( $error )
参数
  • (array) $error Error details from `error_get_last()`.
    Required:
返回值
  • (string) Formatted error description.
定义位置
相关方法
get_the_author_descriptionwp_sidebar_descriptionget_file_descriptionget_the_archive_descriptionwp_widget_description
引入
5.2.0
弃用
-

wp_get_extension_error_description: 这个函数根据传递给它的错误代码,返回一个人类可读的错误信息。这些错误代码是针对媒体上传过程中可能出现的文件扩展名错误,并在wp_check_filetype函数中定义。

获得一个扩展的错误的人类可读描述。

function wp_get_extension_error_description( $error ) {
	$constants   = get_defined_constants( true );
	$constants   = isset( $constants['Core'] ) ? $constants['Core'] : $constants['internal'];
	$core_errors = array();

	foreach ( $constants as $constant => $value ) {
		if ( 0 === strpos( $constant, 'E_' ) ) {
			$core_errors[ $value ] = $constant;
		}
	}

	if ( isset( $core_errors[ $error['type'] ] ) ) {
		$error['type'] = $core_errors[ $error['type'] ];
	}

	/* translators: 1: Error type, 2: Error line number, 3: Error file name, 4: Error message. */
	$error_message = __( 'An error of type %1$s was caused in line %2$s of the file %3$s. Error message: %4$s' );

	return sprintf(
		$error_message,
		"<code>{$error['type']}</code>",
		"<code>{$error['line']}</code>",
		"<code>{$error['file']}</code>",
		"<code>{$error['message']}</code>"
	);
}

常见问题

FAQs
查看更多 >