__CLASS__,
'attributes' => $attributes,
'block_ids' => self::$block_ids,
]
);
$to_replace = '';
$pagination_type = $block->context['generateblocks/carousel/htmlAttributes']['data-pagination-type'] ?? 'bullets';
$replacement = '';
if ( 'fraction' === $pagination_type ) {
$replacement = '1 / 1';
}
if ( 'bullets' === $pagination_type ) {
$replacement = '';
}
if ( $replacement ) {
$block_content = str_replace( $to_replace, $replacement, $block_content );
}
// Add default ARIA attributes if not present using WP HTML Tag Processor
// Only available in WordPress 6.2+, skip for older versions.
if ( class_exists( 'WP_HTML_Tag_Processor' ) ) {
$has_aria_label = isset( $attributes['htmlAttributes']['aria-label'] ) && ! empty( $attributes['htmlAttributes']['aria-label'] );
$processor = new \WP_HTML_Tag_Processor( $block_content );
// Find the first tag (the pagination container).
if ( $processor->next_tag() ) {
// Add default ARIA label if not present.
if ( ! $has_aria_label && ! $processor->get_attribute( 'aria-label' ) ) {
// Map pagination types to default ARIA labels.
$default_labels = [
'bullets' => __( 'Carousel pagination', 'generateblocks-pro' ),
'fraction' => __( 'Carousel slide counter', 'generateblocks-pro' ),
'progressbar' => __( 'Carousel progress', 'generateblocks-pro' ),
];
$aria_label = $default_labels[ $pagination_type ] ?? __( 'Carousel pagination', 'generateblocks-pro' );
$processor->set_attribute( 'aria-label', $aria_label );
}
// Add role attribute for bullets pagination if not present.
if ( 'bullets' === $pagination_type && ! $processor->get_attribute( 'role' ) ) {
$processor->set_attribute( 'role', 'navigation' );
}
$block_content = $processor->get_updated_html();
}
}
return $block_content;
}
}