Automattic / Automattic/WP-Job-Manager

Ultimate Member with WooCommerce Select2 Conflicts

Open
#2,002 3 comments 0 reactions 0 assignees View on GitHub
[Pri] Normal [Status] Accepted Bug
Dominant language
PHP
Stars
899
Forks
369
Avg merge
11h 37m
Merged PRs (30d)
12

Description

When using Ultimate Member, WooCommerce, and WP Job Manager there's a problem with Ultimate Member re-registering `select2` (and deregistering when WooCommerce is installed) which ultimately causes `job_manager_select2_args` to be undefined.

Because there is code in the initialization of the mutliselect fields to check if `job_manager_select2_args` is defined, essentially what happens is those fields never get initialized as select2 fields.

**To Reproduce**
Steps to reproduce the behavior:
1. Install blank WordPress installation
2. Install WP Job Manager and activate
3. Install Ultimate Member and activate
4. Install WooCommerce and activate
5. Goto Job Submit page, multiselect fields are not initialized

I was able to track this down to ultimate member, which is registering `select2` with a priority of `100` on `wp_enqueue_scripts`, wheres WP Job Manager initializes at standard `10` and it seems when the script is re-registered, that it loses anything that was set with `wp_localize_script`

It seems that when you have WooCommerce also installed, the Ultimate Member plugin actually deregisters `select2` (assuming it's done to deregister WooCommerce select2).

So there's two ways I see around this ... one is that we add another action for `wp_enqueue_scripts` and set the priority to something super high like `99999999` and then call `wp_localize_script` to make sure `job_manager_select2_args` is set (since it's not an options dependent on where it's set right now).

The other option would be to localize it against the WP Job Manager scripts themselves `wp-job-manager-term-multiselect` and `wp-job-manager-multiselect`

Another option would be to register select2 with a different handle, although i don't think that would be the "best" idea

Or we could change the filter priority using `um_core_enqueue_priority` -- not sure what adverse issues this could cause though

Thoughts? For now i'm going to add compatibility in my plugin by doing the enqueue action mentioned above at a very high priority (so it's set after any other plugins re-register select2).

It also seems that Ultimate Member has custom CSS for Select2 as well, making the select boxes much larger than necessary and removes the "clean" look from them
```
wp_register_style( 'um_styles', $this->css_baseurl . 'um-styles.css', array(), ultimatemember_version );
```

Contributor guide

Open the contributing guide

Research direction

Start at WP Job Manager's wp_enqueue_scripts initialization and trace how wp_localize_script sets job_manager_select2_args for wp-job-manager-term-multiselect and wp-job-manager-multiselect. Reproduce the conflict with Ultimate Member and WooCommerce, then verify that the multiselect fields initialize correctly without being broken by script re-registration or deregistration.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.