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/plugin.php

    r37674 r37861  
    654654function remove_all_actions($tag, $priority = false) {
    655655    return remove_all_filters($tag, $priority);
     656}
     657
     658/**
     659 * Fires functions attached to a deprecated filter hook.
     660 *
     661 * When a filter hook is deprecated, the apply_filters() call is replaced with
     662 * apply_filters_deprecated(), which triggers a deprecation notice and then fires
     663 * the original filter hook.
     664 *
     665 * @since 4.6.0
     666 *
     667 * @see _deprecated_hook()
     668 *
     669 * @param string $tag         The name of the filter hook.
     670 * @param array  $args        Array of additional function arguments to be passed to apply_filters().
     671 * @param string $version     The version of WordPress that deprecated the hook.
     672 * @param string $replacement Optional. The hook that should have been used.
     673 * @param string $message     Optional. A message regarding the change.
     674 */
     675function apply_filters_deprecated( $tag, $args, $version, $replacement = false, $message = null ) {
     676    if ( ! has_filter( $tag ) ) {
     677        return;
     678    }
     679
     680    _deprecated_hook( $tag, $version, $replacement, $message );
     681
     682    return apply_filters_ref_array( $tag, $args );
     683}
     684
     685/**
     686 * Fires functions attached to a deprecated action hook.
     687 *
     688 * When an action hook is deprecated, the do_action() call is replaced with
     689 * do_action_deprecated(), which triggers a deprecation notice and then fires
     690 * the original hook.
     691 *
     692 * @since 4.6.0
     693 *
     694 * @see _deprecated_hook()
     695 *
     696 * @param string $tag         The name of the action hook.
     697 * @param array  $args        Array of additional function arguments to be passed to do_action().
     698 * @param string $version     The version of WordPress that deprecated the hook.
     699 * @param string $replacement Optional. The hook that should have been used.
     700 * @param string $message     Optional. A message regarding the change.
     701 */
     702function do_action_deprecated( $tag, $args, $version, $replacement = false, $message = null ) {
     703    if ( ! has_action( $tag ) ) {
     704        return;
     705    }
     706
     707    _deprecated_hook( $tag, $version, $replacement, $message );
     708
     709    do_action_ref_array( $tag, $args );
    656710}
    657711
Note: See TracChangeset for help on using the changeset viewer.