Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom element disappeared after refreshing the preview #138

Open
reefki opened this issue Aug 13, 2017 · 10 comments
Open

Custom element disappeared after refreshing the preview #138

reefki opened this issue Aug 13, 2017 · 10 comments

Comments

@reefki
Copy link
Contributor

reefki commented Aug 13, 2017

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;
        }
    }
}
@conwaydev
Copy link

Same here, I proposed #139, but I don't know if thats how @Enclavelyio wants to go about it, but it fixed our scenario which seems like the same as yours

@reefki
Copy link
Contributor Author

reefki commented Aug 15, 2017

@conwaydev Nice! It seems to be worked for me, but let see what @Enclavelyio will do to fix it.

@reefki
Copy link
Contributor Author

reefki commented Aug 16, 2017

@conwaydev I don't think that it happened only to custom namespaced elements, I tried to install tailor official sample extension which has tailor_ prefix on all custom elements and yes, they also fail! Similar to mine, they rendered at first but disappeared after refreshing the window.

I think it's a critical bug and @Enclavelyio or @andrew-worsfold should take a look at this.

@reefki
Copy link
Contributor Author

reefki commented Aug 16, 2017

@conwaydev Just pulled a new changes #140 the problems is only on stripping out tailor_ prefix when creating the regex and append it when parsing post content.

@conwaydev
Copy link

Nice, closed mine, yours works for us!

andrew-worsfold pushed a commit that referenced this issue Aug 22, 2017
* Added - The ability to modify the default media query sizes.
* Improved - Frontend CSS is automatically recompiled from project SCSS files when Customizer settings are updated.
* Improved - The performance of the tailor_modify_colorpicker function.
* Fixed - Element CSS not loading when restoring the "Initialized" history snapshot.
* Fixed - Notice of undefined index [body_class] displayed on the Gutenberg edit screen [GitHub 134](#134).
* Fixed - Certain character sets are not being encoded properly [GitHub 137](#137).
* Fixed - Custom elements are not being correctly extracted from saved HTML content [GitHub 138](#138).
@reefki
Copy link
Contributor Author

reefki commented Aug 22, 2017

Looks like the issue has been resolved in the new release.

@reefki reefki closed this as completed Aug 22, 2017
@reefki
Copy link
Contributor Author

reefki commented Aug 23, 2017

Not really though, updated to the 1.8.1 custom elements still can't be extracted from post content, I don't know why my commit it's worked on 1.8.0, probably some other changes affecting to it. But after some digging, I found that generate_element_regex is fired at default priority that make it possible to be fired before custom elements are registered.

So I pull another commit #143 to make sure it's fired at the very end.

@reefki reefki reopened this Aug 23, 2017
@conwaydev
Copy link

Yeah same for us thanks @reefki

@mihaijoldis
Copy link

Latest release and have the same issue with elements going missing after saving and reopening the editor.
Found this issue and applied commit #143 and its now working again.

@arashohadi
Copy link
Contributor

I can confirm the same problem. The commit in #143 fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants