Code Modernization: Rename parameters that use reserved keywords in bundled themes.

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 `$class` parameter to `$css_class` in:
 * `twentysixteen_excerpt()`
 * `twentynineteen_post_classes()`
* Renames the `$echo` parameter to `$display` in:
 * `twentythirteen_entry_date()`
 * `twentytwenty_generate_css()`
 * `twentytwenty_site_logo()`
 * `twentytwenty_site_description()`
 * `twenty_twenty_one_generate_css()`

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].

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


git-svn-id: http://core.svn.wordpress.org/trunk@52825 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-04-20 14:24:12 +00:00
parent 6ef5625ac2
commit 89f24e9c61
7 changed files with 23 additions and 23 deletions

View File

@ -35,7 +35,7 @@ add_filter( 'body_class', 'twentynineteen_body_classes' );
/** /**
* Adds custom class to the array of posts classes. * Adds custom class to the array of posts classes.
*/ */
function twentynineteen_post_classes( $classes, $class, $post_id ) { function twentynineteen_post_classes( $classes, $css_class, $post_id ) {
$classes[] = 'entry'; $classes[] = 'entry';
return $classes; return $classes;

View File

@ -161,16 +161,16 @@ if ( ! function_exists( 'twentysixteen_excerpt' ) ) :
* *
* @since Twenty Sixteen 1.0 * @since Twenty Sixteen 1.0
* *
* @param string $class Optional. Class string of the div element. Defaults to 'entry-summary'. * @param string $css_class Optional. Class string of the div element. Defaults to 'entry-summary'.
*/ */
function twentysixteen_excerpt( $class = 'entry-summary' ) { function twentysixteen_excerpt( $css_class = 'entry-summary' ) {
$class = esc_attr( $class ); $css_class = esc_attr( $css_class );
if ( has_excerpt() || is_search() ) : if ( has_excerpt() || is_search() ) :
?> ?>
<div class="<?php echo $class; ?>"> <div class="<?php echo $css_class; ?>">
<?php the_excerpt(); ?> <?php the_excerpt(); ?>
</div><!-- .<?php echo $class; ?> --> </div><!-- .<?php echo $css_class; ?> -->
<?php <?php
endif; endif;
} }

View File

@ -562,10 +562,10 @@ if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
* *
* @since Twenty Thirteen 1.0 * @since Twenty Thirteen 1.0
* *
* @param bool $echo (optional) Whether to echo the date. Default true. * @param bool $display (optional) Whether to display the date. Default true.
* @return string The HTML-formatted post date. * @return string The HTML-formatted post date.
*/ */
function twentythirteen_entry_date( $echo = true ) { function twentythirteen_entry_date( $display = true ) {
if ( has_post_format( array( 'chat', 'status' ) ) ) { if ( has_post_format( array( 'chat', 'status' ) ) ) {
/* translators: 1: Post format name, 2: Date. */ /* translators: 1: Post format name, 2: Date. */
$format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' ); $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
@ -582,7 +582,7 @@ if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) ) esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
); );
if ( $echo ) { if ( $display ) {
echo $date; echo $date;
} }

View File

@ -19,9 +19,9 @@ if ( ! function_exists( 'twentytwenty_generate_css' ) ) {
* @param string $value The CSS value. * @param string $value The CSS value.
* @param string $prefix The CSS prefix. * @param string $prefix The CSS prefix.
* @param string $suffix The CSS suffix. * @param string $suffix The CSS suffix.
* @param bool $echo Echo the styles. * @param bool $display Output the styles.
*/ */
function twentytwenty_generate_css( $selector, $style, $value, $prefix = '', $suffix = '', $echo = true ) { function twentytwenty_generate_css( $selector, $style, $value, $prefix = '', $suffix = '', $display = true ) {
$return = ''; $return = '';
@ -35,7 +35,7 @@ if ( ! function_exists( 'twentytwenty_generate_css' ) ) {
$return = sprintf( '%s { %s: %s; }', $selector, $style, $prefix . $value . $suffix ); $return = sprintf( '%s { %s: %s; }', $selector, $style, $prefix . $value . $suffix );
if ( $echo ) { if ( $display ) {
echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- We need to double check this, but for now, we want to pass PHPCS ;) echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- We need to double check this, but for now, we want to pass PHPCS ;)

View File

@ -28,10 +28,10 @@
* @since Twenty Twenty 1.0 * @since Twenty Twenty 1.0
* *
* @param array $args Arguments for displaying the site logo either as an image or text. * @param array $args Arguments for displaying the site logo either as an image or text.
* @param bool $echo Echo or return the HTML. * @param bool $display Display or return the HTML.
* @return string Compiled HTML based on our arguments. * @return string Compiled HTML based on our arguments.
*/ */
function twentytwenty_site_logo( $args = array(), $echo = true ) { function twentytwenty_site_logo( $args = array(), $display = true ) {
$logo = get_custom_logo(); $logo = get_custom_logo();
$site_title = get_bloginfo( 'name' ); $site_title = get_bloginfo( 'name' );
$contents = ''; $contents = '';
@ -83,7 +83,7 @@ function twentytwenty_site_logo( $args = array(), $echo = true ) {
*/ */
$html = apply_filters( 'twentytwenty_site_logo', $html, $args, $classname, $contents ); $html = apply_filters( 'twentytwenty_site_logo', $html, $args, $classname, $contents );
if ( ! $echo ) { if ( ! $display ) {
return $html; return $html;
} }
@ -96,10 +96,10 @@ function twentytwenty_site_logo( $args = array(), $echo = true ) {
* *
* @since Twenty Twenty 1.0 * @since Twenty Twenty 1.0
* *
* @param bool $echo Echo or return the html. * @param bool $display Display or return the HTML.
* @return string The HTML to display. * @return string The HTML to display.
*/ */
function twentytwenty_site_description( $echo = true ) { function twentytwenty_site_description( $display = true ) {
$description = get_bloginfo( 'description' ); $description = get_bloginfo( 'description' );
if ( ! $description ) { if ( ! $description ) {
@ -121,7 +121,7 @@ function twentytwenty_site_description( $echo = true ) {
*/ */
$html = apply_filters( 'twentytwenty_site_description', $html, $description, $wrapper ); $html = apply_filters( 'twentytwenty_site_description', $html, $description, $wrapper );
if ( ! $echo ) { if ( ! $display ) {
return $html; return $html;
} }

View File

@ -17,10 +17,10 @@
* @param string $value The CSS value. * @param string $value The CSS value.
* @param string $prefix The CSS prefix. * @param string $prefix The CSS prefix.
* @param string $suffix The CSS suffix. * @param string $suffix The CSS suffix.
* @param bool $echo Echo the styles. * @param bool $display Output the styles.
* @return string * @return string
*/ */
function twenty_twenty_one_generate_css( $selector, $style, $value, $prefix = '', $suffix = '', $echo = true ) { function twenty_twenty_one_generate_css( $selector, $style, $value, $prefix = '', $suffix = '', $display = true ) {
// Bail early if there is no $selector elements or properties and $value. // Bail early if there is no $selector elements or properties and $value.
if ( ! $value || ! $selector ) { if ( ! $value || ! $selector ) {
@ -29,7 +29,7 @@ function twenty_twenty_one_generate_css( $selector, $style, $value, $prefix = ''
$css = sprintf( '%s { %s: %s; }', $selector, $style, $prefix . $value . $suffix ); $css = sprintf( '%s { %s: %s; }', $selector, $style, $prefix . $value . $suffix );
if ( $echo ) { if ( $display ) {
/* /*
* Note to reviewers: $css contains auto-generated CSS. * Note to reviewers: $css contains auto-generated CSS.
* It is included inside <style> tags and can only be interpreted as CSS on the browser. * It is included inside <style> tags and can only be interpreted as CSS on the browser.

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-beta2-53235'; $wp_version = '6.0-beta2-53236';
/** /**
* 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.