Help Desk

Select2 Library Conflict with SearchWP – help with fix or dequeuing it

  • Posts: 5 Topics: 5
    | Permalink

    Hi There.

    We’ve got a conflict with SearchWP, the Events Calendar plugin is loading a version of the select2 library in the admin and when disabled I am able to use SearchWP but I can’t use it’s admin interface when The Events Calendar plugin is active. How do I dequeue select2 in the admin for certain pages?

    Here’s the full thread from Search WP Support:

    Hi there,

    Based on the explanation it looks like The Events Calendar is outputting a legacy version of select2 on the SearchWP settings screen which is causing the problem. I would recommend opening a ticket with The Events Calendar to find out how to dequeue the select2 library that it is loading, to avoid the issue.

    That will do it!


    Jonathan
    SearchWP, LLC

    Nov 12, 8:07pm
    New SearchWP Support Ticket

    Environment Details
    SearchWP: 2.8.17 WordPress: 4.8.3 PHP: 7.0.25 MySQL: 5.7.20
    Licensed Site
    https://themagiccompass.nz
    Searched for
    Bug (Conflict with The Events Calendar)
    Summary
    Bug (Conflict with The Events Calendar)
    I am having an issue with
    My License
    License issue verification
    I have verified that the active site(s) on file are accurate in my account
    My server is not blocking communication over HTTP to searchwp.com
    Describe the issue you are experiencing in as much detail as possible
    Hi You don’t seem to have an option for plugin conflict

    When The Events Calendar is active your version of the “Select2” library seems to conflict with theirs and I can’t use your UI to create supplemental search engines. Disabling the events Calendar restores the expected behaviour – not sure who needs to do what here but let me know what you’d like me to communicate with the Events Calendar folks.

    Here’s the Javascript Error I see:
    Uncaught Error: Option ‘ajax’ is not allowed for Select2 when attached to a <select> element.
    at String.<anonymous> (select2.min.js?ver=4.7:21)
    at Function.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils&ver=2590038ca004aed3a123c6f25d4bcd81:2)
    at i.prepareOpts (select2.min.js?ver=4.7:21)
    at i.prepareOpts (select2.min.js?ver=4.7:22)
    at init (select2.min.js?ver=4.7:21)
    at HTMLSelectElement.<anonymous> (select2.min.js?ver=4.7:22)
    at Function.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils&ver=2590038ca004aed3a123c6f25d4bcd81:2)
    at a.fn.init.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils&ver=2590038ca004aed3a123c6f25d4bcd81:2)
    at a.fn.init.e.fn.select2 (select2.min.js?ver=4.7:22)
    at HTMLSelectElement.<anonymous> (options-general.php?page=searchwp:9434)

    Cheers

    Posts: 11242
    | Permalink

    Hi, Jonathan.

    They’re correct that our Select2 library is quite a bit outdated.

    It’s on our current to-do list to get this updated, likely to the fairly new SelectWoo fork of Select2.

    Because our Select2 is so outdated (being honest) and because of the way our dropdowns code relies on Select2, our stuff may not work if SearchWP’s version of Select2 is loaded but ours isn’t.

    You can see our dropdowns require our version of Select2: https://github.com/moderntribe/tribe-common/blob/4.7/src/Tribe/Main.php#L210

    Therefore, I don’t think there’s a way to overcome this conflict at this time.

    If you or they have any other ideas at this time, please let me know and I’ll be glad to help as I can.

    Posts: 5 Topics: 5
    | Permalink

    I hear you that the events calendar needs this for the front end to work and I don’t think that will be a problem. However in the WordPress admin this is a major issue for us that HAS to be resolved as soon as possible.

    We have an events site launching very soon. We need to be able to use Search WP search fields that search some custom fields and taxonomies that we have added to the venues and organisers post types. On the front end we are using facetwp for searching and filtering so that works but I need to be able to make a custom Search engine for the search facet with Search WP.

    Because your select2 library is loaded all over the place throughout the WordPress admin it seems, I can’t use Search WP in the WordPress Admin, the output of the admin screen is COMPLETELY broken. The Events calendar has no need to have select2 loaded across the entire admin surely when I’m not in the admin for the Events Calendar, I’m in the admin interface for a completely different plugin. If I turn off The Events Calendar then I can use Search WP to make a new search engine but I can’t access the CPT’s for venue or organizer to include them or their custom fields in that search engine and as soon as I turn on The Events Calendar I can no longer edit that custom search engine – so that defeats the purpose entirely.

    Conditionally loading your select2 library only when in the edit mode for your plugin in the backend would be a solution I think. I’m a bit short of development chops to sort this but it’s a major show stopper for us at this point.

    Posts: 11242
    | Permalink

    I heard today that the latest Avada theme dequeues our Select2 so I gave it a look and they do

    wp_dequeue_script( 'tribe-events-select2' );

    and then they enqueue their own Select2 CSS and Select2 JS for Select2 version 4.0.3

    Therefore, it might be worth a try on your end if you wish.

    Posts: 5 Topics: 5
    | Permalink

    I was able to turn this off but not with the code you suggested. This was only a temporary fix to enable me to build the SearchWP extra search engine. After that I had to disable my code in order to continue to be able to add events.

    Please get the dev team to limit the scope of your select2 library to your own plugin in the backend, not the whole admin interface.

    Here is what I used for anyone else with the same issue:

    if ( is_admin()  ) {
            wp_deregister_script( 'tribe-select2' );
        }  
    
    Posts: 11242
    | Permalink

    I’m glad you got that figured out. Thanks for sharing with us and others.

    I’ve passed along your request and set this thread to Pending Fix status, which means this thread should receive a reply when the fix is released.