Introduce a `$parent_class` parameter for `_deprecated_constructor()`.

Use the parameter for the deprecated constructor warning in `WP_Widget` to provide an indication to which widget is using the PHP4 style constructor.

Props sebastian.pisula.
Fixes #33440.
Built from https://develop.svn.wordpress.org/trunk@36541


git-svn-id: http://core.svn.wordpress.org/trunk@36508 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-02-16 23:20:26 +00:00
parent 8a52014638
commit 9e73dea03a
3 changed files with 30 additions and 10 deletions

View File

@ -168,7 +168,7 @@ class WP_Widget {
* @param array $control_options
*/
public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) {
_deprecated_constructor( 'WP_Widget', '4.3.0' );
_deprecated_constructor( 'WP_Widget', '4.3.0', get_class( $this ) );
WP_Widget::__construct( $id_base, $name, $widget_options, $control_options );
}

View File

@ -3628,22 +3628,28 @@ function _deprecated_function( $function, $version, $replacement = null ) {
* This function is to be used in every PHP4 style constructor method that is deprecated.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @access private
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class Optional. The parent class calling the deprecated constructor.
* Default empty string.
*/
function _deprecated_constructor( $class, $version ) {
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
/**
* Fires when a deprecated constructor is called.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class The parent class calling the deprecated constructor.
*/
do_action( 'deprecated_constructor_run', $class, $version );
do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
/**
* Filter whether to trigger an error for deprecated functions.
@ -3656,9 +3662,23 @@ function _deprecated_constructor( $class, $version ) {
*/
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $class, $version, '<pre>__construct()</pre>' ) );
if ( ! empty( $parent_class ) ) {
/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
/* translators: 1: PHP class name, 2: version number, 3: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
$class, $version, '<pre>__construct()</pre>' ) );
}
} else {
trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class, $version, '<pre>__construct()</pre>' ) );
if ( ! empty( $parent_class ) ) {
trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$class, $version, '<pre>__construct()</pre>' ) );
}
}
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-alpha-36540';
$wp_version = '4.5-alpha-36541';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.