PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / trunk
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts vtrunk
2.8.14 2.8.13 2.8.12 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.11 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 trunk 1.0.1 1.0.2 1.1.0 1.1.1 All 147 releases
← All changes | includes/custom-style.php +37 -14 2.8.13trunk View file →
@@ -131,10 +131,10 @@
131 131
132 132 // Render settings for carousels.
133 133 add_filter( 'render_block', [ $this, 'render_carousel_settings' ], 30, 3 );
134 134
135 - // Migrate CBB class for old blocks.
136 - add_filter( 'render_block', [ $this, 'migrate_cbb_class' ], 30, 3 );
135 + // Handle migration css class and custom css.
136 + add_filter( 'render_block', [ $this, 'manage_cbb_class' ], 30, 3 );
137 137
138 138 // Render steps block data.
139 139 add_filter( 'render_block_data', [ $this, 'render_steps_block_data' ], 10, 3 );
140 140
@@ -1987,9 +1987,9 @@
1987 1987 if ( ! $name || ! $duration ) {
1988 1988 return $accumulator;
1989 1989 }
1990 1990
1991 - $delay = $animation['delay'] ?? 0;
1991 + $delay = empty( $animation['delay'] ) ? 0 : $animation['delay'];
1992 1992 $repeat = $animation['repeat'] ?? 1;
1993 1993 $infinite = $animation['infinite'] ?? false;
1994 1994 $timing_function = $animation['timingFunction'] ?? '';
1995 1995 $animation_name = isset( $animation_names[ $name ]['name'] ) ? $animation_names[ $name ]['name'] : $name;
@@ -3713,9 +3713,9 @@
3713 3713 return apply_filters( 'cbb_carousel_preloader', '<div class="cbb-loader"></div>', $block, $block_instance );
3714 3714 }
3715 3715
3716 3716 /**
3717 - * Migrate cbb class for old CBB blocks.
3717 + * Manage css class: migrate old class and adding custom css class.
3718 3718 *
3719 3719 * @param string $block_content
3720 3720 * @param array $block
3721 3721 * @param WP_Block $block_instance
@@ -3720,28 +3720,51 @@
3720 3720 * @param array $block
3721 3721 * @param WP_Block $block_instance
3722 3722 * @return string
3723 3723 */
3724 - public function migrate_cbb_class( $block_content, $block, $block_instance ) {
3724 + public function manage_cbb_class( $block_content, $block, $block_instance ) {
3725 3725 // Ignore admin side or empty content.
3726 3726 if ( is_admin() || ! $block_content ) {
3727 3727 return $block_content;
3728 3728 }
3729 3729
3730 - // There is no need to migrate.
3731 - $migrate_cbb_class = $block_instance->block_type->supports['migrateClass'] ?? '';
3732 - if ( ! $migrate_cbb_class ) {
3730 + // Bail if it is not a CBB block.
3731 + if ( empty( $block_instance->block_type->supports['cbb'] ?? '' ) ) {
3733 3732 return $block_content;
3734 3733 }
3735 3734
3736 - // Replace the class.
3737 - $block_reader = new \WP_HTML_Tag_Processor( $block_content );
3738 - if ( $block_reader->next_tag( [ 'class_name' => $migrate_cbb_class ] ) ) {
3739 - $new_class = str_ends_with( $migrate_cbb_class, 'custom' ) ? 'cbb-block' : 'cbb-block-parent';
3740 - $block_reader->set_attribute( 'class', str_replace( $migrate_cbb_class, $new_class, $block_reader->get_attribute( 'class' ) ) );
3735 + // Get custom classes.
3736 + $css_classes = trim( $block_instance->block_type->supports['CSSClasses'] ?? '' );
3741 3737
3738 + // Get migrate class.
3739 + $migrate_class = trim( $block_instance->block_type->supports['migrateClass'] ?? '' );
3740 +
3741 + // Bail if we don't need to process.
3742 + if ( ! $css_classes && ! $migrate_class ) {
3743 + return $block_content;
3744 + }
3745 +
3746 + // Initialize the HTML Tag Processor.
3747 + $p = new \WP_HTML_Tag_Processor( $block_content );
3748 +
3749 + // Target only the very first outer wrapping element.
3750 + if ( $p->next_tag() ) {
3751 + if ( $migrate_class ) {
3752 + $p->remove_class( $migrate_class );
3753 + $p->add_class( str_ends_with( $migrate_class, 'custom' ) ? 'cbb-block' : 'cbb-block-parent' );
3754 + }
3755 +
3756 + if ( $css_classes ) {
3757 + // Explode by space in case multiple custom classes are supplied.
3758 + foreach ( explode( ' ', $css_classes ) as $single_class ) {
3759 + if ( ! empty( $single_class ) ) {
3760 + $p->add_class( $single_class );
3761 + }
3762 + }
3763 + }
3764 +
3742 3765 // Render the updated HTML.
3743 - return $block_reader->get_updated_html();
3766 + return $p->get_updated_html();
3744 3767 }
3745 3768
3746 3769 return $block_content;
3747 3770 }