_deprecated_argument

函式
_deprecated_argument ( $function, $version, $message = '' )
引數
  • (string) $function The function that was called.
    Required:
  • (string) $version The version of WordPress that deprecated the argument used.
    Required:
  • (string) $message Optional. A message regarding the change. Default empty.
    Required:
    Default: (empty)
定義位置
相關方法
rest_handle_deprecated_argument_deprecated_function_deprecated_file_deprecated_hook_deprecated_constructor
引入
3.0.0
棄用
-

deprecated_argument: 一個函式,當使用已棄用的函式引數時,會觸發一個棄用通知。

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

每當使用一個棄用的函式引數時,都要使用這個函式。在這個函式被呼叫之前,必須通過與預設值比較或評估引數是否為空來檢查引數是否被使用。

比如說

if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, ‘3.0.0’ )。
}

有一個將被呼叫的鉤子deprecated_argument_run,可以用來獲取回溯,直到哪個檔案和函式使用了這個被棄用的引數。

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

function _deprecated_argument( $function, $version, $message = '' ) {

	/**
	 * Fires when a deprecated argument is called.
	 *
	 * @since 3.0.0
	 *
	 * @param string $function The function that was called.
	 * @param string $message  A message regarding the change.
	 * @param string $version  The version of WordPress that deprecated the argument used.
	 */
	do_action( 'deprecated_argument_run', $function, $message, $version );

	/**
	 * Filters whether to trigger an error for deprecated arguments.
	 *
	 * @since 3.0.0
	 *
	 * @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
		if ( function_exists( '__' ) ) {
			if ( $message ) {
				trigger_error(
					sprintf(
						/* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
						__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
						$function,
						$version,
						$message
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						/* translators: 1: PHP function name, 2: Version number. */
						__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
						$function,
						$version
					),
					E_USER_DEPRECATED
				);
			}
		} else {
			if ( $message ) {
				trigger_error(
					sprintf(
						'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
						$function,
						$version,
						$message
					),
					E_USER_DEPRECATED
				);
			} else {
				trigger_error(
					sprintf(
						'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
						$function,
						$version
					),
					E_USER_DEPRECATED
				);
			}
		}
	}
}

常見問題

FAQs
檢視更多 >