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
This commit is contained in:
Sergey Biryukov 2020-07-05 21:07:48 +00:00
parent b1b1b08e43
commit 09921a5283
2 changed files with 26 additions and 30 deletions

View File

@ -4700,9 +4700,9 @@ function absint( $maybeint ) {
* *
* @param string $function The function that was called. * @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the function. * @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. * 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 ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) { if ( $replacement ) {
trigger_error( trigger_error(
sprintf( sprintf(
/* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
@ -4747,7 +4747,7 @@ function _deprecated_function( $function, $version, $replacement = null ) {
); );
} }
} else { } else {
if ( ! is_null( $replacement ) ) { if ( $replacement ) {
trigger_error( trigger_error(
sprintf( sprintf(
'%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', '%1$s is <strong>deprecated</strong> 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 ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( ! empty( $parent_class ) ) { if ( $parent_class ) {
trigger_error( trigger_error(
sprintf( sprintf(
/* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */ /* 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 { } else {
if ( ! empty( $parent_class ) ) { if ( $parent_class ) {
trigger_error( trigger_error(
sprintf( sprintf(
'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> 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 $file The file that was included.
* @param string $version The version of WordPress that deprecated the file. * @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. * @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. * @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. * Fires when a deprecated file is called.
@ -4914,7 +4914,7 @@ function _deprecated_file( $file, $version, $replacement = null, $message = '' )
$message = empty( $message ) ? '' : ' ' . $message; $message = empty( $message ) ? '' : ' ' . $message;
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) { if ( $replacement ) {
trigger_error( trigger_error(
sprintf( sprintf(
/* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ /* 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 { } else {
if ( ! is_null( $replacement ) ) { if ( $replacement ) {
trigger_error( trigger_error(
sprintf( sprintf(
'%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', '%1$s is <strong>deprecated</strong> 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 $function The function that was called.
* @param string $version The version of WordPress that deprecated the argument used. * @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. * 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 ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( ! is_null( $message ) ) { if ( $message ) {
trigger_error( trigger_error(
sprintf( sprintf(
/* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ /* 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 { } else {
if ( ! is_null( $message ) ) { if ( $message ) {
trigger_error( trigger_error(
sprintf( sprintf(
'%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', '%1$s was called with an argument that is <strong>deprecated</strong> 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 $hook The hook that was used.
* @param string $version The version of WordPress that deprecated the hook. * @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 $replacement Optional. The hook that should have been used. Default empty.
* @param string $message Optional. A message regarding the change. Default null. * @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. * 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 ) ) { if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message; $message = empty( $message ) ? '' : ' ' . $message;
if ( ! is_null( $replacement ) ) { if ( $replacement ) {
trigger_error( trigger_error(
sprintf( sprintf(
/* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ /* 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 ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function, $message, $version ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( is_null( $version ) ) { if ( $version ) {
$version = '';
} else {
/* translators: %s: Version number. */ /* translators: %s: Version number. */
$version = sprintf( __( '(This message was added in version %s.)' ), $version ); $version = sprintf( __( '(This message was added in version %s.)' ), $version );
} }
@ -5190,9 +5188,7 @@ function _doing_it_wrong( $function, $message, $version ) {
E_USER_NOTICE E_USER_NOTICE
); );
} else { } else {
if ( is_null( $version ) ) { if ( $version ) {
$version = '';
} else {
$version = sprintf( '(This message was added in version %s.)', $version ); $version = sprintf( '(This message was added in version %s.)', $version );
} }

View File

@ -620,10 +620,10 @@ function remove_all_actions( $tag, $priority = false ) {
* @param string $tag The name of the filter hook. * @param string $tag The name of the filter hook.
* @param array $args Array of additional function arguments to be passed to apply_filters(). * @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 $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used. 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 null. * @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 ) ) { if ( ! has_filter( $tag ) ) {
return $args[0]; 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 string $tag The name of the action hook.
* @param array $args Array of additional function arguments to be passed to do_action(). * @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 $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used. 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 null. * @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 ) ) { if ( ! has_action( $tag ) ) {
return; return;
} }