WordPress.org

Make WordPress Core

Ticket #41125: 0001-Add-new-_deprecated_class-function.patch

File 0001-Add-new-_deprecated_class-function.patch, 3.2 KB (added by jrf, 3 years ago)

Patch to add the proposed _deprecated_class() function

  • src/wp-includes/functions.php

    From d79ad8242bbdb7b5461b9db2d2db4649f093e536 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Wed, 21 Jun 2017 23:16:40 +0200
    Subject: [PATCH] Add new `_deprecated_class()` function.
    
    ---
     src/wp-includes/functions.php | 57 +++++++++++++++++++++++++++++++++++++++++++
     1 file changed, 57 insertions(+)
    
    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 828f123..21ba238 100644
    a b function _deprecated_hook( $hook, $version, $replacement = null, $message = null 
    40904090}
    40914091
    40924092/**
     4093 * Mark a class as deprecated and inform when it has been used.
     4094 *
     4095 * There is a {@see 'hook deprecated_class_run'} that will be called that can be used
     4096 * to get the backtrace up to what file and function called the deprecated
     4097 * class.
     4098 *
     4099 * The current behavior is to trigger a user error if `WP_DEBUG` is true.
     4100 *
     4101 * This function is to be used in the class constructor for every class that is deprecated.
     4102 *
     4103 * @since 4.9.0
     4104 * @access private
     4105 *
     4106 * @param string $class       The class being instantiated.
     4107 * @param string $version     The version of WordPress that deprecated the class.
     4108 * @param string $replacement Optional. The class or function that should have been called. Default null.
     4109 */
     4110function _deprecated_class( $class, $version, $replacement = null ) {
     4111
     4112        /**
     4113         * Fires when a deprecated class is called.
     4114         *
     4115         * @since 4.9.0
     4116         *
     4117         * @param string $class       The class being instantiated.
     4118         * @param string $replacement The class or function that should have been called.
     4119         * @param string $version     The version of WordPress that deprecated the class.
     4120         */
     4121        do_action( 'deprecated_class_run', $function, $replacement, $version );
     4122
     4123        /**
     4124         * Filters whether to trigger an error for deprecated classes.
     4125         *
     4126         * @since 4.9.0
     4127         *
     4128         * @param bool $trigger Whether to trigger the error for deprecated classes. Default true.
     4129         */
     4130        if ( WP_DEBUG && apply_filters( 'deprecated_class_trigger_error', true ) ) {
     4131                if ( function_exists( '__' ) ) {
     4132                        if ( ! is_null( $replacement ) ) {
     4133                                /* translators: 1: PHP class name, 2: version number, 3: alternative clas or function name */
     4134                                trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ), E_USER_DEPRECATED );
     4135                        } else {
     4136                                /* translators: 1: PHP class name, 2: version number */
     4137                                trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ), E_USER_DEPRECATED );
     4138                        }
     4139                } else {
     4140                        if ( ! is_null( $replacement ) ) {
     4141                                trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ), E_USER_DEPRECATED );
     4142                        } else {
     4143                                trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ), E_USER_DEPRECATED );
     4144                        }
     4145                }
     4146        }
     4147}
     4148
     4149/**
    40934150 * Mark something as being incorrectly called.
    40944151 *
    40954152 * There is a hook {@see 'doing_it_wrong_run'} that will be called that can be used