From a6ebaefb92bce6511e91e183d388a8a7ef3f251e Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Sun, 28 Jun 2015 14:56:24 +0000 Subject: [PATCH] Add Deprecated Constructor Function This function is one that can be called in core to indicate that a PHP4 style constructor is used. PHP4 style constructors are deprecated in PHP7. Props jorbin, DrewAPicture for docs See #31982 Built from https://develop.svn.wordpress.org/trunk@32989 git-svn-id: http://core.svn.wordpress.org/trunk@32960 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 46 +++++++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 1dce3aa161..33619fa458 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3415,6 +3415,52 @@ function _deprecated_function( $function, $version, $replacement = null ) { } } +/** + * Marks a constructor as deprecated and informs when it has been used. + * + * Similar to _deprecated_function(), but with different strings. Used to + * remove PHP4 style constructors. + * + * The current behavior is to trigger a user error if WP_DEBUG is true. + * + * This function is to be used in every PHP4 style constructor method that is deprecated. + * + * @since 4.3.0 + * + * @access private + * + * @param string $class The class containing the deprecated constructor. + * @param string $version The version of WordPress that deprecated the function. + */ +function _deprecated_constructor( $class, $version ) { + + /** + * Fires when a deprecated constructor is called. + * + * @since 4.3.0 + * + * @param string $class The class containing the deprecated constructor. + * @param string $version The version of WordPress that deprecated the function. + */ + do_action( 'deprecated_constructor_run', $class, $version ); + + /** + * Filter whether to trigger an error for deprecated functions. + * + * @since 4.3.0 + * + * @param bool $trigger Whether to trigger the error for deprecated functions. Default true. + */ + if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) { + if ( function_exists( '__' ) ) { + trigger_error( sprintf( __( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.' ), $class, $version, '
__construct()
' ) ); + } else { + trigger_error( sprintf( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.', $class, $version, '
__construct()
' ) ); + } + } + +} + /** * Mark a file as deprecated and inform when it has been used. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 95645556c8..679e53f040 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32988'; +$wp_version = '4.3-alpha-32989'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.