_deprecated_function

函式
_deprecated_function ( $function, $version, $replacement = '' )
引數
  • (string) $function The function that was called.
    Required:
  • (string) $version The version of WordPress that deprecated the function.
    Required:
  • (string) $replacement Optional. The function that should have been called. Default empty.
    Required:
    Default: (empty)
定義位置
相關方法
_deprecated_filerest_handle_deprecated_function_deprecated_argument_deprecated_hook_deprecated_constructor
引入
2.5.0
棄用
-

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

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

有一個鉤子{@see ‘deprecated_function_run’}將被呼叫,可以用來獲取回溯,直到哪個檔案和函式呼叫了被棄用的函式。

目前的行為是,如果`WP_DEBUG’為真,就會觸發一個使用者錯誤。

這個函式將被用於每個被棄用的函式中。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _deprecated_function( $function, $version, $replacement = '' ) {
/**
* Fires when a deprecated function is called.
*
* @since 2.5.0
*
* @param string $function The function that was called.
* @param string $replacement The function that should have been called.
* @param string $version The version of WordPress that deprecated the function.
*/
do_action( 'deprecated_function_run', $function, $replacement, $version );
/**
* Filters whether to trigger an error for deprecated functions.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( $replacement ) {
trigger_error(
sprintf(
/* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
__( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
$function,
$version,
$replacement
),
E_USER_DEPRECATED
);
} else {
trigger_error(
sprintf(
/* translators: 1: PHP function name, 2: Version number. */
__( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
$function,
$version
),
E_USER_DEPRECATED
);
}
} else {
if ( $replacement ) {
trigger_error(
sprintf(
'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$function,
$version,
$replacement
),
E_USER_DEPRECATED
);
} else {
trigger_error(
sprintf(
'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
$function,
$version
),
E_USER_DEPRECATED
);
}
}
}
}
function _deprecated_function( $function, $version, $replacement = '' ) { /** * Fires when a deprecated function is called. * * @since 2.5.0 * * @param string $function The function that was called. * @param string $replacement The function that should have been called. * @param string $version The version of WordPress that deprecated the function. */ do_action( 'deprecated_function_run', $function, $replacement, $version ); /** * Filters whether to trigger an error for deprecated functions. * * @since 2.5.0 * * @param bool $trigger Whether to trigger the error for deprecated functions. Default true. */ if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { if ( function_exists( '__' ) ) { if ( $replacement ) { trigger_error( sprintf( /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ __( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $function, $version, $replacement ), E_USER_DEPRECATED ); } else { trigger_error( sprintf( /* translators: 1: PHP function name, 2: Version number. */ __( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ), E_USER_DEPRECATED ); } } else { if ( $replacement ) { trigger_error( sprintf( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ), E_USER_DEPRECATED ); } else { trigger_error( sprintf( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ), E_USER_DEPRECATED ); } } } }
function _deprecated_function( $function, $version, $replacement = '' ) {

	/**
	 * Fires when a deprecated function is called.
	 *
	 * @since 2.5.0
	 *
	 * @param string $function    The function that was called.
	 * @param string $replacement The function that should have been called.
	 * @param string $version     The version of WordPress that deprecated the function.
	 */
	do_action( 'deprecated_function_run', $function, $replacement, $version );

	/**
	 * Filters whether to trigger an error for deprecated functions.
	 *
	 * @since 2.5.0
	 *
	 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
		if ( function_exists( '__' ) ) {
			if ( $replacement ) {
				trigger_error(
					sprintf(
						/* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
						__( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
						$function,
						$version,
						$replacement
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						/* translators: 1: PHP function name, 2: Version number. */
						__( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
						$function,
						$version
					),
					E_USER_DEPRECATED
				);
			}
		} else {
			if ( $replacement ) {
				trigger_error(
					sprintf(
						'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
						$function,
						$version,
						$replacement
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
						$function,
						$version
					),
					E_USER_DEPRECATED
				);
			}
		}
	}
}

常見問題

FAQs
檢視更多 >