将构造函数标记为已弃用,并在使用时通知。

原型

_deprecated_constructor( string $class, string $version, string $parent_class = '' )

描述

与_deprecated_function()类似,但具有不同的字符串。用于删除PHP4样式构造函数。

参数

$class (string) (Required) 包含已弃用的构造函数的类。

$version (string) (Required) 弃用该函数的WordPress版本。

$parent_class (string) (Optional)  父类调用不推荐的构造函数。

源文件

路径:wp-includes/functions.php

<?php
...
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
	/**
	 * Fires when a deprecated constructor is called.
	 *
	 * @since 4.3.0
	 * @since 4.5.0 Added the `$parent_class` parameter.
	 *
	 * @param string $class        The class containing the deprecated constructor.
	 * @param string $version      The version of WordPress that deprecated the function.
	 * @param string $parent_class The parent class calling the deprecated constructor.
	 */
	do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
	/**
	 * Filters whether to trigger an error for deprecated functions.
	 *
	 * `WP_DEBUG` must be true in addition to the filter evaluating to true.
	 *
	 * @since 4.3.0
	 *
	 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
		if ( function_exists( '__' ) ) {
			if ( ! empty( $parent_class ) ) {
				/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
				trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
					$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
			} else {
				/* translators: 1: PHP class name, 2: version number, 3: __construct() method */
				trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
					$class, $version, '<pre>__construct()</pre>' ) );
			}
		} else {
			if ( ! empty( $parent_class ) ) {
				trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
					$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
			} else {
				trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
					$class, $version, '<pre>__construct()</pre>' ) );
			}
		}
	}
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/_deprecated_constructor/