WordPress.org

Make WordPress Core

Ticket #11386: function-deprecated_argument.diff

File function-deprecated_argument.diff, 2.5 KB (added by nacin, 8 years ago)

New function, _deprecated_argument( $function, $argument, $version, $replacement = null )

  • functions.php

     
    30083008                        trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) );
    30093009        }
    30103010}
     3011/**
     3012 * Marks a function argument as deprecated and informs when it has been used.
     3013 *
     3014 * This function is to be used whenever a deprecated function argument is used.
     3015 * Before this function is called, the argument must be checked for whether it was
     3016 * used by comparing it to its default value or evaluating whether it is empty.
     3017 * For example:
     3018 * <code>
     3019 * if ( !empty($deprecated) )
     3020 *      _deprecated_argument( __FUNCTION__, 'deprecated', '0.0' );
     3021 * </code>
     3022 *
     3023 * There is a hook deprecated_argument_run that will be called that can be used
     3024 * to get the backtrace up to what file and function used the deprecated
     3025 * argument.
     3026 *
     3027 * The current behavior is to trigger an user error if WP_DEBUG is true.
     3028 *
     3029 * @package WordPress
     3030 * @package Debug
     3031 * @since 3.0.0
     3032 * @access private
     3033 *
     3034 * @uses do_action() Calls 'deprecated_argument_run' and passes the function and argument names and what to use instead.
     3035 * @uses apply_filters() Calls 'deprecated_argument_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
     3036 *
     3037 * @param string $function The function that was called
     3038 * @param string $argument The name of the deprecated argument that was used
     3039 * @param string $version The version of WordPress that deprecated the function
     3040 * @param string $replacement Optional. The function that should have been called
     3041 */
     3042function _deprecated_argument($function, $argument, $version, $replacement = null) {
    30113043
     3044    do_action('deprecated_argument_run', $function, $argument, $replacement);
     3045
     3046    // Allow plugin to filter the output error trigger
     3047    if( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
     3048        if( !is_null($replacement) )
     3049            trigger_error( sprintf( __('The %1$s argument of %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.'), $function, $argument, $version, $replacement ) );
     3050        else
     3051            trigger_error( sprintf( __('The %1$s argument of %2$s is <strong>deprecated</strong> since version %3$s with no alternative available.'), $function, $argument, $version ) );
     3052    }
     3053}
     3054
    30123055/**
    30133056 * Is the server running earlier than 1.5.0 version of lighttpd
    30143057 *