Skip to content

Custom element disappeared after refreshing the preview #138

@reefki

Description

@reefki

Everything was fine when adding my custom element into the canvas and hit the save button, I could see my custom element in the front end. However, if I refresh the preview window it gets disappeared while it's still visible on the front end and WordPress content editor. Here is what I see in the content editor:

screen shot 2017-08-13 at 23 06 33

This is happened after updating Tailor plugin from 1.7.4 to the latest version 1.8.0, I was never facing this problem on previously.

Below is my custom element codes:

if (! function_exists('my_custom_element_shortcode')) {
    function my_custom_element_shortcode($atts, $content = null, $tag) {
        $atts = shortcode_atts(array('text' => ''), $atts, $tag);

        $html_atts = tailor_get_attributes(array(
            'class' => array('tailor-element', 'tailor-custom-element', 'my-custom-element'),
        ));
        
        ob_start();

        tailor_partial('custom', 'element');

        $content = ob_get_clean();
        $wrapper = "<div {$html_atts}>%s</div>";

        return sprintf($wrapper, $content);
    }
    
    add_shortcode('my_custom_element', 'my_custom_element_shortcode');
}
if (! function_exists('register_custom_tailor_elements')) {
    function register_custom_tailor_elements($manager) {
        $manager->add_element('my_custom_element', array(
            'label'       => esc_html__('Custom Element', 'text-domain'),
            'description' => esc_html__('Element description', 'text-domain'),
            'type'        => 'content',
        ));
    }
    
    add_filter('tailor_register_elements', 'register_custom_tailor_elements');
}
if (class_exists('Tailor_Element') && ! class_exists('My_Custom_Element_Element'))
{
    class My_Custom_Element_Element extends Tailor_Element
    {
        protected function register_controls()
        {
            $this->add_section('general', array(
                'title'    => esc_html__('General', 'text-domain'),
                'priority' => 10,
            ));

            $this->add_setting('text', array(
                'sanitize_callback' => 'tailor_sanitize_text',
            ));

            $this->add_control('text', array(
                'section'  => 'general',
                'label'    => esc_html__('Text', 'text-domain'),
                'type'     => 'text',
                'priority' => 10,
            ));
        }

        public function generate_css($atts = array())
        {
             $css_rules = array();
	     $excluded_settings = array();
             $css_rules = tailor_css_presets($css_rules, $atts, $excluded_settings);

	     return $css_rules;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions