wp/wp-includes/blocks/archives.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/blocks/archives.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/blocks/archives.php	Tue Dec 15 13:49:49 2020 +0100
@@ -72,76 +72,55 @@
 	<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,
-			)
-		);
-
-		$archives_args['echo'] = 0;
-
-		$archives = wp_get_archives( $archives_args );
-
-		$classnames = esc_attr( $class );
-
-		if ( empty( $archives ) ) {
-
-			$block_content = sprintf(
-				'<div class="%1$s">%2$s</div>',
-				$classnames,
-				__( 'No archives to show.' )
-			);
-		} else {
-
-			$block_content = sprintf(
-				'<ul class="%1$s">%2$s</ul>',
-				$classnames,
-				$archives
-			);
-		}
 	}
 
-	return $block_content;
+	$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,
+		)
+	);
+
+	$archives_args['echo'] = 0;
+
+	$archives = wp_get_archives( $archives_args );
+
+	$classnames = esc_attr( $class );
+
+	if ( empty( $archives ) ) {
+
+		return sprintf(
+			'<div class="%1$s">%2$s</div>',
+			$classnames,
+			__( 'No archives to show.' )
+		);
+	}
+
+	return sprintf(
+		'<ul class="%1$s">%2$s</ul>',
+		$classnames,
+		$archives
+	);
 }
 
 /**
  * Register archives block.
  */
 function register_block_core_archives() {
-	register_block_type(
-		'core/archives',
+	register_block_type_from_metadata(
+		__DIR__ . '/archives',
 		array(
-			'attributes'      => array(
-				'align'             => array(
-					'type' => 'string',
-				),
-				'className'         => array(
-					'type' => 'string',
-				),
-				'displayAsDropdown' => array(
-					'type'    => 'boolean',
-					'default' => false,
-				),
-				'showPostCounts'    => array(
-					'type'    => 'boolean',
-					'default' => false,
-				),
-			),
 			'render_callback' => 'render_block_core_archives',
 		)
 	);
 }
-
 add_action( 'init', 'register_block_core_archives' );