_deprecated_class

函数
_deprecated_class ( $class_name, $version, $replacement = '' )
参数
  • (string) $class_name The name of the class being instantiated.
    Required:
  • (string) $version The version of WordPress that deprecated the class.
    Required:
  • (string) $replacement Optional. The class or function that should have been called. Default empty string.
    Required:
    Default: (empty)
定义位置
相关方法
_deprecated_file_deprecated_hook_deprecated_argument_deprecated_constructor_deprecated_function
引入
6.4.0
弃用
-

将一个类标记为废弃类,并在该类被使用时发出通知。

有一个{@see ‘deprecated_class_run’} 钩子会被调用,可用于获取回溯至哪个文件和函数调用了被弃用的类。

如果 `WP_DEBUG` 为 true,当前行为将触发用户错误。

该函数应在每个已废弃类的类构造函数中使用。参见 {@see} 以了解 PHP4 风格的构造函数。

function _deprecated_class( $class_name, $version, $replacement = '' ) {

	/**
	 * Fires when a deprecated class is called.
	 *
	 * @since 6.4.0
	 *
	 * @param string $class_name  The name of the class being instantiated.
	 * @param string $replacement The class or function that should have been called.
	 * @param string $version     The version of WordPress that deprecated the class.
	 */
	do_action( 'deprecated_class_run', $class_name, $replacement, $version );

	/**
	 * Filters whether to trigger an error for a deprecated class.
	 *
	 * @since 6.4.0
	 *
	 * @param bool $trigger Whether to trigger an error for a deprecated class. Default true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_class_trigger_error', true ) ) {
		if ( function_exists( '__' ) ) {
			if ( $replacement ) {
				$message = sprintf(
					/* translators: 1: PHP class name, 2: Version number, 3: Alternative class or function name. */
					__( 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
					$class_name,
					$version,
					$replacement
				);
			} else {
				$message = sprintf(
					/* translators: 1: PHP class name, 2: Version number. */
					__( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
					$class_name,
					$version
				);
			}
		} else {
			if ( $replacement ) {
				$message = sprintf(
					'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
					$class_name,
					$version,
					$replacement
				);
			} else {
				$message = sprintf(
					'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
					$class_name,
					$version
				);
			}
		}

		wp_trigger_error( '', $message, E_USER_DEPRECATED );
	}
}

常见问题

FAQs
查看更多 >