_deprecated_constructor

函式
_deprecated_constructor ( $class, $version, $parent_class = '' )
引數
  • (string) $class The class containing the deprecated constructor.
    Required:
  • (string) $version The version of WordPress that deprecated the function.
    Required:
  • (string) $parent_class Optional. The parent class calling the deprecated constructor. Default empty string.
    Required:
    Default: (empty)
定義位置
相關方法
_deprecated_function_deprecated_hook_deprecated_argumentprep_atom_text_construct_deprecated_file
引入
4.3.0
棄用
-

deprecated_constructor: 當使用已棄用的建構函式時,觸發一個棄用通知的函式。

將一個建構函式標記為棄用的,並在它被使用時進行通知。

類似於 _deprecated_function(),但使用不同的字串。用來刪除PHP4風格的建構函式。

目前的行為是,如果 `WP_DEBUG`為真,則觸發使用者錯誤。

這個函式要用在每個被棄用的PHP4風格的建構函式方法中。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 ( $parent_class ) {
trigger_error(
sprintf(
/* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */
__( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
$class,
$parent_class,
$version,
'<code>__construct()</code>'
),
E_USER_DEPRECATED
);
} else {
trigger_error(
sprintf(
/* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */
__( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
$class,
$version,
'<code>__construct()</code>'
),
E_USER_DEPRECATED
);
}
} else {
if ( $parent_class ) {
trigger_error(
sprintf(
'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
$class,
$parent_class,
$version,
'<code>__construct()</code>'
),
E_USER_DEPRECATED
);
} else {
trigger_error(
sprintf(
'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$class,
$version,
'<code>__construct()</code>'
),
E_USER_DEPRECATED
);
}
}
}
}
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 ( $parent_class ) { trigger_error( sprintf( /* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */ __( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ), $class, $parent_class, $version, '<code>__construct()</code>' ), E_USER_DEPRECATED ); } else { trigger_error( sprintf( /* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */ __( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $class, $version, '<code>__construct()</code>' ), E_USER_DEPRECATED ); } } else { if ( $parent_class ) { trigger_error( sprintf( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', $class, $parent_class, $version, '<code>__construct()</code>' ), E_USER_DEPRECATED ); } else { trigger_error( sprintf( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class, $version, '<code>__construct()</code>' ), E_USER_DEPRECATED ); } } } }
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 ( $parent_class ) {
				trigger_error(
					sprintf(
						/* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */
						__( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
						$class,
						$parent_class,
						$version,
						'<code>__construct()</code>'
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						/* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */
						__( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
						$class,
						$version,
						'<code>__construct()</code>'
					),
					E_USER_DEPRECATED
				);
			}
		} else {
			if ( $parent_class ) {
				trigger_error(
					sprintf(
						'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
						$class,
						$parent_class,
						$version,
						'<code>__construct()</code>'
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
						$class,
						$version,
						'<code>__construct()</code>'
					),
					E_USER_DEPRECATED
				);
			}
		}
	}

}

常見問題

FAQs
檢視更多 >