Skip Navigation

Page builder content duplicated by Layouts Visual Editor cell

Resolved

Reported for: Toolset Layouts 2.0.1

Resolved in: Toolset Layouts 2.0.2

Symptoms

This problem has been solved for a number of plugins such as: Divi Builder, Beaver Builder, Elementor, EDD etc, but there are still some plugins that may experience the problem. Normally what happens is that in a page where the content is built using a content builder and it is rendered with Layouts using a “Post Content cell” or a “Visual Editor cell” with a “wpv-post-body” call, if another “Visual Editor cell” is present in the page, before the cell where the content is rendered, the content will be wrongly rendered in this latter cell.

To prevent this to happen we implemented a filter to control when “the_content” filter can run in a “Visual Editor cell”, but since every builder plugin has its own strategy to render its content, we need a different implementation of this filter callback, which suits the strategy the builder uses to render its content.

When you run into this problem, please contact support and mention this errata.

Workaround

Add a filter callback to “ddl_apply_the_content_filter_in_cells” with proper control flow to tell “Visual Editor cell” to avoid running “the_content” filter under specific conditions and thus preventing any duplication.

This is an example implementation for Elementor plugin:

class Layouts_Compatibility_Elementor implements Toolset_Compatibility_Handler_Interface {

    public function initialize() {
        add_action( 'ddl_before_frontend_render_cell', array( $this, 'disable_content_filter_if_necessary' ), 10, 2 );
    }

    /**
     * Use filter to make sure that the content filter in cells is not applied if cell is rendering
     * post content and Elementor plugin is active in the same time
     *
     * This will ensure compatibility and correct rendering for Elementor output
     * @param $cell
     * @param $renderer
     *
     * @return bool (is filter applied)
     */
    public function disable_content_filter_if_necessary( $cell, $renderer ) {

        $should_apply_content_filter = true;

        if (
            ( $cell->get_cell_type() === 'cell-content-template' && $cell->check_if_cell_renders_post_content() === false )
            || ( $cell->get_cell_type() === 'cell-text' && $this->has_wpvbody_tag( array( $cell ) ) === false )
        ) {
            add_filter( 'ddl_apply_the_content_filter_in_cells', '__return_false' );
            $should_apply_content_filter = false;
        }

        return $should_apply_content_filter;
    }

    /**
     * Check do we have wpvbody tag inside any cell from the list
     * @param $cells
     *
     * @return bool
     */
    public function has_wpvbody_tag( $cells ) {
        return WPDD_Utils::visual_editor_cell_has_wpvbody_tag( $cells ) !== '' ;
    }


}

As you can see we are using a combination of an action hook (“ddl_before_frontend_render_cell”), to perform a series of controls on the cell itself (what kind of cell is it? does it renders the content?) and then apply a callback filter to the aforementioned “ddl_apply_the_content_filter_in_cells” to avoid it to run, using as a callback WordPress built in helper function “__return_false”.

Comments are closed