^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助,如果有代码出错,请联系站长解决
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数_deprecated_constructor()用法示例

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

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

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

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


描述

Similar to _deprecated_function(), but with different strings. Used to remove PHP4 style constructors.

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

This function is to be used in every PHP4 style constructor method that is deprecated.


参数

$class

(string)
(Required)
The class containing the deprecated constructor.

$version

(string)
(Required)
The version of WordPress that deprecated the function.

$parent_class

(string)
(Optional)
The parent class calling the deprecated constructor.

Default value: ''


源代码

File: wp-includes/functions.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>' ) );
			}
		}
	}

}

更新日志

Version 描述
4.5.0 Added the $parent_class parameter.
4.3.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    deprecated_constructor_run
  • wp-includes/functions.php:
    deprecated_constructor_trigger_error
  • wp-includes/l10n.php:
    __()
  • wp-includes/plugin.php:
    do_action()
  • wp-includes/plugin.php:
    apply_filters()

Used By

  • wp-includes/class-wp-widget-factory.php:
    WP_Widget_Factory::WP_Widget_Factory()
  • wp-includes/class-wp-widget.php:
    WP_Widget::WP_Widget()

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈