WordPress.org

Make WordPress Core

Ticket #10441: 10441.diff

File 10441.diff, 3.9 KB (added by DrewAPicture, 20 months ago)

Refresh + docs

  • src/wp-includes/functions.php

     
    35753575} 
    35763576 
    35773577/** 
     3578 * Marks a hook as deprecated and informs when it has been used. 
     3579 * 
     3580 * There is a hook deprecated_hook_used that will be called that can be used 
     3581 * to get the backtrace up to what file and function was used for the callback. 
     3582 * 
     3583 * The current behavior is to trigger a user error if WP_DEBUG is true. 
     3584 * 
     3585 * This function is to be used for every hook that is deprecated, when any callback is 
     3586 * attacked to the hook, as determined by has_action() or has_filter(), and shall be 
     3587 * called before the hook is fired. 
     3588 * 
     3589 * @since 4.4.0 
     3590 * 
     3591 * @param string $hook        The hook that was used. 
     3592 * @param string $version     The version of WordPress that deprecated the hook. 
     3593 * @param string $replacement Optional. The hook that should have been used. 
     3594 * @param string $message     Optional. A message regarding the change. 
     3595 */ 
     3596function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) { 
     3597        /** 
     3598         * Filter whether to trigger deprecated hook errors. 
     3599         * 
     3600         * @since 4.4.0 
     3601         * 
     3602         * @param bool $trigger Whether to trigger deprecated hook errors. Requires 
     3603         *                      `WP_DEBUG` to be defined true. 
     3604         */ 
     3605        if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) { 
     3606                $message = empty( $message ) ? '' : ' ' . $message; 
     3607                if ( ! is_null( $replacement ) ) { 
     3608                        trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message ); 
     3609                } else { 
     3610                        trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message ); 
     3611                } 
     3612        } 
     3613} 
     3614 
     3615/** 
    35783616 * Mark something as being incorrectly called. 
    35793617 * 
    35803618 * There is a hook doing_it_wrong_run that will be called that can be used 
  • src/wp-includes/plugin.php

     
    656656        return remove_all_filters($tag, $priority); 
    657657} 
    658658 
     659/** 
     660 * Fires a deprecated filter. 
     661 * 
     662 * Wraps apply_filters(). 
     663 * 
     664 * @since 4.4.0 
     665 * 
     666 * @see _deprecated_hook() 
     667 * 
     668 * @param string $tag         The name of the filter hook. 
     669 * @param array  $args        Array of additional function arguments to be passed to apply_filters(). 
     670 * @param string $version     The version of WordPress that deprecated the hook. 
     671 * @param string $replacement Optional. The hook that should have been used. 
     672 * @param string $message     Optional. A message regarding the change. 
     673 */ 
     674function apply_deprecated_filters( $tag, $args, $version, $replacement = false, $message = null ) { 
     675        if ( ! has_filter( $tag ) ) { 
     676                return; 
     677        } 
     678        _deprecated_hook( $tag, $version, $replacement, $message ); 
     679 
     680        array_unshift( $args, $tag ); 
     681        return call_user_func_array( 'apply_filters', $args ); 
     682} 
     683 
     684/** 
     685 * Fires a deprecated action. 
     686 * 
     687 * Wraps do_action(). 
     688 * 
     689 * @since 4.4.0 
     690 * 
     691 * @see _deprecated_hook() 
     692 * 
     693 * @param string $tag         The name of the filter hook. 
     694 * @param array  $args        Array of additional function arguments to be passed to do_action(). 
     695 * @param string $version     The version of WordPress that deprecated the hook. 
     696 * @param string $replacement Optional. The hook that should have been used. 
     697 * @param string $message     Optional. A message regarding the change. 
     698 */ 
     699function do_deprecated_action( $tag, $args, $version, $replacement = false, $message = null ) { 
     700        if ( ! has_action( $tag ) ) { 
     701                return; 
     702        } 
     703 
     704        _deprecated_hook( $tag, $version, $replacement, $message ); 
     705 
     706        array_unshift( $args, $tag ); 
     707        call_user_func_array( 'do_action', $args ); 
     708} 
     709 
    659710// 
    660711// Functions for handling plugins. 
    661712//