Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

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

Open
pufflik opened this issue Jan 5, 2021 · 1 comment

Comments

@pufflik
Copy link

pufflik commented Jan 5, 2021

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 :)

@pufflik pufflik changed the title Language switcher disappears on Post Editing page Language switcher disappears on Post Editing page (quick and dirty fix inside) Jan 5, 2021
@g4rf
Copy link

g4rf commented Jun 2, 2023

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

g4rf added a commit to g4rf/wp-multilang-valentyn that referenced this issue Jun 20, 2023
- checks if toolbar is loaded and deferres adding if needed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants