Skip to content

Commit

Permalink
Chore: Code improvements to block PHP files. (#17288)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored and talldan committed Sep 2, 2019
1 parent 8213431 commit f1b2f29
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
54 changes: 25 additions & 29 deletions packages/block-library/src/archives/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,48 +72,44 @@ function render_block_core_archives( $attributes ) {
<select id="' . $dropdown_id . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">' . $label . '</option>' . $archives . '</select>';

$block_content = sprintf(
return sprintf(
'<div class="%1$s">%2$s</div>',
esc_attr( $class ),
$block_content
);
} else {

$class .= ' wp-block-archives-list';
}

/** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */
$archives_args = apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'show_post_count' => $show_post_count,
)
);
$class .= ' wp-block-archives-list';

$archives_args['echo'] = 0;
/** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */
$archives_args = apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'show_post_count' => $show_post_count,
)
);

$archives = wp_get_archives( $archives_args );
$archives_args['echo'] = 0;

$classnames = esc_attr( $class );
$archives = wp_get_archives( $archives_args );

if ( empty( $archives ) ) {
$classnames = esc_attr( $class );

$block_content = sprintf(
'<div class="%1$s">%2$s</div>',
$classnames,
__( 'No archives to show.' )
);
} else {
if ( empty( $archives ) ) {

$block_content = sprintf(
'<ul class="%1$s">%2$s</ul>',
$classnames,
$archives
);
}
return sprintf(
'<div class="%1$s">%2$s</div>',
$classnames,
__( 'No archives to show.' )
);
}

return $block_content;
return sprintf(
'<ul class="%1$s">%2$s</ul>',
$classnames,
$archives
);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ function render_block_core_categories( $attributes ) {
$class .= " {$attributes['className']}";
}

$block_content = sprintf(
return sprintf(
$wrapper_markup,
esc_attr( $class ),
$items_markup
);

return $block_content;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/latest-comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function render_block_core_latest_comments( $attributes = array() ) {
}
$classnames = esc_attr( $class );

$block_content = ! empty( $comments ) ? sprintf(
return ! empty( $comments ) ? sprintf(
'<ol class="%1$s">%2$s</ol>',
$classnames,
$list_items_markup
Expand All @@ -146,8 +146,6 @@ function render_block_core_latest_comments( $attributes = array() ) {
$classnames,
__( 'No comments to show.' )
);

return $block_content;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ function render_block_core_latest_posts( $attributes ) {
$class .= ' ' . $attributes['className'];
}

$block_content = sprintf(
return sprintf(
'<ul class="%1$s">%2$s</ul>',
esc_attr( $class ),
$list_items_markup
);

return $block_content;
}

/**
Expand Down

0 comments on commit f1b2f29

Please sign in to comment.