Code Modernization: Rename parameters that use reserved keywords in wp-includes/class.wp-scripts.php.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit renames the `$echo` parameter to `$display` in `WP_Scripts` class methods.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53283


git-svn-id: http://core.svn.wordpress.org/trunk@52872 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-04-26 14:56:08 +00:00
parent 053b9bbd71
commit 6cdf9f1c86
2 changed files with 23 additions and 23 deletions

View File

@ -190,20 +190,20 @@ class WP_Scripts extends WP_Dependencies {
* Prints extra scripts of a registered script. * Prints extra scripts of a registered script.
* *
* @since 2.1.0 * @since 2.1.0
* @since 2.8.0 Added the `$echo` parameter. * @since 2.8.0 Added the `$display` parameter.
* @deprecated 3.3.0 * @deprecated 3.3.0
* *
* @see print_extra_script() * @see print_extra_script()
* *
* @param string $handle The script's registered handle. * @param string $handle The script's registered handle.
* @param bool $echo Optional. Whether to echo the extra script * @param bool $display Optional. Whether to print the extra script
* instead of just returning it. Default true. * instead of just returning it. Default true.
* @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, * @return bool|string|void Void if no data exists, extra scripts if `$display` is true,
* true otherwise. * true otherwise.
*/ */
public function print_scripts_l10n( $handle, $echo = true ) { public function print_scripts_l10n( $handle, $display = true ) {
_deprecated_function( __FUNCTION__, '3.3.0', 'WP_Scripts::print_extra_script()' ); _deprecated_function( __FUNCTION__, '3.3.0', 'WP_Scripts::print_extra_script()' );
return $this->print_extra_script( $handle, $echo ); return $this->print_extra_script( $handle, $display );
} }
/** /**
@ -211,19 +211,19 @@ class WP_Scripts extends WP_Dependencies {
* *
* @since 3.3.0 * @since 3.3.0
* *
* @param string $handle The script's registered handle. * @param string $handle The script's registered handle.
* @param bool $echo Optional. Whether to echo the extra script * @param bool $display Optional. Whether to print the extra script
* instead of just returning it. Default true. * instead of just returning it. Default true.
* @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, * @return bool|string|void Void if no data exists, extra scripts if `$display` is true,
* true otherwise. * true otherwise.
*/ */
public function print_extra_script( $handle, $echo = true ) { public function print_extra_script( $handle, $display = true ) {
$output = $this->get_data( $handle, 'data' ); $output = $this->get_data( $handle, 'data' );
if ( ! $output ) { if ( ! $output ) {
return; return;
} }
if ( ! $echo ) { if ( ! $display ) {
return $output; return $output;
} }
@ -444,11 +444,11 @@ class WP_Scripts extends WP_Dependencies {
* Must be lowercase. * Must be lowercase.
* @param string $position Optional. Whether to add the inline script * @param string $position Optional. Whether to add the inline script
* before the handle or after. Default 'after'. * before the handle or after. Default 'after'.
* @param bool $echo Optional. Whether to echo the script * @param bool $display Optional. Whether to print the script
* instead of just returning it. Default true. * instead of just returning it. Default true.
* @return string|false Script on success, false otherwise. * @return string|false Script on success, false otherwise.
*/ */
public function print_inline_script( $handle, $position = 'after', $echo = true ) { public function print_inline_script( $handle, $position = 'after', $display = true ) {
$output = $this->get_data( $handle, $position ); $output = $this->get_data( $handle, $position );
if ( empty( $output ) ) { if ( empty( $output ) ) {
@ -457,7 +457,7 @@ class WP_Scripts extends WP_Dependencies {
$output = trim( implode( "\n", $output ), "\n" ); $output = trim( implode( "\n", $output ), "\n" );
if ( $echo ) { if ( $display ) {
printf( "<script%s id='%s-js-%s'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output ); printf( "<script%s id='%s-js-%s'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output );
} }
@ -582,13 +582,13 @@ class WP_Scripts extends WP_Dependencies {
* *
* @since 5.0.0 * @since 5.0.0
* *
* @param string $handle Name of the script to add the inline script to. * @param string $handle Name of the script to add the inline script to.
* Must be lowercase. * Must be lowercase.
* @param bool $echo Optional. Whether to echo the script * @param bool $display Optional. Whether to print the script
* instead of just returning it. Default true. * instead of just returning it. Default true.
* @return string|false Script on success, false otherwise. * @return string|false Script on success, false otherwise.
*/ */
public function print_translations( $handle, $echo = true ) { public function print_translations( $handle, $display = true ) {
if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) { if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) {
return false; return false;
} }
@ -610,7 +610,7 @@ class WP_Scripts extends WP_Dependencies {
} )( "{$domain}", {$json_translations} ); } )( "{$domain}", {$json_translations} );
JS; JS;
if ( $echo ) { if ( $display ) {
printf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $output ); printf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $output );
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-beta2-53282'; $wp_version = '6.0-beta2-53283';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.