[ 'type' => 'string', 'default' => 'post', ], 'className' => [ 'type' => 'string', ], 'type' => [ 'type' => 'string', 'default' => 'monthly', ], 'align' => [ 'type' => 'string', ], 'displayAsDropdown' => [ 'type' => 'boolean', 'default' => false, ], 'showPostCounts' => [ 'type' => 'boolean', 'default' => false, ], ]; /** * Constructor * * @param string $name block name. */ public function __construct( string $name ) { if ( $name ) { $this->name = $name; } $this->register(); } /** * Render callback * * @param array $attributes block attributes. * * @return false|string */ public function render( $attributes ) { $show_post_count = ! empty( $attributes['showPostCounts'] ); $post_type = $attributes['postType']; $type = $attributes['type']; $class = 'wp-block-archives'; if ( isset( $attributes['align'] ) ) { $class .= " align{$attributes['align']}"; } if ( isset( $attributes['className'] ) ) { $class .= " {$attributes['className']}"; } if ( ! empty( $attributes['displayAsDropdown'] ) ) { $class .= ' wp-block-archives-dropdown'; $dropdown_id = esc_attr( uniqid( 'wp-block-archives-' ) ); $title = __( 'Archives' ); $dropdown_args = array( 'type' => $type, 'format' => 'option', 'post_type' => $post_type, 'show_post_count' => $show_post_count, ); $dropdown_args['echo'] = 0; $archives = wp_get_archives( $dropdown_args ); switch ( $dropdown_args['type'] ) { case 'yearly': $label = __( 'Select Year' ); break; case 'monthly': $label = __( 'Select Month' ); break; case 'daily': $label = __( 'Select Day' ); break; case 'weekly': $label = __( 'Select Week' ); break; default: $label = __( 'Select Post' ); break; } $label = esc_attr( $label ); $block_content = ' '; $block_content = sprintf( '