Support

Account

Home Forums ACF PRO Select2 Conflict with Awesome Support

Solving

Select2 Conflict with Awesome Support

  • Hi there,

    I’m the lead developer of Awesome Support, and we’re currently having a conflict with ACF Pro: https://github.com/Awesome-Support/Awesome-Support/issues/332

    The problem is that ACF Pro is loading select2 on every admin page, and the version you guys use doesn’t match the one we use, which breaks things.

    My colleague already reached out to you and was told that ACF doesn’t load select2 assets on every page in the latest versions. I guess this is something that’s been fixed then.

    What I’d like to know is in which version did you change that? I’m adding a compatibility fix in Awesome Support, but I’d like to limit it to the conflicting versions of ACF only.

    Cheers,
    Julien

  • Hi @julien731 ,

    Thank a lot for the feedback.

    The issue seems to be caused by a conflict between version 3.4 and 4 of the select2 plugin.

    The developer is already aware of this issue and we have already recommended the use the version 4 select2 in order to avoid the conflict.

    Hopefully, this issue will be sorted soon.

  • Thanks for the quick reply James. I appreciate it. It’s good to hear that this has been taken into account.

    However, what I’d like to know is which version of ACF Pro has a fix for that, so that I can load my compatibility fix for users using older versions of ACF Pro.

  • Why is ACF using the plugin version for the select2 script version? The big issue here is select2 is being registered using the plugin version and not the select2 script version. You should always use the script version when you enqueue – that way if another plugin is using the script, WP can compare versions and use the newest one.

    https://developer.wordpress.org/reference/functions/wp_enqueue_script/

    This needs to be changed to avoid compatibility issues with plugins in the future.

  • Hi @ajgagnon

    The main reason ACF still use the old version is that it contains more functionality such as the ability to order the selected values. If it causes a conflict, I believe you can always remove it:

    <?php
    
    function m_dequeue_script() {
    
        wp_deregister_script( 'select2' );
        wp_deregister_style( 'select2' );
    
    }
    
    add_action( 'init', 'my_dequeue_script', 20 );
    
    ?>

    I hope this makes sense 🙂

  • Hi @ajgagnon

    Thanks for your reply. I can assure you that ACF PRO uses the script version to register Select2 JS. Currently, the version is set to ‘3.5.2’

  • Hi @julien731

    Thanks for the topic.
    ACF enqueues the Select2 JS library (v3.5.2) on all admin pages where ACF fields may exist (post, term, user, comment, media, etc).

    ACF has an action called ‘acf/input/admin_enqueue_scripts’ which mimics the WP ‘admin_enqueue_scripts’ one. The ACF select field listens for ‘acf/input/admin_enqueue_scripts’ and enqueues the Select2 JS.

    I hook into the ‘admin_enqueue_scripts’ action with a priority of 20 if that helps.

  • Currently i have the same problem in backend with another plugin (WP Customer Area).

    I’ve temporarely solved with this code

    function my_acf_admin_enqueue_scripts() {
    	wp_dequeue_script( 'select2');
    	wp_deregister_script( 'select2' );
    	wp_enqueue_style('select2', '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css');
        wp_enqueue_script('select2', '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js', '', '', false);
    }
    add_action('admin_enqueue_scripts', 'my_acf_admin_enqueue_scripts');

    But i don’t know if it’s the best approach and can bring problems to ACF backend pages and fields.

  • Hi @rics ,

    Thanks for reaching out to us.

    Your workaround will work just fine.

    However, as I had pointed out, you will be missing out on some of the features available in select2 3.* such as the ability to order the selected values.

    I hope this helps clarify 🙂

  • It conflicts with Shortcake Shortcode UI (featured plugin on way to core). Has to be solved somehow, dont know how.

    I used this snipped and sorting is still there !!??

    Can we get some more info about this conflict ?
    List of possible missing features ?

    https://github.com/wp-shortcake/shortcake/issues/660

  • Hi @stagger-lee

    Please open a new support ticket at [email protected] with more info on this conflict so that we can help in fixing this conflict.

    Thanks.

  • Hello,
    just a thought, since this exact problem rises quite often. What do you think about namespacing select2 library to be specific for ACF? I know, that in some cases, that might lead to unnecessary requests, since you might need to load same library more times. But it would solve all those conflicts with various plugins. For example, Yoast SEO does exactly that, they register lib as yoast-seo-select2 and use namespaced calls to lib as well and they would never conflict with other plugins…

    Have a nice day, Jakub

  • Hi Jakub

    Thanks for the question.

    I actually think that name-spacing a 3rd party library is the cause of issues, not the solution.

    If no one namespaced the ‘select2’ JS library, only 1 library would be enqueued into the admin page and would solve lots of JS errors.
    When the page has multiple libraries, this is where we run into issues.

    I have included some new settings in ACF PRO which allow you to change the select2 library from v3 to v4 or even remove it completely from ACF.
    http://www.advancedcustomfields.com/resources/acfsettings/

    Thanks
    E

  • Well, this is actually exactly the case, where two plugins did it “right” and used same library handle. It would work only in ideal world, where library API would never ever change.
    But I got your point 🙂 thanks for answer.
    Have a nice christmas, J.

Viewing 15 posts - 1 through 15 (of 15 total)

The topic ‘Select2 Conflict with Awesome Support’ is closed to new replies.