Make WordPress Core


Ignore:
Timestamp:
06/25/2016 07:56:19 PM (8 years ago)
Author:
boonebgorges
Message:

Allow action and filter hooks to be deprecated.

When a filter or action hook is deprecated, the corresponding apply_filters()
or do_action() calls should be switched out with apply_filters_deprecated()
or do_action_deprecated(). The latter functions will throw a deprecation
before invoking the original hook.

Props solarissmoke, SergeyBiryukov, DrewAPicture.
Fixes #10441.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r37717 r37861  
    38943894
    38953895/**
     3896 * Marks a deprecated action or filter hook as deprecated and throws a notice.
     3897 *
     3898 * Use the 'deprecated_hook_run' action to get the backtrace describing where the
     3899 * deprecated hook was called.
     3900 *
     3901 * Default behavior is to trigger a user error if WP_DEBUG is true.
     3902 *
     3903 * This function is called by the do_action_deprecated() and apply_filters_deprecated()
     3904 * functions, and so generally does not need to be called directly.
     3905 *
     3906 * @since 4.6.0
     3907 * @access private
     3908 *
     3909 * @param string $hook        The hook that was used.
     3910 * @param string $version     The version of WordPress that deprecated the hook.
     3911 * @param string $replacement Optional. The hook that should have been used.
     3912 * @param string $message     Optional. A message regarding the change.
     3913 */
     3914function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
     3915    /**
     3916     * Fires when a deprecated hook is called.
     3917     *
     3918     * @since 4.6.0
     3919     *
     3920     * @param string $hook        The hook that was called.
     3921     * @param string $replacement The hook that should be used as a replacement.
     3922     * @param string $version     The version of WordPress that deprecated the argument used.
     3923     * @param string $message     A message regarding the change.
     3924     */
     3925    do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
     3926
     3927    /**
     3928     * Filter whether to trigger deprecated hook errors.
     3929     *
     3930     * @since 4.6.0
     3931     *
     3932     * @param bool $trigger Whether to trigger deprecated hook errors. Requires
     3933     *                      `WP_DEBUG` to be defined true.
     3934     */
     3935    if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
     3936        $message = empty( $message ) ? '' : ' ' . $message;
     3937        if ( ! is_null( $replacement ) ) {
     3938            trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
     3939        } else {
     3940            trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
     3941        }
     3942    }
     3943}
     3944
     3945/**
    38963946 * Mark something as being incorrectly called.
    38973947 *
Note: See TracChangeset for help on using the changeset viewer.