Skip to content

Commit 2b44eb0

Browse files
committed
REF: refactored Walker_Comment to use get_args() helper method
- Replaced duplicated wp_parse_args() calls with a single get_args() helper - All 7 methods now use $this->get_args( $args ) for consistency - Single source of defaults: style, avatar_size, format, short_ping, max_depth Affected: src/wp-includes/class-walker-comment.php
1 parent e8a65ce commit 2b44eb0

1 file changed

Lines changed: 28 additions & 47 deletions

File tree

src/wp-includes/class-walker-comment.php

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ class Walker_Comment extends Walker {
4040
'id' => 'comment_ID',
4141
);
4242

43+
/**
44+
* Parses arguments with defaults.
45+
*
46+
* @since unreleased
47+
*
48+
* @param array $args Arguments to parse.
49+
* @return array Parsed arguments.
50+
*/
51+
protected function get_args( array $args ): array {
52+
return array_merge(
53+
array(
54+
'style' => 'ul',
55+
'avatar_size' => 32,
56+
'format' => 'xhtml',
57+
'short_ping' => false,
58+
'max_depth' => '',
59+
),
60+
$args
61+
);
62+
}
63+
4364
/**
4465
* Starts the list before the elements are added.
4566
*
@@ -53,12 +74,7 @@ class Walker_Comment extends Walker {
5374
* @param array $args Optional. Uses 'style' argument for type of HTML list. Default empty array.
5475
*/
5576
public function start_lvl( &$output, $depth = 0, $args = array() ) {
56-
$args = wp_parse_args(
57-
$args,
58-
array(
59-
'style' => 'ul',
60-
)
61-
);
77+
$args = $this->get_args( $args );
6278

6379
$GLOBALS['comment_depth'] = $depth + 1;
6480

@@ -89,12 +105,7 @@ public function start_lvl( &$output, $depth = 0, $args = array() ) {
89105
* Default empty array.
90106
*/
91107
public function end_lvl( &$output, $depth = 0, $args = array() ) {
92-
$args = wp_parse_args(
93-
$args,
94-
array(
95-
'style' => 'ul',
96-
)
97-
);
108+
$args = $this->get_args( $args );
98109

99110
$GLOBALS['comment_depth'] = $depth + 1;
100111

@@ -185,13 +196,7 @@ public function display_element( $element, &$children_elements, $max_depth, $dep
185196
* @param int $current_object_id Optional. ID of the current comment. Default 0.
186197
*/
187198
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
188-
$args = wp_parse_args(
189-
$args,
190-
array(
191-
'short_ping' => false,
192-
'format' => 'xhtml',
193-
)
194-
);
199+
$args = $this->get_args( $args );
195200

196201
// Restores the more descriptive, specific name for use within this method.
197202
$comment = $data_object;
@@ -245,12 +250,7 @@ public function start_el( &$output, $data_object, $depth = 0, $args = array(), $
245250
* @param array $args Optional. An array of arguments. Default empty array.
246251
*/
247252
public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
248-
$args = wp_parse_args(
249-
$args,
250-
array(
251-
'style' => 'ul',
252-
)
253-
);
253+
$args = $this->get_args( $args );
254254

255255
if ( ! empty( $args['end-callback'] ) ) {
256256
ob_start();
@@ -282,12 +282,7 @@ public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
282282
* @param array $args An array of arguments.
283283
*/
284284
protected function ping( $comment, $depth, $args ) {
285-
$args = wp_parse_args(
286-
$args,
287-
array(
288-
'style' => 'ul',
289-
)
290-
);
285+
$args = $this->get_args( $args );
291286

292287
$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
293288
?>
@@ -333,14 +328,7 @@ public function filter_comment_text( $comment_text, $comment ) {
333328
* @param array $args An array of arguments.
334329
*/
335330
protected function comment( $comment, $depth, $args ) {
336-
$args = wp_parse_args(
337-
$args,
338-
array(
339-
'style' => 'ul',
340-
'avatar_size' => 32,
341-
'max_depth' => '',
342-
)
343-
);
331+
$args = $this->get_args( $args );
344332

345333
if ( 'div' === $args['style'] ) {
346334
$tag = 'div';
@@ -452,14 +440,7 @@ protected function comment( $comment, $depth, $args ) {
452440
* @param array $args An array of arguments.
453441
*/
454442
protected function html5_comment( $comment, $depth, $args ) {
455-
$args = wp_parse_args(
456-
$args,
457-
array(
458-
'style' => 'ul',
459-
'avatar_size' => 32,
460-
'max_depth' => '',
461-
)
462-
);
443+
$args = $this->get_args( $args );
463444

464445
$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
465446

0 commit comments

Comments
 (0)