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_hook() WordPress Function

The _deprecated_hook() function is used to trigger a user-defined function when a deprecated hook is called. Deprecated hooks are those that have been replaced by newer hooks or have been removed altogether. The function takes two arguments: the old hook name and the new hook name. If the new hook name is present, it will be used instead of the old one. If the new hook name is not present, the function will return false.

_deprecated_hook( string $hook, string $version, string $replacement = '', string $message = '' ) #

Marks a deprecated action or filter hook as deprecated and throws a notice.


Description

Use the ‘deprecated_hook_run’ action to get the backtrace describing where the deprecated hook was called.

Default behavior is to trigger a user error if WP_DEBUG is true.

This function is called by the do_action_deprecated() and apply_filters_deprecated() functions, and so generally does not need to be called directly.


Top ↑

Parameters

$hook

(string)(Required)The hook that was used.

$version

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

$replacement

(string)(Optional) The hook that should have been used.

Default value: ''

$message

(string)(Optional) A message regarding the change.

Default value: ''


Top ↑

Source

File: wp-includes/functions.php

function _deprecated_hook( $hook, $version, $replacement = '', $message = '' ) {
	/**
	 * Fires when a deprecated hook is called.
	 *
	 * @since 4.6.0
	 *
	 * @param string $hook        The hook that was called.
	 * @param string $replacement The hook that should be used as a replacement.
	 * @param string $version     The version of WordPress that deprecated the argument used.
	 * @param string $message     A message regarding the change.
	 */
	do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );

	/**
	 * Filters whether to trigger deprecated hook errors.
	 *
	 * @since 4.6.0
	 *
	 * @param bool $trigger Whether to trigger deprecated hook errors. Requires
	 *                      `WP_DEBUG` to be defined true.
	 */
	if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
		$message = empty( $message ) ? '' : ' ' . $message;

		if ( $replacement ) {
			trigger_error(
				sprintf(
					/* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
					__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
					$hook,
					$version,
					$replacement
				) . $message,
				E_USER_DEPRECATED
			);
		} else {
			trigger_error(
				sprintf(
					/* translators: 1: WordPress hook name, 2: Version number. */
					__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
					$hook,
					$version
				) . $message,
				E_USER_DEPRECATED
			);
		}
	}
}


Top ↑

Changelog

Changelog
VersionDescription
5.4.0The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More