From 09921a528369ef66dab23ebe346b9c0436aa3d52 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 5 Jul 2020 21:07:48 +0000 Subject: [PATCH] Plugins: Consistently use an empty string as the default value for `$replacement` and `$message` parameters in: * `_deprecated_function()` * `_deprecated_constructor()` * `_deprecated_file()` * `_deprecated_argument()` * `_deprecated_hook()` * `apply_filters_deprecated()` * `do_action_deprecated()` This matches the documented type of `string` for these parameters and removes unnecessarily strict `! is_null()` checks. Follow-up to [46792]. Props jignesh.nakrani, renathoc, SergeyBiryukov. Fixes #49698. git-svn-id: https://develop.svn.wordpress.org/trunk@48327 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 44 ++++++++++++++++------------------- src/wp-includes/plugin.php | 12 +++++----- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 62f01fd77a..31f4bee377 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -4700,9 +4700,9 @@ function absint( $maybeint ) { * * @param string $function The function that was called. * @param string $version The version of WordPress that deprecated the function. - * @param string $replacement Optional. The function that should have been called. Default null. + * @param string $replacement Optional. The function that should have been called. Default empty. */ -function _deprecated_function( $function, $version, $replacement = null ) { +function _deprecated_function( $function, $version, $replacement = '' ) { /** * Fires when a deprecated function is called. @@ -4724,7 +4724,7 @@ function _deprecated_function( $function, $version, $replacement = null ) { */ if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { if ( function_exists( '__' ) ) { - if ( ! is_null( $replacement ) ) { + if ( $replacement ) { trigger_error( sprintf( /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ @@ -4747,7 +4747,7 @@ function _deprecated_function( $function, $version, $replacement = null ) { ); } } else { - if ( ! is_null( $replacement ) ) { + if ( $replacement ) { trigger_error( sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', @@ -4816,7 +4816,7 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { */ if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) { if ( function_exists( '__' ) ) { - if ( ! empty( $parent_class ) ) { + if ( $parent_class ) { trigger_error( sprintf( /* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */ @@ -4841,7 +4841,7 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { ); } } else { - if ( ! empty( $parent_class ) ) { + if ( $parent_class ) { trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is deprecated since version %3$s! Use %4$s instead.', @@ -4886,10 +4886,10 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { * @param string $file The file that was included. * @param string $version The version of WordPress that deprecated the file. * @param string $replacement Optional. The file that should have been included based on ABSPATH. - * Default null. + * Default empty. * @param string $message Optional. A message regarding the change. Default empty. */ -function _deprecated_file( $file, $version, $replacement = null, $message = '' ) { +function _deprecated_file( $file, $version, $replacement = '', $message = '' ) { /** * Fires when a deprecated file is called. @@ -4914,7 +4914,7 @@ function _deprecated_file( $file, $version, $replacement = null, $message = '' ) $message = empty( $message ) ? '' : ' ' . $message; if ( function_exists( '__' ) ) { - if ( ! is_null( $replacement ) ) { + if ( $replacement ) { trigger_error( sprintf( /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ @@ -4937,7 +4937,7 @@ function _deprecated_file( $file, $version, $replacement = null, $message = '' ) ); } } else { - if ( ! is_null( $replacement ) ) { + if ( $replacement ) { trigger_error( sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', @@ -4984,9 +4984,9 @@ function _deprecated_file( $file, $version, $replacement = null, $message = '' ) * * @param string $function The function that was called. * @param string $version The version of WordPress that deprecated the argument used. - * @param string $message Optional. A message regarding the change. Default null. + * @param string $message Optional. A message regarding the change. Default empty. */ -function _deprecated_argument( $function, $version, $message = null ) { +function _deprecated_argument( $function, $version, $message = '' ) { /** * Fires when a deprecated argument is called. @@ -5008,7 +5008,7 @@ function _deprecated_argument( $function, $version, $message = null ) { */ if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { if ( function_exists( '__' ) ) { - if ( ! is_null( $message ) ) { + if ( $message ) { trigger_error( sprintf( /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ @@ -5031,7 +5031,7 @@ function _deprecated_argument( $function, $version, $message = null ) { ); } } else { - if ( ! is_null( $message ) ) { + if ( $message ) { trigger_error( sprintf( '%1$s was called with an argument that is deprecated since version %2$s! %3$s', @@ -5072,10 +5072,10 @@ function _deprecated_argument( $function, $version, $message = null ) { * * @param string $hook The hook that was used. * @param string $version The version of WordPress that deprecated the hook. - * @param string $replacement Optional. The hook that should have been used. Default null. - * @param string $message Optional. A message regarding the change. Default null. + * @param string $replacement Optional. The hook that should have been used. Default empty. + * @param string $message Optional. A message regarding the change. Default empty. */ -function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) { +function _deprecated_hook( $hook, $version, $replacement = '', $message = '' ) { /** * Fires when a deprecated hook is called. * @@ -5099,7 +5099,7 @@ function _deprecated_hook( $hook, $version, $replacement = null, $message = null if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) { $message = empty( $message ) ? '' : ' ' . $message; - if ( ! is_null( $replacement ) ) { + if ( $replacement ) { trigger_error( sprintf( /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ @@ -5166,9 +5166,7 @@ function _doing_it_wrong( $function, $message, $version ) { */ if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function, $message, $version ) ) { if ( function_exists( '__' ) ) { - if ( is_null( $version ) ) { - $version = ''; - } else { + if ( $version ) { /* translators: %s: Version number. */ $version = sprintf( __( '(This message was added in version %s.)' ), $version ); } @@ -5190,9 +5188,7 @@ function _doing_it_wrong( $function, $message, $version ) { E_USER_NOTICE ); } else { - if ( is_null( $version ) ) { - $version = ''; - } else { + if ( $version ) { $version = sprintf( '(This message was added in version %s.)', $version ); } diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index 25c60a5813..6ba09d2b9a 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -620,10 +620,10 @@ function remove_all_actions( $tag, $priority = false ) { * @param string $tag The name of the filter hook. * @param array $args Array of additional function arguments to be passed to apply_filters(). * @param string $version The version of WordPress that deprecated the hook. - * @param string $replacement Optional. The hook that should have been used. Default null. - * @param string $message Optional. A message regarding the change. Default null. + * @param string $replacement Optional. The hook that should have been used. Default empty. + * @param string $message Optional. A message regarding the change. Default empty. */ -function apply_filters_deprecated( $tag, $args, $version, $replacement = null, $message = null ) { +function apply_filters_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) { if ( ! has_filter( $tag ) ) { return $args[0]; } @@ -647,10 +647,10 @@ function apply_filters_deprecated( $tag, $args, $version, $replacement = null, $ * @param string $tag The name of the action hook. * @param array $args Array of additional function arguments to be passed to do_action(). * @param string $version The version of WordPress that deprecated the hook. - * @param string $replacement Optional. The hook that should have been used. Default null. - * @param string $message Optional. A message regarding the change. Default null. + * @param string $replacement Optional. The hook that should have been used. Default empty. + * @param string $message Optional. A message regarding the change. Default empty. */ -function do_action_deprecated( $tag, $args, $version, $replacement = null, $message = null ) { +function do_action_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) { if ( ! has_action( $tag ) ) { return; }