_deprecated_class()WP 6.4.0

Marks a class as deprecated and informs when it has been used.

There is a deprecated_class_run hook that will be called that can be used to get the backtrace up to what file and function called the deprecated class.

The current behavior is to trigger a user error if WP_DEBUG is true.

This function is to be used in the class constructor for every deprecated class. See _deprecated_constructor() for deprecating PHP4-style constructors.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

Return

null. Nothing (null).

Usage

_deprecated_class( $class_name, $version, $replacement );
$class_name(string) (required)
The name of the class being instantiated.
$version(string) (required)
The version of WordPress that deprecated the class.
$replacement(string)
The class or function that should have been called.
Default: empty string

Changelog

Since 6.4.0 Introduced.

_deprecated_class() code WP 6.5.4

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 );
	}
}