VaLeXaR / wp-multilang

Multilingual plugin for WordPress.
130 stars 44 forks source link

Language switcher disappears on Post Editing page (quick and dirty fix inside) #177

Open pufflik opened 3 years ago

pufflik commented 3 years ago

Tested in WordPress 5.6. I guess there's something in jQuery update that breaks existing functionality. To deal with call stack order I wrapped this function https://github.com/VaLeXaR/wp-multilang/blob/master/includes/admin/class-wpm-admin-assets.php#L197 with setTimeout, and it works fine even with 0 delay, but I hope it will be fixed with the next update. This fix not elegant at all, for sure, but since there are timeouts in wp-edit-post, maybe it's not that bad after all :)

g4rf commented 1 year ago

Nice hack, I've looked a lot around for finding a solution for the sometimes appearing and mostly disappered language switcher in the block editor. To think your approach a little bit further, I do a check if the toolbar exists, and if not, I'll set a timeout. Works for me fine. :)

$(window).on('pageshow', function(){
    if ($('#wpm-language-switcher').length === 0) {
        var language_switcher = wp.template( 'wpm-ls-customizer' );

        var wpm_add_language_switcher_deferred = function() {
            var toolbar = $('.edit-post-header-toolbar');
            if(toolbar.length) {
                toolbar.prepend(language_switcher);
            } else {
                window.setTimeout(wpm_add_language_switcher_deferred, 100);
            }
        }

        wpm_add_language_switcher_deferred();
    }
});

Have a fork here with more changes, mostly pull requests from this repo:: https://github.com/g4rf/wp-multilang