Add multi-select for engagement trigger associated items - #3238
Add multi-select for engagement trigger associated items#3238faisalahammad wants to merge 12 commits into
Conversation
Allow selecting multiple courses, lessons, memberships, etc. for engagement triggers instead of a single item or Any. - Enable Select2 multi-select on trigger post fields - Store multiple IDs as comma-separated string in postmeta - Use FIND_IN_SET() for backward-compatible SQL matching - Update admin list table to display multiple linked items Fixes gocodebox#3233
brianhogg
left a comment
There was a problem hiding this comment.
Thanks for the submission! I've added some comments.
To confirm for this and for the other PRs, have they been physically tested or just tested via AI? While using AI to create the code is fine, we did update the contributing guidelines to make clear that the PR needs to use the template that appears when you physically open the PR in github, which includes the checkbox stating that the PR has been tested.
- Drop llms_filter_input_sanitize_string wrapper in save(), read $_POST directly with wp_unslash + absint (nonce verified at top of save) - Echo trigger links as built so esc_url/esc_html run at point of echo instead of building a links array - Restore "Any ___" placeholders for all trigger post-type selectors - Store each selected trigger post ID in its own _llms_engagement_trigger_post meta row and query with regular equality instead of FIND_IN_SET - Guard get_term() against WP_Error in the track title fallback Refs gocodebox#3238
faisalahammad
left a comment
There was a problem hiding this comment.
Thanks for the review. All four comments are addressed in 0070aa6.
- Removed the llms_filter_input_sanitize_string wrapper and read $_POST directly with wp_unslash and absint (nonce checked at the top of save).
- Echo the trigger links inside the loop so esc_url and esc_html run at the point of echo.
- Restored the Any ___ placeholders for all trigger post types.
- Dropped FIND_IN_SET. Each selected ID is stored in its own _llms_engagement_trigger_post meta row and the query uses a regular equality match.
Also updated this PR description to use the default template with the testing checklist filled in. Ready for another look.
|
@faisalahammad Please also confirm the comment above #3238 (review) |
Nonce is verified at the top of save() so the sniff recognizes it without the ignore. Addresses PR review feedback. Refs gocodebox#3238
|
Addressed the open review comments in f65c81a.
Both threads resolved. Ready for another look when you have time. |
|
To confirm both points above:
@brianhogg let me know if you would like more detail on the manual test steps. |
|
@faisalahammad Will test but looks like we're pretty much there. Feel free to update the changelog yml to add your |
|
Re: brianhogg attribution — added in commit 453c41c. Changelog yml now carries attributions: [@faisalahammad] on the 3233 entry, which renders as Thanks @faisalahammad! when the release tooling runs. Schema validates clean. |
|
@faisalahammad Could the height of the box to select item(s) be the standard height by default? I'm not sure why it's double height in the screenshot (possibly WP 7.0 related formatting), as it should expand if many courses are picked. |
|
@brianhogg Hi, I’ve tried adjusting the height of the box to the standard size, but I wasn’t able to reduce it. Could you please help me look into this? Thanks! |
|
@faisalahammad Fixed the styling to match multi-select boxes like Enroll New Students (edit course), but when testing the engagements persist to CleanShot.2026-07-21.at.05.28.37.mp4 |
brianhogg
left a comment
There was a problem hiding this comment.
Does not work when testing. Selected trigger post(s) persist, but do not load back into the editor after save/reload.
|
Hi @brianhogg, |
Passes saved trigger post IDs as the field selected key so the Select renderer marks each option selected and Select2 hydrates them on editor reload. Refs gocodebox#3238
|
Fixed. Saved trigger post IDs now load back into the multi-select on editor reload. The faux field ( Demo: https://screendrop-worker.faisalahammad24.workers.dev/5c1d7b4c @brianhogg could you take another look? |
Description
Currently engagement triggers can target either one specific post (course, lesson, membership) or any post of that type. This adds the ability to select multiple items, limiting triggers to a specific set of courses, lessons, memberships, etc.
Fixes #3233
Changes
_llms_engagement_trigger_postpostmeta row (one row per ID). An empty selection stores a singleanyrow. This keeps the trigger query as a regular equality match instead ofFIND_IN_SET.get_engagements()usesmeta_value = %d OR meta_value = 'any', matching the per-row storage. Backward compatible with existing single-ID engagements.How has this been tested?
Physically tested in a local WordPress install against the built plugin zip.
Test 1: Multi-select UI
Result: Multiple courses are saved (one postmeta row per ID) and listed in the admin columns.
Test 2: Backward compatibility
Result: Single-ID engagements unaffected.
Test 3: "Any" behavior
Result: Trigger applies to all courses (stored as "any").
Test 4: Trigger fires for each selected item
Result: Engagement triggers for both selected courses.
Automated tests: engagement and notification PHPUnit suites pass (
class-llms-test-engagements,class-llms-test-engagement-handler, notification earned tests). PHPCS (check-cs-errors) passes clean.Screenshots
Types of changes
New feature (non-breaking change which adds functionality).
Checklist: