Skip to content

Commit

Permalink
Dev: Use WP_HTML_Tag_Processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gaambo committed Nov 1, 2023
1 parent e0413fb commit f83b6ee
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions good-slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: Good Slider
* Description: A simple and extendable slider block using Swiper
* Requires at least: 6.0
* Requires at least: 6.2
* Requires PHP: 7.4
* Version: 1.3.1
* Author: GoodWP
Expand Down Expand Up @@ -163,12 +163,12 @@ function renderSliderBlock($attributes, $content)
* @param array $attributes the block instances attributes
*/
$swiperOptions = apply_filters('good-slider/swiper-options', [], $attributes);
$content = preg_replace(
'/' . preg_quote('class="', '/') . '/',
'data-swiper-options="' . esc_attr(wp_json_encode($swiperOptions)) . '" class="',
$content,
1
);

$html = new \WP_HTML_Tag_Processor($content);
if ($html->next_tag(['class' => 'wp-block-good-slider'])) {
$html->set_attribute('data-swiper-options', wp_json_encode($swiperOptions));
}
return $html->get_updated_html();

return $content;
}
Expand Down

0 comments on commit f83b6ee

Please # to comment.